diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1e47389..212a31b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,6 +19,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + # Full history: Starlight dates "Last updated" (and dateModified) from each file's last commit + fetch-depth: 0 - uses: actions/setup-node@v4 with: node-version: 24 diff --git a/astro.config.mjs b/astro.config.mjs index f12b745..a908d4a 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -21,6 +21,8 @@ export default defineConfig({ editLink: { baseUrl: 'https://github.com/BazarPro/docs/edit/main/' }, lastUpdated: true, customCss: ['./src/styles/theme.css'], + // Preview image and structured data for search engines (src/routeData.ts) + routeMiddleware: './src/routeData.ts', // Plausible (data.bazarpro.de): cookie-free page views; options are set per site in Plausible head: [ { diff --git a/src/content/docs/en/index.mdx b/src/content/docs/en/index.mdx index 42b0335..8177943 100644 --- a/src/content/docs/en/index.mdx +++ b/src/content/docs/en/index.mdx @@ -1,5 +1,5 @@ --- -title: BazarPro Docs +title: Help and guides for children's bazaars, bike sales and flea markets description: Guides for children's clothing bazaars, bike sales and flea markets with BazarPro – for organizers, sellers and visitors. template: splash hero: diff --git a/src/content/docs/index.mdx b/src/content/docs/index.mdx index 896d79d..0cc58db 100644 --- a/src/content/docs/index.mdx +++ b/src/content/docs/index.mdx @@ -1,5 +1,5 @@ --- -title: BazarPro Docs +title: Hilfe und Ratgeber für Kinderbasar, Fahrradbörse und Flohmarkt description: Anleitungen und Ratgeber für Kinderkleiderbasar, Fahrradbörse und Flohmarkt mit BazarPro – für Veranstalter, Verkäufer und Besucher. template: splash hero: diff --git a/src/routeData.ts b/src/routeData.ts new file mode 100644 index 0000000..a3f59a6 --- /dev/null +++ b/src/routeData.ts @@ -0,0 +1,81 @@ +import { defineRouteMiddleware } from '@astrojs/starlight/route-data'; + +/** + * SEO additions to Starlight's head tags: a preview image for shared links and + * structured data (schema.org) for search engines. + */ + +// Same picture as on bazarpro.de; 1200 × 630 as social networks expect +const PREVIEW_IMAGE = 'https://bazarpro.de/og-image.png'; + +const PUBLISHER = { + '@type': 'Organization', + name: 'BazarPro', + url: 'https://bazarpro.de', + logo: 'https://bazarpro.de/logo.png', +}; + +function jsonLd(data: Record) { + return { + tag: 'script' as const, + attrs: { type: 'application/ld+json' }, + content: JSON.stringify(data).replace(/ { + const route = context.locals.starlightRoute; + const { title, description, template } = route.entry.data; + const site = context.site ?? new URL('https://docs.bazarpro.de'); + const url = new URL(context.url.pathname, site).href; + const home = new URL(route.locale ? `/${route.locale}/` : '/', site).href; + + route.head.push( + { tag: 'meta', attrs: { property: 'og:image', content: PREVIEW_IMAGE } }, + { tag: 'meta', attrs: { property: 'og:image:width', content: '1200' } }, + { tag: 'meta', attrs: { property: 'og:image:height', content: '630' } }, + { tag: 'meta', attrs: { name: 'twitter:image', content: PREVIEW_IMAGE } } + ); + + if (route.id === '404' || route.id.endsWith('/404')) return; + + if (template === 'splash' && url === home) { + route.head.push( + jsonLd({ + '@context': 'https://schema.org', + '@type': 'WebSite', + name: route.siteTitle, + url: home, + inLanguage: route.lang, + description, + publisher: PUBLISHER, + }) + ); + return; + } + + route.head.push( + jsonLd({ + '@context': 'https://schema.org', + '@type': 'Article', + headline: title, + description, + url, + mainEntityOfPage: url, + inLanguage: route.lang, + ...(route.lastUpdated ? { dateModified: route.lastUpdated.toISOString() } : {}), + image: PREVIEW_IMAGE, + author: PUBLISHER, + publisher: PUBLISHER, + }), + jsonLd({ + '@context': 'https://schema.org', + '@type': 'BreadcrumbList', + // Sidebar groups have no page of their own, Google wants a URL for each level + itemListElement: [ + { '@type': 'ListItem', position: 1, name: route.siteTitle, item: home }, + { '@type': 'ListItem', position: 2, name: title, item: url }, + ], + }) + ); +});