2025-06-11 23:20:36 +00:00
|
|
|
import type { WithContext, BlogPosting } from "schema-dts";
|
2025-06-14 12:08:48 +00:00
|
|
|
import { config } from "../../config";
|
2025-06-11 23:20:36 +00:00
|
|
|
|
|
|
|
export type BlogPostSchemaParams = {
|
2025-06-14 11:25:17 +00:00
|
|
|
readonly dateModified: string;
|
|
|
|
readonly datePublished: string;
|
|
|
|
readonly description: string;
|
2025-06-14 11:47:17 +00:00
|
|
|
readonly isBasedOn?: string;
|
2025-06-14 11:09:34 +00:00
|
|
|
readonly lang: string;
|
2025-06-14 19:25:16 +00:00
|
|
|
readonly preview: string;
|
2025-06-14 11:25:17 +00:00
|
|
|
readonly siteUrl: string;
|
|
|
|
readonly slug: string;
|
|
|
|
readonly title: string;
|
2025-06-11 23:20:36 +00:00
|
|
|
};
|
|
|
|
|
2025-06-14 19:25:16 +00:00
|
|
|
export default ({ siteUrl, slug, title, description, preview, datePublished, dateModified, lang, isBasedOn }: BlogPostSchemaParams): WithContext<BlogPosting> => ({
|
2025-06-11 23:20:36 +00:00
|
|
|
"@context": "https://schema.org",
|
|
|
|
"@type": "BlogPosting",
|
|
|
|
"url": new URL(`/blog/${slug}`, siteUrl).toString(),
|
|
|
|
"headline": title,
|
2025-06-14 11:09:34 +00:00
|
|
|
"description": description,
|
2025-06-14 19:25:16 +00:00
|
|
|
"image": new URL(preview, siteUrl).toString(),
|
2025-06-11 23:20:36 +00:00
|
|
|
"datePublished": datePublished,
|
2025-06-14 11:25:17 +00:00
|
|
|
"dateModified": dateModified,
|
2025-06-14 11:09:34 +00:00
|
|
|
"inLanguage": lang,
|
2025-06-11 23:20:36 +00:00
|
|
|
"author": {
|
|
|
|
"@type": "Person",
|
2025-06-14 12:08:48 +00:00
|
|
|
"name": config.author.name,
|
|
|
|
"url": config.author.url,
|
|
|
|
"sameAs": config.author.sameAs,
|
2025-06-11 23:20:36 +00:00
|
|
|
},
|
2025-06-14 11:09:34 +00:00
|
|
|
"mainEntityOfPage": {
|
|
|
|
"@type": "WebPage",
|
|
|
|
"@id": new URL(`/blog/${slug}`, siteUrl).toString(),
|
|
|
|
},
|
2025-06-14 11:47:17 +00:00
|
|
|
...(isBasedOn && { isBasedOn: isBasedOn }),
|
2025-06-11 23:20:36 +00:00
|
|
|
});
|