Skip to content

Commit

Permalink
chore: improve schema
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Dec 22, 2023
1 parent 6c1e36d commit e737917
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions src/utils/ghost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type PostDetail = {
};

// https://schema.org/TechArticle
// https://schema.org/HowTo

export const getBlogPostSchema = (
isGuide: boolean,
Expand All @@ -33,37 +34,67 @@ export const getBlogPostSchema = (
const {
excerpt,
featureImage,
primaryAuthor: author,
primaryAuthor,
publishedAt,
slug,
tags,
title,
} = post;

return JSON.stringify({
const author = {
"@type": "Person",
"alternateName": primaryAuthor.slug,
"image": primaryAuthor.profileImage,
"name": primaryAuthor.name,
"url": `https://www.forbole.com/author/${primaryAuthor.slug}`,
};

const keyworkdsObj = !!tags?.length && {
keywords: tags
.map((x: { name: any }) => x.name ?? "")
.filter(Boolean)
.join(", "),
};

const common = {
"@context": "https://schema.org",
"name": title,
"image": featureImage,
"url": `https://www.forbole.com/${isGuide ? "staking" : "blog"}/${
post.slug
}`,
};

if (slug?.includes("-opening")) {
return JSON.stringify({
...common,
"@type": "JobPosting",
"datePosted": publishedAt,
"industry": "Cryptocurrencies Validators and Blockchain Development",
});
}

if (slug?.includes("how-to")) {
return JSON.stringify({
...common,
...keyworkdsObj,
"@type": "HowTo",
"headline": title,
...(excerpt && { abstract: excerpt }),
"inLanguage": getLanguageFromLocale(locale),
"datePublished": publishedAt,
author,
});
}

return JSON.stringify({
...common,
...keyworkdsObj,
"@type": "TechArticle",
...(excerpt && { abstract: excerpt }),
"headline": title,
"image": [featureImage],
...(excerpt && { abstract: excerpt }),
"inLanguage": getLanguageFromLocale(locale),
"datePublished": publishedAt,
"url": `https://www.forbole.com/${isGuide ? "staking" : "blog"}/${
post.slug
}`,
...(!!tags?.length && {
keywords: tags
.map((x: { name: any }) => x.name ?? "")
.filter(Boolean)
.join(", "),
}),
"author": [
{
"@type": "Person",
"alternateName": author.slug,
"image": author.profileImage,
"name": author.name,
"url": `https://www.forbole.com/author/${author.slug}`,
},
],
author,
});
};

0 comments on commit e737917

Please sign in to comment.