Skip to content

Commit

Permalink
Export updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MythicalFish committed Oct 4, 2024
1 parent 964abdf commit 40fbfc6
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 90 deletions.
5 changes: 3 additions & 2 deletions internal/step2/exportLinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function getLinks() {
const oldPosts = await readPosts();
const newPosts = await fetchNewPosts();

let csvContent = 'title,oldURL,devURL,prodURL\n';
let csvContent = 'title,oldURL,devURL,prodURL,cmsURL\n';

for (const title of titles) {
const oldPost = oldPosts.find(p => p.title === title);
Expand All @@ -46,9 +46,10 @@ async function getLinks() {
const oldURL = oldPost ? `https://nextflow.io/blog/${oldPost.slug}.html` : '';
const devURL = newPost ? `https://seqera.io/preview?type=blogPostDev&id=${id}` : '';
const prodURL = newPost ? `https://seqera.io/blog/${newSlug}` : '';
const cmsURL = 'https://seqera-cms.netlify.app/seqera/structure/blogPostDev;' + id;

const escapedTitle = title.includes(',') ? `"${title}"` : title;
csvContent += `${escapedTitle},${oldURL},${devURL},${prodURL}\n`;
csvContent += `${escapedTitle},${oldURL},${devURL},${prodURL},${cmsURL}\n`;
}

fs.writeFileSync(outputFile, csvContent, 'utf8');
Expand Down
45 changes: 45 additions & 0 deletions internal/step2/exportLinks2.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fs from 'fs';
import path from 'path';
import sanityClient from '@sanity/client';

const outputFile = path.join(process.cwd(), './links2.csv');

export const client = sanityClient({
projectId: 'o2y1bt2g',
dataset: 'seqera',
token: process.env.SANITY_TOKEN,
useCdn: false,
});

async function fetchNewPosts() {
return await client.fetch(`*[_type == "blogPostDev2"]`);
}

async function getLinks() {
console.log('🟢🟢🟢 Export');
const newPosts = await fetchNewPosts();

let csvContent = 'title,oldURL,devURL,prodURL,cmsURL\n';

for (const post of newPosts) {

let id = post?._id || '';
if (id.split('.')[1]) id = id.split('.')[1];

const slug = post?.meta?.slug?.current || '';
const title = post?.title || '';

const oldURL = post ? `https://seqera.io/blog/${slug}` : '';
const devURL = post ? `https://seqera.io/preview?type=blogPostDev&id=${id}` : '';
const prodURL = ''
const cmsURL = 'https://seqera-cms.netlify.app/seqera/structure/blogPostDev2;' + id;

const escapedTitle = title.includes(',') ? `"${title}"` : title;
csvContent += `${escapedTitle},${oldURL},${devURL},${prodURL},${cmsURL}\n`;
}

fs.writeFileSync(outputFile, csvContent, 'utf8');
console.log(`CSV file has been written to ${outputFile}`);
}

getLinks();
Loading

0 comments on commit 40fbfc6

Please sign in to comment.