From f01c8b7e0d4aa3cf5d542793818e30703613f0a9 Mon Sep 17 00:00:00 2001 From: spences10 Date: Sat, 6 Jan 2024 11:03:03 +0000 Subject: [PATCH] refactor: :label: update types for json-ld --- packages/svead/src/lib/components/head.svelte | 10 +-- .../src/lib/components/schema-org.svelte | 83 +++++++++++++------ packages/svead/src/lib/types.ts | 37 ++++++++- packages/svead/vitest.config.ts | 22 +++++ 4 files changed, 120 insertions(+), 32 deletions(-) create mode 100644 packages/svead/vitest.config.ts diff --git a/packages/svead/src/lib/components/head.svelte b/packages/svead/src/lib/components/head.svelte index 8ca157d..2d94d88 100644 --- a/packages/svead/src/lib/components/head.svelte +++ b/packages/svead/src/lib/components/head.svelte @@ -1,7 +1,7 @@ - - {@html jsonLdScript} - + + {@html JSON.stringify(jsonLd)} + diff --git a/packages/svead/src/lib/types.ts b/packages/svead/src/lib/types.ts index ce3351a..780524e 100644 --- a/packages/svead/src/lib/types.ts +++ b/packages/svead/src/lib/types.ts @@ -13,19 +13,52 @@ interface CommonEntity { } export interface AuthorEntity { - type: AuthorType; + '@type': AuthorType; + type?: AuthorType; name: string; url: string; } export interface PublisherEntity { - type: 'Organization'; + '@type': 'Organization'; name: string; logo: string; + url?: string; +} + +export interface BreadcrumbItem { + name: string; + url: string; } export interface MainEntity extends CommonEntity { type: MainEntityType; author: AuthorEntity; publisher: PublisherEntity; + breadcrumb?: { + '@type': 'BreadcrumbList'; + itemListElement: { + '@type': 'ListItem'; + position: number; + item: BreadcrumbItem; + }[]; + }; +} + +export interface JsonLdMainEntity extends MainEntity { + '@context': string; + '@type': MainEntityType; + inLanguage?: string; + breadcrumb?: { + '@type': 'BreadcrumbList'; + itemListElement: { + '@type': 'ListItem'; + position: number; + item: BreadcrumbItem; + }[]; + }; + mainEntityOfPage?: { + '@type': string; + '@id': string; + }; } diff --git a/packages/svead/vitest.config.ts b/packages/svead/vitest.config.ts new file mode 100644 index 0000000..2c55119 --- /dev/null +++ b/packages/svead/vitest.config.ts @@ -0,0 +1,22 @@ +import { defineConfig, mergeConfig } from 'vitest/config'; +import viteConfig from './vite.config'; + +export default mergeConfig( + viteConfig, + defineConfig({ + test: { + include: ['src/**/*.test.{js,ts,svelte}'], + globals: true, + environment: 'jsdom', + coverage: { + all: false, + thresholds: { + statements: 75, + branches: 84, + functions: 68, + lines: 75, + }, + }, + }, + }), +);