Schema Component
The <Schema /> component serializes your Schema.org entities into a sanitized <script type="application/ld+json"> tag with zero client-side JavaScript.
1. Imports
Section titled “1. Imports”Astro
---import { Schema } from '@unschema-graph/astro';---
<head> <Schema items={[organization, article]} /></head>Svelte 5
<script lang="ts">import { Schema } from '@unschema-graph/svelte';</script>
<!-- Automatically renders in document <head> via <svelte:head> --><Schema items={[organization, article]} baseUrl="https://example.com" />2. Props Reference
Section titled “2. Props Reference”| Prop | Type | Default | Description |
|---|---|---|---|
items |
(SchemaOrgEntity | null | undefined)[] |
undefined |
Array of entities to merge into the unified @graph. |
item |
SchemaOrgEntity | null |
undefined |
Convenience prop for passing a single entity. |
data |
SchemaOrgEntity | SchemaOrgEntity[] | null |
undefined |
Universal alias accepting a single entity or an array. |
baseUrl |
string |
See priority below | Resolves explicit relative @id values against this canonical origin. |
inLanguage |
string |
See priority below | Fills missing language code on language-aware entities. |
pretty |
boolean |
false |
Enables indented, multi-line JSON output for debugging. |
indent |
number |
2 |
Space indentation width when pretty is enabled. |
graph |
boolean |
true |
Wraps entities in a root @graph. If false and only 1 entity is provided, renders flat root. |
context |
string |
'https://schema.org' |
Root JSON-LD context URL. |
debug (Astro only) |
boolean |
false |
Injects an HTML diagnostic comment and prints development terminal logs. |
3. Resolution Priority
Section titled “3. Resolution Priority”When resolving relative identifiers (#organization, /posts/hello#article):
- Astro component:
baseUrlprop → integration/global configuration →Astro.sitefallback. The Astro integration writes itsbaseUrloption to that global configuration, or writesconfig.sitewhen the option is omitted. - Svelte component:
baseUrlprop → global configuration. - Core API: the
baseUrlpassed inGraphOptions.getGlobalConfig()is available to application code, butbuildJsonLdGraph()does not read it automatically.
For language enrichment, an entity’s existing inLanguage is always preserved. Otherwise Astro
uses the component prop, then Astro.currentLocale, then the integration/global default. Svelte
uses the component prop, then the global default.
4. Usage Patterns
Section titled “4. Usage Patterns”Passing Multiple Entities (items)
Section titled “Passing Multiple Entities (items)”Recommended pattern: pass all layout and page entities to a single <Schema /> call:
<Schema items={[publisherOrg, authorPerson, articleNode, breadcrumbs]} />Passing a Single Entity (item)
Section titled “Passing a Single Entity (item)”<Schema item={organization} />Pretty-Printing in Development
Section titled “Pretty-Printing in Development”<Schema items={[org, website]} pretty={import.meta.env.DEV} debug={import.meta.env.DEV}/>