Put a component on the page and pass the data it already has. astro-structured-data writes the schema.org JSON-LD and meta tags that search engines read, and stops the build when the data would not be valid.
$npminstall@casoon/astro-structured-data
$pnpmadd@casoon/astro-structured-data
$yarnadd@casoon/astro-structured-data
MITnpm 2.4.1Astro 5 · 6 · 70 kB client JS
What it is for
From the data on your page to a richer search result
Dates, prices, ratings and venues only show up in search when the page describes them as schema.org data. The components turn your props into exactly that.
Illustration with the data of three examples from the showcase. Whether and how a rich result appears is decided by the search engine.
Why it exists
01
Hand-written JSON-LD fails silently
A German date, a € sign instead of EUR or a missing field raises no error. The markup is simply ignored, and you notice weeks later in Search Console.
02
Your pages already have the data
Titles, dates, prices and addresses sit in frontmatter, content collections or your CMS. Pass them as props instead of keeping a second copy as JSON.
03
Errors surface in the build
Every component checks its props. Wrong data stops the build with the component, the page and the field, so it never reaches production.
How it works
Props in, JSON-LD and meta tags out
Each component validates its props and writes a JSON-LD block. Optionally, all schemas of a page are merged into one @graph, and canonical, Open Graph and Twitter tags are derived from the same data. Nothing is added to the JavaScript your visitors download.
Blogs, shops, local businesses, events, job boards: each component knows which fields its rich result needs. The generic <Schema> covers any other schema.org type.
Docs: the README is a short overview that links to the documentation on the project site; everything it explained before is in the docs. The graph mode and on-demand rendering guides show how graph mode works and the measured time to first byte as diagrams.
npm: the package's homepage is the project site on GitHub Pages instead of the retired product page.
Pages: the project site uses the current shared theme (0.12.10).
Project site: search result cards and source labels meet 4.5:1 contrast again with the current theme, and the terminal scenes are rebuilt with castwright 0.6.
Frequently asked questions
What happens if I pass invalid data to a component?
The build fails with the component, the page and the offending field, for example a date that is not ISO 8601 or a currency that is not an ISO 4217 code. The markup never reaches production silently wrong.
Does this add any JavaScript to the pages my visitors load?
No. Every component runs at build time (or on the server in SSR) and only writes a JSON-LD script tag and meta tags into the HTML.
What if I leave out a field Google recommends but does not require?
The build still succeeds. After astro build, the integration lists each missing recommended field once per type, so you can decide whether to add it.
Can I combine several schemas on one page into a single JSON-LD block?
Yes. With useGraph set, all schemas of a page are merged into one @graph block wherever the SchemaGraph component is placed, instead of one script tag per component.
Which Astro and Node versions are supported?
Astro 5, 6 and 7, with Node 18 or later. The compatibility table in the README lists which package version matches which Astro range.