1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import type { ProfilePage, WebPage } from "schema-dts";
import { personId, websiteId } from "./ids";
export type WebsiteSchemaParams = {
readonly description: string;
readonly lang: string;
readonly page: string;
readonly siteUrl: string;
readonly title: string;
readonly type?: "WebPage" | "ProfilePage";
};
export default ({ siteUrl, page, title, description, lang, type = "WebPage" }: WebsiteSchemaParams): WebPage | ProfilePage => {
const url = new URL(page, siteUrl).toString();
const base = {
"@type": type,
"@id": url,
"url": url,
"name": title,
"description": description,
"inLanguage": lang,
"isPartOf": { "@id": websiteId(siteUrl) },
} as const;
if (type === "ProfilePage") {
return {
...base,
"@type": "ProfilePage",
"mainEntity": { "@id": personId(siteUrl) },
};
}
return base;
};
|