Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions apps/sanity/functions/syndicate-content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export const handler = documentEventHandler<ContentDocument>(
slug: `${data._type}-${slug}`,
tags: hashnodeTags,
...(hashnodeCoverImageUrl
? { coverImageOptions: { coverImageURL: hashnodeCoverImageUrl } }
? { coverImage: hashnodeCoverImageUrl }
: {}),
originalArticleURL: canonicalUrl,
contentMarkdown: `Original: ${canonicalUrl}\n\n${youtubeEmbed}${contentMarkdown}`,
Expand All @@ -416,14 +416,16 @@ export const handler = documentEventHandler<ContentDocument>(
existingSyndication?.externalId || data.hashnode || null;

let publishedPost: { id: string; slug?: string; url?: string } | null = null;
const authHeader = token.startsWith("Bearer ") ? token : `Bearer ${token}`;

if (existingHashnodeSlug && !existingHashnodeSlug.startsWith("simulated-")) {
// Lookup post ID from Hashnode
const getPostRes = await fetch("https://gql.hashnode.com", {
const getPostRes = await fetch("https://gql-beta.hashnode.com", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: token,
Authorization: authHeader,
"x-hashnode-client": "hashnode-cli",
},
body: JSON.stringify({
operationName: "Publication",
Expand All @@ -445,11 +447,12 @@ export const handler = documentEventHandler<ContentDocument>(
const updateInput = { ...articleInput };
delete updateInput.slug; // slug cannot be updated

const updateRes = await fetch("https://gql.hashnode.com", {
const updateRes = await fetch("https://gql-beta.hashnode.com", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: token,
Authorization: authHeader,
"x-hashnode-client": "hashnode-cli",
},
body: JSON.stringify({
operationName: "updatePost",
Expand Down Expand Up @@ -479,11 +482,12 @@ export const handler = documentEventHandler<ContentDocument>(

if (!publishedPost) {
// Create post mutation
const publishRes = await fetch("https://gql.hashnode.com", {
const publishRes = await fetch("https://gql-beta.hashnode.com", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: token,
Authorization: authHeader,
"x-hashnode-client": "hashnode-cli",
},
body: JSON.stringify({
operationName: "publishPost",
Expand Down
8 changes: 5 additions & 3 deletions scripts/run-syndicate-post.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,19 @@ async function run() {
publicationId,
slug: `${doc._type}-${slug}`,
tags: hashnodeTags,
...(hashnodeCoverImageUrl ? { coverImageOptions: { coverImageURL: hashnodeCoverImageUrl } } : {}),
...(hashnodeCoverImageUrl ? { coverImage: hashnodeCoverImageUrl } : {}),
originalArticleURL: canonicalUrl,
contentMarkdown: `Original: ${canonicalUrl}\n\n${youtubeEmbed}${contentMarkdown}`,
};

try {
const publishRes = await fetch("https://gql.hashnode.com", {
const authHeader = hashnodeToken.startsWith("Bearer ") ? hashnodeToken : `Bearer ${hashnodeToken}`;
const publishRes = await fetch("https://gql-beta.hashnode.com", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: hashnodeToken,
Authorization: authHeader,
"x-hashnode-client": "hashnode-cli",
},
body: JSON.stringify({
operationName: "publishPost",
Expand Down
Loading