[READ-ONLY] a fast, modern browser for the npm registry
at main 41 lines 1.1 kB view raw
1import type { Thing, WebSite, WithContext } from 'schema-dts' 2 3/** 4 * Inject JSON-LD script into head 5 */ 6export function setJsonLd(schema: WithContext<Thing> | WithContext<Thing>[]): void { 7 const schemas = Array.isArray(schema) ? schema : [schema] 8 9 useHead({ 10 script: schemas.map((s, i) => ({ 11 type: 'application/ld+json', 12 innerHTML: JSON.stringify(s), 13 key: `json-ld-${i}`, 14 })), 15 }) 16} 17 18/** 19 * Create WebSite schema with search action 20 */ 21export function createWebSiteSchema(options?: { 22 name?: string 23 description?: string 24}): WithContext<WebSite> { 25 const siteUrl = 'https://npmx.dev' 26 return { 27 '@context': 'https://schema.org', 28 '@type': 'WebSite', 29 'name': options?.name ?? 'npmx', 30 'url': siteUrl, 31 'description': options?.description ?? 'A fast, modern browser for the npm registry', 32 'potentialAction': { 33 '@type': 'SearchAction', 34 'target': { 35 '@type': 'EntryPoint', 36 'urlTemplate': `${siteUrl}/search?q={search_term_string}`, 37 }, 38 'query': 'required name=search_term_string', 39 }, 40 } 41}