Skip to content

Your first schema with Astro

This guide starts with one Article. You will see the generated JSON-LD before learning how to connect a complete page graph.

You need Node.js 22.12 or newer and an Astro 5, 6, or 7 project.

Terminal window
pnpm add @unschema-graph/astro zod

Using npm, yarn, or bun? See all installation commands.

Create or open an Astro page and render <Schema /> inside its <head>:

src/pages/hello.astro
---
import { Article, Schema } from '@unschema-graph/astro';
const article = Article({
headline: 'My first typed JSON-LD',
image: 'https://example.com/cover.jpg',
datePublished: '2026-09-29',
author: 'Ada Lovelace',
});
---
<html lang="en">
<head>
<title>{article.headline}</title>
<Schema item={article} graph={false} />
</head>
<body><h1>{article.headline}</h1></body>
</html>

The builder checks required fields with Zod. Astro renders the component on the server, so this example adds no client-side JavaScript.

Open the page source and find:

<script type="application/ld+json">
{"@context":"https://schema.org","@type":"Article","headline":"My first typed JSON-LD"}
</script>

The real script also contains the image, publication date, and author. The shortened output above shows the structure to look for.

A production article usually belongs to a WebPage and WebSite, has a publisher Organization, and references those entities with stable @id values. Pass them together with items={[organization, website, page, article]} instead of rendering separate scripts.

Build that connected graph.

Learn what builders, entities, identities, and graphs mean, or open the complete Astro integration reference.