[READ-ONLY] a fast, modern browser for the npm registry

refactor: use JSON-LD schema types from the `schema-dts` package (#751)

Co-authored-by: Daniel Roe <daniel@roe.dev>

authored by

Okinea Dev
Daniel Roe
and committed by
GitHub
4d771408 2ea2019c

+13 -92
+4 -92
app/composables/useJsonLd.ts
··· 1 - // JSON-LD Schema Types 2 - interface JsonLdBase { 3 - '@context': 'https://schema.org' 4 - '@type': string 5 - } 6 - 7 - interface WebSiteSchema extends JsonLdBase { 8 - '@type': 'WebSite' 9 - 'name': string 10 - 'url': string 11 - 'description'?: string 12 - 'potentialAction'?: SearchActionSchema 13 - } 14 - 15 - interface SearchActionSchema { 16 - '@type': 'SearchAction' 17 - 'target': { 18 - '@type': 'EntryPoint' 19 - 'urlTemplate': string 20 - } 21 - 'query-input': string 22 - } 23 - 24 - interface SoftwareApplicationSchema extends JsonLdBase { 25 - '@type': 'SoftwareApplication' 26 - 'name': string 27 - 'description'?: string 28 - 'applicationCategory': 'DeveloperApplication' 29 - 'operatingSystem': 'Cross-platform' 30 - 'url': string 31 - 'softwareVersion'?: string 32 - 'dateModified'?: string 33 - 'datePublished'?: string 34 - 'license'?: string 35 - 'author'?: PersonSchema | OrganizationSchema | (PersonSchema | OrganizationSchema)[] 36 - 'maintainer'?: PersonSchema | OrganizationSchema | (PersonSchema | OrganizationSchema)[] 37 - 'offers'?: OfferSchema 38 - 'downloadUrl'?: string 39 - 'codeRepository'?: string 40 - 'keywords'?: string[] 41 - } 42 - 43 - interface PersonSchema extends JsonLdBase { 44 - '@type': 'Person' 45 - 'name': string 46 - 'url'?: string 47 - } 48 - 49 - interface OrganizationSchema extends JsonLdBase { 50 - '@type': 'Organization' 51 - 'name': string 52 - 'url'?: string 53 - 'logo'?: string 54 - 'description'?: string 55 - 'sameAs'?: string[] 56 - } 57 - 58 - interface OfferSchema { 59 - '@type': 'Offer' 60 - 'price': string 61 - 'priceCurrency': string 62 - } 63 - 64 - interface BreadcrumbListSchema extends JsonLdBase { 65 - '@type': 'BreadcrumbList' 66 - 'itemListElement': BreadcrumbItemSchema[] 67 - } 68 - 69 - interface BreadcrumbItemSchema { 70 - '@type': 'ListItem' 71 - 'position': number 72 - 'name': string 73 - 'item'?: string 74 - } 75 - 76 - interface ProfilePageSchema extends JsonLdBase { 77 - '@type': 'ProfilePage' 78 - 'name': string 79 - 'url': string 80 - 'mainEntity': PersonSchema | OrganizationSchema 81 - } 82 - 83 - type JsonLdSchema = 84 - | WebSiteSchema 85 - | SoftwareApplicationSchema 86 - | PersonSchema 87 - | OrganizationSchema 88 - | BreadcrumbListSchema 89 - | ProfilePageSchema 1 + import type { Thing, WebSite, WithContext } from 'schema-dts' 90 2 91 3 /** 92 4 * Inject JSON-LD script into head 93 5 */ 94 - export function setJsonLd(schema: JsonLdSchema | JsonLdSchema[]) { 6 + export function setJsonLd(schema: WithContext<Thing> | WithContext<Thing>[]): void { 95 7 const schemas = Array.isArray(schema) ? schema : [schema] 96 8 97 9 useHead({ ··· 109 21 export function createWebSiteSchema(options?: { 110 22 name?: string 111 23 description?: string 112 - }): WebSiteSchema { 24 + }): WithContext<WebSite> { 113 25 const siteUrl = 'https://npmx.dev' 114 26 return { 115 27 '@context': 'https://schema.org', ··· 123 35 '@type': 'EntryPoint', 124 36 'urlTemplate': `${siteUrl}/search?q={search_term_string}`, 125 37 }, 126 - 'query-input': 'required name=search_term_string', 38 + 'query': 'required name=search_term_string', 127 39 }, 128 40 } 129 41 }
+1
package.json
··· 108 108 "knip": "5.82.1", 109 109 "lint-staged": "16.2.7", 110 110 "playwright-core": "1.58.0", 111 + "schema-dts": "1.1.5", 111 112 "simple-git-hooks": "2.13.1", 112 113 "typescript": "5.9.3", 113 114 "vitest": "npm:@voidzero-dev/vite-plus-test@0.0.0-833c515fa25cef20905a7f9affb156dfa6f151ab",
+8
pnpm-lock.yaml
··· 231 231 playwright-core: 232 232 specifier: 1.58.0 233 233 version: 1.58.0 234 + schema-dts: 235 + specifier: 1.1.5 236 + version: 1.1.5 234 237 simple-git-hooks: 235 238 specifier: 2.13.1 236 239 version: 2.13.1 ··· 8185 8188 sax@1.4.4: 8186 8189 resolution: {integrity: sha512-1n3r/tGXO6b6VXMdFT54SHzT9ytu9yr7TaELowdYpMqY/Ao7EnlQGmAQ1+RatX7Tkkdm6hONI2owqNx2aZj5Sw==} 8187 8190 engines: {node: '>=11.0.0'} 8191 + 8192 + schema-dts@1.1.5: 8193 + resolution: {integrity: sha512-RJr9EaCmsLzBX2NDiO5Z3ux2BVosNZN5jo0gWgsyKvxKIUL5R3swNvoorulAeL9kLB0iTSX7V6aokhla2m7xbg==} 8188 8194 8189 8195 schema-utils@4.3.3: 8190 8196 resolution: {integrity: sha512-eflK8wEtyOE6+hsaRVPxvUKYCpRgzLqDTb8krvAsRIwOGlHoSgYLgBXoubGgLd2fT41/OUYdb48v4k4WWHQurA==} ··· 19432 19438 yoga-layout: 3.2.1 19433 19439 19434 19440 sax@1.4.4: {} 19441 + 19442 + schema-dts@1.1.5: {} 19435 19443 19436 19444 schema-utils@4.3.3: 19437 19445 dependencies: