Skip to content
This repository was archived by the owner on Jan 1, 2025. It is now read-only.

Commit e54bfbb

Browse files
feat: ✨ Not able to pull publication title from Hashnode (#22)
Co-authored-by: create-issue-branch[bot] <53036503+create-issue-branch[bot]@users.noreply.github.com> Co-authored-by: Adam Matthiesen <amatthiesen@outlook.com>
1 parent cf327f2 commit e54bfbb

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

.changeset/lazy-bobcats-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@matthiesenxyz/astro-hashnode": patch
3+
---
4+
5+
[Internal] better handling of the `hashnodeURL` input to verify that including `http` or `https` in the URL does not break the entire integration

package/src/hn-gql/client.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@ export const getClient = () => {
66
return new GraphQLClient("https://gql.hashnode.com")
77
}
88

9+
export function removeHTTPSProtocol(url: string) {
10+
return url.replace(/^https?:\/\//, '');
11+
}
12+
export function removeHTTPProtocol(url: string) {
13+
const fixHTTPS = removeHTTPSProtocol(url);
14+
return fixHTTPS.replace(/^http?:\/\//, '');
15+
}
16+
17+
const newURL = removeHTTPProtocol(config.hashnodeURL);
18+
919
export const getAllPosts = async () => {
1020
const client = getClient();
1121

1222
const allPosts = await client.request<AllPostsData>(
1323
gql`
1424
query allPosts {
15-
publication(host: "${config.hashnodeURL}") {
25+
publication(host: "${newURL}") {
1626
title
1727
posts(first: 20) {
1828
pageInfo{
@@ -56,7 +66,7 @@ export const getPost = async (slug: string) => {
5666
const data = await client.request<PostOrPageData>(
5767
gql`
5868
query postDetails($slug: String!) {
59-
publication(host: "${config.hashnodeURL}") {
69+
publication(host: "${newURL}") {
6070
post(slug: $slug) {
6171
author{
6272
name
@@ -92,7 +102,7 @@ export const getAboutPage = async () => {
92102
const page = await client.request<PostOrPageData>(
93103
gql`
94104
query pageData {
95-
publication(host: "${config.hashnodeURL}") {
105+
publication(host: "${newURL}") {
96106
staticPage(slug: "about") {
97107
title
98108
content {
@@ -114,7 +124,7 @@ export const getPublication = async () => {
114124
const data = await client.request<PublicationData>(
115125
gql`
116126
query pubData {
117-
publication(host: "${config.hashnodeURL}") {
127+
publication(host: "${newURL}") {
118128
title
119129
displayTitle
120130
descriptionSEO

0 commit comments

Comments
 (0)