From e54bfbbfd2485e2f512c64d55dd0800cfabf5400 Mon Sep 17 00:00:00 2001 From: "create-issue-branch[bot]" <53036503+create-issue-branch[bot]@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:25:49 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Not=20able=20to=20pull=20pu?= =?UTF-8?q?blication=20title=20from=20Hashnode=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: create-issue-branch[bot] <53036503+create-issue-branch[bot]@users.noreply.github.com> Co-authored-by: Adam Matthiesen --- .changeset/lazy-bobcats-leave.md | 5 +++++ package/src/hn-gql/client.ts | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) 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 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