diff options
| author | Valentin Popov <valentin@popov.link> | 2026-04-22 19:11:58 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-04-22 19:11:58 +0300 |
| commit | 5e818d804d5d38beff0f3754a006333752fd5082 (patch) | |
| tree | 7f2d1097390bbdb3c5fa1593f6d15d6dfb3b0dd8 /src/utils/schemas/pageSchema.ts | |
| parent | 41bb3099660b6210a419c4190a1bc08d7ba58c00 (diff) | |
| download | popov.link-5e818d804d5d38beff0f3754a006333752fd5082.tar.xz popov.link-5e818d804d5d38beff0f3754a006333752fd5082.zip | |
refactor: update schema handling and improve SEO metadata
- Changed schema type from WithContext<Thing> to Thing[] in Head, BaseLayout, and JsonLd components for better flexibility.
- Added optional robots meta tag to Head component.
- Updated JSON-LD generation in JsonLd component to include a structured payload.
- Enhanced page and blog schemas to support breadcrumb and person schemas for improved SEO.
- Introduced new utility schemas for website and person to streamline schema generation.
- Refactored existing schemas to align with the new structure and ensure consistency across components.
Diffstat (limited to 'src/utils/schemas/pageSchema.ts')
| -rw-r--r-- | src/utils/schemas/pageSchema.ts | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/utils/schemas/pageSchema.ts b/src/utils/schemas/pageSchema.ts index 606488b..ba8fd86 100644 --- a/src/utils/schemas/pageSchema.ts +++ b/src/utils/schemas/pageSchema.ts @@ -1,23 +1,36 @@ -import type { WithContext, WebPage } from "schema-dts"; +import type { ProfilePage, WebPage } from "schema-dts"; +import { personId, websiteId } from "./ids"; export type WebsiteSchemaParams = { readonly description: string; + readonly lang: string; + readonly mainEntityId?: string; readonly page: string; readonly siteUrl: string; readonly title: string; - readonly lang: string; + readonly type?: "WebPage" | "ProfilePage"; }; -export default ({ siteUrl, page, title, description, lang }: WebsiteSchemaParams): WithContext<WebPage> => ({ - "@context": "https://schema.org", - "@type": "WebPage", - "@id": new URL(page, siteUrl).toString(), - "url": new URL(page, siteUrl).toString(), - "name": title, - "description": description, - "inLanguage": lang, - "mainEntity": { - "@type": "WebSite", - "@id": new URL("/", siteUrl).toString(), - }, -}); +export default ({ siteUrl, page, title, description, lang, type = "WebPage", mainEntityId }: 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": mainEntityId ?? personId(siteUrl) }, + }; + } + + return base; +}; |
