From 4c3e8d055e396d6551a881b8bb59a1ed97f23b9e Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 24 Jun 2023 22:13:01 +0100 Subject: [PATCH] ci: update dev.to sync script --- .github/workflows/sync.yml | 2 +- scripts/publish.mjs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index c2dc7862..b2b4279d 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -5,7 +5,7 @@ on: branches: - main paths: - - "src/content/**" + - "src/content/blog/**" - ".github/workflows/test.yml" jobs: diff --git a/scripts/publish.mjs b/scripts/publish.mjs index 86f77685..e352918e 100644 --- a/scripts/publish.mjs +++ b/scripts/publish.mjs @@ -16,7 +16,8 @@ async function getMarkdownArticles() { articles.push({ body_markdown: contents .replace(/\(\//g, '(https://roe.dev/') - .replace(/ ---? /g, ' — '), + .replace(/ ---? /g, ' — ') + .replace(/(\n|^)---\n[\s\S]*\n---\n/, '\n'), title: contents.match(/title: (.*)/)?.[1], slug, canonical_url: `https://roe.dev/blog/${slug}/`, @@ -33,7 +34,6 @@ function getArticles() { }) } -// eslint-disable-next-line async function postArticle({ title, body_markdown, canonical_url }) { try { return await $fetch(`${url}/articles`, { @@ -55,7 +55,6 @@ async function postArticle({ title, body_markdown, canonical_url }) { } } -// eslint-disable-next-line async function updateArticle(id, { title, body_markdown, canonical_url }) { try { return await $fetch(`${url}/articles/${id}`, { @@ -80,15 +79,15 @@ async function updateArticle(id, { title, body_markdown, canonical_url }) { getArticles().then(async articles => { const markdownArticles = await getMarkdownArticles() // console.log('TCL: markdownArticles', markdownArticles) - markdownArticles.forEach(markdownArticle => { + for (const markdownArticle of markdownArticles) { const article = articles.find( article => article.canonical_url === markdownArticle.canonical_url ) // console.log('TCL: article', article) if (article) { - updateArticle(article.id, markdownArticle) + await updateArticle(article.id, markdownArticle) } else { - postArticle(markdownArticle) + await postArticle(markdownArticle) } - }) + } }) -- knotmirror 0.0.1