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 relative @id, url, and item values against this canonical origin. |
inLanguage |
string |
Astro: Astro.currentLocaleSvelte: undefined |
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. Base URL Resolution Priority
Section titled “3. Base URL Resolution Priority”When resolving relative identifiers (#organization, /posts/hello#article):
- Astro component:
baseUrlprop →Astro.site→ global configuration. The Astro integration writes itsbaseUrloption to that global configuration, or falls back toconfig.sitewhen the option is omitted. - Svelte component: the
baseUrlprop only. It does not read the Core global configuration automatically. - Core API: the
baseUrlpassed inGraphOptions.getGlobalConfig()is available to application code, butbuildJsonLdGraph()does not read it automatically.
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}/>