feat(kb) - add structured ld+json data to KB pages (#51498)

## Problem

Follow up to #51497 and #51496, but for KB.

Currently the KB has no [structured
metadata](https://developers.google.com/search/docs/appearance/structured-data/intro-structured-data)
about any of the pages, which can be important for LLM-indexing.

## Solution

Follow up to #51497 and #51496, but for KB.

Adds two types of structured data to every KB article:
- Breadcrumb
- TechArticle
(validation available at
[schema.org](https://validator.schema.org/#url=https%3A%2F%2Fkb-git-kody-devrel-698-kb-structured-data-supabase.vercel.app%2Fkb%2Fguides%2Fsample-guide))

Future work will likely add in an FAQ type.

## Preview links


https://kb-git-kody-devrel-698-kb-structured-data-supabase.vercel.app/kb/guides/sample-guide
<img width="1101" height="571" alt="image"
src="https://github.com/user-attachments/assets/dbd95f32-3aaa-4c2e-891b-ee31cbef34dd"
/>

https://validator.schema.org/#url=https%3A%2F%2Fkb-git-kody-devrel-698-kb-structured-data-supabase.vercel.app%2Fkb%2Fguides%2Fsample-guide

---------

Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
Kody JacksonandClaude Haiku 5.5 authored and GitHub committed 2026-10-20 08:39:33 -05:00
1 parent 2abcb83cf1
commit 8993001471
6 files changed
+107 -6

No files matched your search

+3 -2
View File
@@ -15,16 +15,17 @@ interface Props {
github_url?: string
viewGitHubLink?: string
date?: string
jsonLd?: Record<string, unknown> | Record<string, unknown>[]
}
const { title, description, topics = [], github_url, viewGitHubLink, date } = Astro.props
const { title, description, topics = [], github_url, viewGitHubLink, date, jsonLd } = Astro.props
function isKnownTopic(topic: string): topic is Topic {
return (TOPIC_NAMES as readonly string[]).includes(topic)
}
---
<Layout title={title} description={description}>
<Layout title={title} description={description} jsonLd={jsonLd}>
<article class="prose max-w-3xl mx-auto px-6 py-16">
<h1>{title}</h1>
{date && <p class="text-sm pb-4">{date}</p>}
+4 -1
View File
@@ -3,13 +3,15 @@ import { genFaviconLinks } from 'common/MetaFavicons/icons'
import Footer from '../components/Footer.astro'
import { Header } from '../components/Header'
import '../styles/globals.css'
import { serializeJsonLd } from '../lib/json-ld'
interface Props {
title: string
description?: string
jsonLd?: Record<string, unknown> | Record<string, unknown>[]
}
const { title, description } = Astro.props
const { title, description, jsonLd } = Astro.props
const faviconRoute = import.meta.env.DEV ? '/favicon/local' : '/favicon'
---
@@ -44,6 +46,7 @@ const faviconRoute = import.meta.env.DEV ? '/favicon/local' : '/favicon'
/>
<link rel="sitemap" href={`${import.meta.env.BASE_URL}/sitemap-index.xml`} />
<title>{title} | Supabase Knowledge Base</title>
{jsonLd && <script type="application/ld+json" is:inline set:html={serializeJsonLd(jsonLd)} />}
</head>
<body>
<Header client:load />
+63
View File
@@ -0,0 +1,63 @@
// Canonical origin + base path from astro.config.mjs (`site` and `base`).
const KB_ORIGIN = 'https://supabase.com'
export const KB_BASE_URL = `${KB_ORIGIN}/kb`
type JsonLdSchema = Record<string, unknown> | Record<string, unknown>[]
export function serializeJsonLd(schema: JsonLdSchema): string {
return JSON.stringify(schema)
.replace(/</g, '\\u003c')
.replace(/>/g, '\\u003e')
.replace(/&/g, '\\u0026')
}
interface TechArticleSchemaInput {
url: string
headline: string
description?: string
}
// Guides carry no publish or modified dates in their frontmatter, so the
// schema omits them rather than inventing values.
export function techArticleSchema(input: TechArticleSchemaInput) {
return {
'@context': 'https://schema.org',
'@type': 'TechArticle',
'@id': `${input.url}#page`,
mainEntityOfPage: {
'@type': 'WebPage',
'@id': input.url,
},
url: input.url,
headline: input.headline,
description: input.description,
inLanguage: 'en',
publisher: {
'@type': 'Organization',
name: 'Supabase',
url: KB_ORIGIN,
logo: {
'@type': 'ImageObject',
url: `${KB_ORIGIN}/images/og/supabase-og.png`,
},
},
}
}
export interface BreadcrumbItem {
name: string
url: string
}
export function breadcrumbListSchema(items: BreadcrumbItem[]) {
return {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
itemListElement: items.map((item, index) => ({
'@type': 'ListItem',
position: index + 1,
name: item.name,
item: item.url,
})),
}
}
+19 -1
View File
@@ -3,6 +3,7 @@ import { getCollection, render } from 'astro:content'
import { Admonition } from 'ui-patterns/Admonition'
import ArticleLayout from '../../layouts/ArticleLayout.astro'
import { breadcrumbListSchema, KB_BASE_URL, techArticleSchema } from '../../lib/json-ld'
export async function getStaticPaths() {
const guides = await getCollection('guides')
@@ -18,8 +19,25 @@ const { Content } = await render(guide)
// guide.filePath is relative to the kb app root, e.g. "src/content/guides/foo.mdx"
const viewGitHubLink = `https://github.com/supabase/supabase/blob/master/apps/kb/${guide.filePath}`
const url = `${KB_BASE_URL}/guides/${guide.id}`
const jsonLd = [
techArticleSchema({ url, headline: title, description }),
breadcrumbListSchema([
{ name: 'Knowledge Base', url: KB_BASE_URL },
{ name: title, url },
]),
]
---
<ArticleLayout title={title} description={description} topics={topics} github_url={github_url} viewGitHubLink={viewGitHubLink} date={date}>
<ArticleLayout
title={title}
description={description}
topics={topics}
github_url={github_url}
viewGitHubLink={viewGitHubLink}
date={date}
jsonLd={jsonLd}
>
<Content components={{ Admonition }} />
</ArticleLayout>
+7 -1
View File
@@ -2,6 +2,7 @@
import { getCollection } from 'astro:content'
import Layout from '../../layouts/Layout.astro'
import { breadcrumbListSchema, KB_BASE_URL } from '../../lib/json-ld'
import { TOPICS, topicToSlug } from '../../lib/topics'
export async function getStaticPaths() {
@@ -25,9 +26,14 @@ export async function getStaticPaths() {
}
const { topic, description, guides } = Astro.props
const url = `${KB_BASE_URL}/topics/${topicToSlug(topic)}`
const jsonLd = breadcrumbListSchema([
{ name: 'Knowledge Base', url: KB_BASE_URL },
{ name: topic, url },
])
---
<Layout title={topic} description={description}>
<Layout title={topic} description={description} jsonLd={jsonLd}>
<article class="prose max-w-3xl mx-auto px-6 py-16">
<h1>{topic}</h1>
<p class="lead">{description}</p>
@@ -3,6 +3,7 @@ import { getCollection, render } from 'astro:content'
import { Admonition } from 'ui-patterns/Admonition'
import ArticleLayout from '../../layouts/ArticleLayout.astro'
import { breadcrumbListSchema, KB_BASE_URL, techArticleSchema } from '../../lib/json-ld'
import { getGithubUrlsBySlug } from '../../lib/troubleshooting-db'
export async function getStaticPaths() {
@@ -22,8 +23,17 @@ export async function getStaticPaths() {
const { entry, githubUrl } = Astro.props
const { title, description, topics } = entry.data
const { Content } = await render(entry)
const url = `${KB_BASE_URL}/troubleshooting/${entry.id}`
const jsonLd = [
techArticleSchema({ url, headline: title, description }),
breadcrumbListSchema([
{ name: 'Knowledge Base', url: KB_BASE_URL },
{ name: title, url },
]),
]
---
<ArticleLayout title={title} description={description} topics={topics} github_url={githubUrl}>
<ArticleLayout title={title} description={description} topics={topics} github_url={githubUrl} jsonLd={jsonLd}>
<Content components={{ Admonition }} />
</ArticleLayout>