Skip to content

Commit

Permalink
Create CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
MythicalFish committed Oct 4, 2024
1 parent e89e474 commit 964abdf
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 5 deletions.
12 changes: 7 additions & 5 deletions internal/step2/exportLinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async function readPosts() {
return JSON.parse(data);
}


export const client = sanityClient({
projectId: 'o2y1bt2g',
dataset: 'seqera',
Expand All @@ -23,8 +22,6 @@ async function fetchNewPosts() {
return await client.fetch(`*[_type == "blogPostDev"]`);
}



async function getLinks() {
console.log('🟢🟢🟢 Export');
const fileContents = fs.readFileSync(titlesFile, 'utf8');
Expand All @@ -33,6 +30,8 @@ async function getLinks() {
const oldPosts = await readPosts();
const newPosts = await fetchNewPosts();

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

for (const title of titles) {
const oldPost = oldPosts.find(p => p.title === title);
const newPost = newPosts.find(p => p.title === title);
Expand All @@ -42,15 +41,18 @@ async function getLinks() {
let id = newPost?._id || '';
if (id.split('.')[1]) id = id.split('.')[1];

let newSlug = newPost?.slug?.current || '';
let newSlug = newPost?.meta?.slug?.current || '';

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 escapedTitle = title.includes(',') ? `"${title}"` : title;
csvContent += `${escapedTitle},${oldURL},${devURL},${prodURL}\n`;
}


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

getLinks();
Loading

0 comments on commit 964abdf

Please sign in to comment.