Skip to content

Schema Component

The <Schema /> component serializes your Schema.org entities into a sanitized <script type="application/ld+json"> tag with zero client-side JavaScript.


Astro

src/layouts/BaseLayout.astro
---
import { Schema } from '@unschema-graph/astro';
---
<head>
<Schema items={[organization, article]} />
</head>

Svelte 5

src/routes/+page.svelte
<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" />

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.

When resolving relative identifiers (#organization, /posts/hello#article):

  1. Astro component: baseUrl prop → integration/global configuration → Astro.site fallback. The Astro integration writes its baseUrl option to that global configuration, or writes config.site when the option is omitted.
  2. Svelte component: baseUrl prop → global configuration.
  3. Core API: the baseUrl passed in GraphOptions. getGlobalConfig() is available to application code, but buildJsonLdGraph() 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.


Recommended pattern: pass all layout and page entities to a single <Schema /> call:

src/pages/article.astro
<Schema items={[publisherOrg, authorPerson, articleNode, breadcrumbs]} />
src/pages/about.astro
<Schema item={organization} />
src/pages/index.astro
<Schema
items={[org, website]}
pretty={import.meta.env.DEV}
debug={import.meta.env.DEV}
/>