From 61fffbd60092e2005a8076eb127e201df68fba52 Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Fri, 15 Mar 2024 13:04:40 -0700 Subject: [PATCH 2/4] Created new functions to handle removal of `http` and `https` from hashnodeURL before being passed to GraphQL --- package/src/hn-gql/client.ts | 18 ++++++++++++++---- playground/astro.config.mjs | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/package/src/hn-gql/client.ts b/package/src/hn-gql/client.ts index 893b1fb..d7ba74a 100644 --- a/package/src/hn-gql/client.ts +++ b/package/src/hn-gql/client.ts @@ -6,13 +6,23 @@ export const getClient = () => { return new GraphQLClient("https://gql.hashnode.com") } +export function removeHTTPSProtocol(url: string) { + return url.replace(/^https?:\/\//, ''); +} +export function removeHTTPProtocol(url: string) { + const fixHTTPS = removeHTTPSProtocol(url); + return fixHTTPS.replace(/^http?:\/\//, ''); +} + +const newURL = removeHTTPProtocol(config.hashnodeURL); + export const getAllPosts = async () => { const client = getClient(); const allPosts = await client.request( gql` query allPosts { - publication(host: "${config.hashnodeURL}") { + publication(host: "${newURL}") { title posts(first: 20) { pageInfo{ @@ -56,7 +66,7 @@ export const getPost = async (slug: string) => { const data = await client.request( gql` query postDetails($slug: String!) { - publication(host: "${config.hashnodeURL}") { + publication(host: "${newURL}") { post(slug: $slug) { author{ name @@ -92,7 +102,7 @@ export const getAboutPage = async () => { const page = await client.request( gql` query pageData { - publication(host: "${config.hashnodeURL}") { + publication(host: "${newURL}") { staticPage(slug: "about") { title content { @@ -114,7 +124,7 @@ export const getPublication = async () => { const data = await client.request( gql` query pubData { - publication(host: "${config.hashnodeURL}") { + publication(host: "${newURL}") { title displayTitle descriptionSEO diff --git a/playground/astro.config.mjs b/playground/astro.config.mjs index 48cb804..4041a53 100644 --- a/playground/astro.config.mjs +++ b/playground/astro.config.mjs @@ -10,7 +10,7 @@ export default defineConfig({ // }), integrations: [ astroHashnode({ - hashnodeURL: "astroplayground.hashnode.dev", + hashnodeURL: "https://astroplayground.hashnode.dev", verbose: true, disableViewTransitions: false, }) -- 2.40.1 From e048d8dd1ab885d7fdd07518b9de9bd082559242 Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Fri, 15 Mar 2024 13:06:08 -0700 Subject: [PATCH 3/4] add changeset --- .changeset/lazy-bobcats-leave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lazy-bobcats-leave.md diff --git a/.changeset/lazy-bobcats-leave.md b/.changeset/lazy-bobcats-leave.md new file mode 100644 index 0000000..c3ffc92 --- /dev/null +++ b/.changeset/lazy-bobcats-leave.md @@ -0,0 +1,5 @@ +--- +"@matthiesenxyz/astro-hashnode": patch +--- + +[Internal] better handling of the `hashnodeURL` input to verify that including `http` or `https` in the URL does not break the entire integration -- 2.40.1 From bdade728c8616e0c81a32ce0213bdcea0280b7bc Mon Sep 17 00:00:00 2001 From: Adam Matthiesen Date: Fri, 15 Mar 2024 13:19:57 -0700 Subject: [PATCH 4/4] a little more testing latter. and its still working --- playground/astro.config.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/astro.config.mjs b/playground/astro.config.mjs index 4041a53..48cb804 100644 --- a/playground/astro.config.mjs +++ b/playground/astro.config.mjs @@ -10,7 +10,7 @@ export default defineConfig({ // }), integrations: [ astroHashnode({ - hashnodeURL: "https://astroplayground.hashnode.dev", + hashnodeURL: "astroplayground.hashnode.dev", verbose: true, disableViewTransitions: false, }) -- 2.40.1