From 55bb2dad6c0cc99834845268e5c217cbaa0ce9e5 Mon Sep 17 00:00:00 2001 From: joostdecock Date: Sun, 16 Jul 2023 06:45:55 +0200 Subject: [PATCH] fix: Added designs to Sanity migration scrips --- scripts/sanity-to-markdown.mjs | 31 +++++++++++++++++--------- sites/sanity/scripts/import-sanity.sh | 1 + sites/sanity/scripts/replace-sanity.sh | 23 ++++++++++--------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/scripts/sanity-to-markdown.mjs b/scripts/sanity-to-markdown.mjs index ff7005acd67..db07fe2bded 100644 --- a/scripts/sanity-to-markdown.mjs +++ b/scripts/sanity-to-markdown.mjs @@ -33,21 +33,26 @@ const sanity = { */ /* - * Query to load makers from Strapi + * Query to load makers and designs from Strapi */ -const loadMakers = async () => { +const loadMakersAndDesigns = async () => { const result = await axios.get( 'https://posts.freesewing.org/showcaseposts?_locale=en&_sort=date:ASC&_limit=500' ) const makers = {} + const designs = {} for (const post of result.data) { makers[post.slug] = post.maker?.displayname && post.maker.displayname !== 'A FreeSewing Maker' ? post.maker.displayname : 'unknown' + designs[post.slug] = [] + if (post.design1) designs[post.slug].push(post.design1) + if (post.design2) designs[post.slug].push(post.design2) + if (post.design3) designs[post.slug].push(post.design3) } - return makers + return { designs, makers } } /* @@ -120,22 +125,27 @@ const createBlogPosts = async (posts, images) => { /* * Port a sanity showcase post to markdown */ -const sanityShowcasePostToMd = (post, img, maker) => `--- +const sanityShowcasePostToMd = (post, img, maker, designs) => { + //if (designs.length > 1) console.log(designs) + + return `--- maker: ${JSON.stringify(maker)} caption: ${JSON.stringify(post.caption)} date: ${JSON.stringify(post.date)} image: ${JSON.stringify(img)} intro: ${JSON.stringify(post.intro)} title: ${JSON.stringify(post.title)} +designs: ${JSON.stringify(designs)} --- ${post.body} ` +} /* * Helper method to create all showcase posts */ -const createShowcasePosts = async (posts, images, makers) => { +const createShowcasePosts = async (posts, images, makers, designs) => { const promises = [] const root = ['markdown', 'org', 'showcase'] // First create the folders @@ -155,7 +165,8 @@ const createShowcasePosts = async (posts, images, makers) => { sanityShowcasePostToMd( post, images.showcase[post.slug.current], - makers[post.slug.current] + makers[post.slug.current], + designs[post.slug.current] ) ) ) @@ -235,13 +246,13 @@ const sanityToMarkdown = async () => { console.log(' - Migrating blog posts') await createBlogPosts(content.blog, images) - // We failed to migrate maker info, so let's load that from Strapi - console.log(' - Loading makers from strapi (missing in Sanity)') - const makers = await loadMakers() + // We failed to migrate maker & designs info, so let's load that from Strapi + console.log(' - Loading makers and designs from strapi (missing in Sanity)') + const { makers, designs } = await loadMakersAndDesigns() // Migrate showcase posts console.log(' - Migrating showcase posts') - await createShowcasePosts(content.showcase, images, makers) + await createShowcasePosts(content.showcase, images, makers, designs) // Migrate newsletter posts console.log(' - Migrating newsletter posts') diff --git a/sites/sanity/scripts/import-sanity.sh b/sites/sanity/scripts/import-sanity.sh index 3d81a0f3b03..670b876e5e8 100755 --- a/sites/sanity/scripts/import-sanity.sh +++ b/sites/sanity/scripts/import-sanity.sh @@ -10,3 +10,4 @@ sanity dataset import ./export/showcasede.ndjson site-content sanity dataset import ./export/showcasenl.ndjson site-content sanity dataset import ./export/showcasefr.ndjson site-content sanity dataset import ./export/newsletter.ndjson site-content +sanity dataset import ./export/contentimg.ndjson site-content diff --git a/sites/sanity/scripts/replace-sanity.sh b/sites/sanity/scripts/replace-sanity.sh index ede6b1f7d78..3439f3c4d16 100755 --- a/sites/sanity/scripts/replace-sanity.sh +++ b/sites/sanity/scripts/replace-sanity.sh @@ -1,12 +1,13 @@ #!/bin/bash -sanity dataset import ./export/blogen.ndjson production --replace -sanity dataset import ./export/bloges.ndjson production --replace -sanity dataset import ./export/blogde.ndjson production --replace -sanity dataset import ./export/blognl.ndjson production --replace -sanity dataset import ./export/blogfr.ndjson production --replace -sanity dataset import ./export/showcaseen.ndjson production --replace -sanity dataset import ./export/showcasees.ndjson production --replace -sanity dataset import ./export/showcasede.ndjson production --replace -sanity dataset import ./export/showcasenl.ndjson production --replace -sanity dataset import ./export/showcasefr.ndjson production --replace -sanity dataset import ./export/newsletter.ndjson production --replace +sanity dataset import ./export/blogen.ndjson site-content --replace +sanity dataset import ./export/bloges.ndjson site-content --replace +sanity dataset import ./export/blogde.ndjson site-content --replace +sanity dataset import ./export/blognl.ndjson site-content --replace +sanity dataset import ./export/blogfr.ndjson site-content --replace +sanity dataset import ./export/showcaseen.ndjson site-content --replace +sanity dataset import ./export/showcasees.ndjson site-content --replace +sanity dataset import ./export/showcasede.ndjson site-content --replace +sanity dataset import ./export/showcasenl.ndjson site-content --replace +sanity dataset import ./export/showcasefr.ndjson site-content --replace +sanity dataset import ./export/newsletter.ndjson site-content --replace +sanity dataset import ./export/contentimg.ndjson site-content --replace