From 128cd18efc5b74504c4c3b94a8f4721e7ac9ff56 Mon Sep 17 00:00:00 2001 From: Alex Patterson Date: Mon, 18 Dec 2023 03:35:59 -0500 Subject: [PATCH] run hashnode env variable --- apps/codingcatdev/scripts/post-hashnode.js | 18 +++++++++++++----- .../post/angular-17-cypress-testing/+page.md | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/codingcatdev/scripts/post-hashnode.js b/apps/codingcatdev/scripts/post-hashnode.js index 993f0409..fe4ada32 100644 --- a/apps/codingcatdev/scripts/post-hashnode.js +++ b/apps/codingcatdev/scripts/post-hashnode.js @@ -17,7 +17,7 @@ const addArticle = async (input) => { return fetch('https://api.hashnode.com/', { method: 'POST', headers: { - authorization: '2b02d999-9e2d-409a-a2b4-7a1bcbbc58d5', + authorization: process.env.PRIVATE_HASHNODE, 'Content-Type': 'application/json' }, body: JSON.stringify({ @@ -56,6 +56,7 @@ for await (const file of g) { // TODO: We might need to add a check on cononical if this page is already in dev.to if ( fm?.slug && + fm.slug === 'angular-17-cypress-testing' && fm?.title && fm?.cover && fm?.published === 'published' && @@ -105,13 +106,20 @@ ${content}`; console.log('addArticle result:', response.status); if (response?.error) console.error('error', response.error); // Get new devto url and update - if (response.status === 201) { + if (response.status === 200) { const json = await response.json(); - if (json?.url) { - console.log('Updating', file, { devto: json.url }); + const hashnodeSlug = json?.data?.createPublicationStory?.post?.slug; + + if (!hashnodeSlug) { + console.error('hasnode url missing'); + continue; + } + + if (hashnodeSlug) { + console.log('Updating', file, { hashnode: json.url }); const newMdFile = matter.stringify(content, { ...data, - devto: json.url + hashnode: hashnodeSlug }); fs.writeFileSync(file, newMdFile, { encoding: 'utf8' }); } diff --git a/apps/codingcatdev/src/routes/(content-single)/(non-course)/post/angular-17-cypress-testing/+page.md b/apps/codingcatdev/src/routes/(content-single)/(non-course)/post/angular-17-cypress-testing/+page.md index b8562afe..34f7c9bb 100644 --- a/apps/codingcatdev/src/routes/(content-single)/(non-course)/post/angular-17-cypress-testing/+page.md +++ b/apps/codingcatdev/src/routes/(content-single)/(non-course)/post/angular-17-cypress-testing/+page.md @@ -7,7 +7,7 @@ cover: >- https://media.codingcat.dev/image/upload/v1700112316/main-codingcatdev-photo/cypress-angular-testing.png devto: 'https://dev.to/codingcatdev/how-to-test-angular-17-using-cypressio-27cg' excerpt: How you can easily test Angular 17 components with Cypress -hashnode: null +hashnode: published: published start: 'November 11, 2023' slug: angular-17-cypress-testing