Files
AndreaSlopFotografie/web/src/seo.ts
T
SluijsensandClaude Opus 5.5 4d6408b607 Completes the front-end shell with footer, status pages and SEO
Adds the footer, back-to-top button, skip link, placeholder routes,
404 and error pages inside the shell, plus per-page SEO from a single
page registry (canonical URLs, Open Graph image, JSON-LD, generated
sitemap.xml and robots.txt).

Theme tokens and recipes replace repeated styling, the hero loads only
the active and neighbouring slides, and the e-mail address is joined
in the browser to keep it out of the HTML and bundle.

Adds Vitest with property-based (fast-check) and axe tests, ESLint,
security headers for dev and preview, Lighthouse CI and a `pnpm check`
script that runs all quality gates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:05:02 +02:00

102 lines
3.8 KiB
TypeScript

// SEO: head-tags per pagina en voor de hele site, plus gestructureerde data.
// Titels en beschrijvingen staan in het pagina-register (sitePages.ts).
import type { SiteContent } from './content/types.ts';
import { visibleSocials } from './lib/visibleSocials.ts';
import type { RoutePath } from './navigation.ts';
import sitePages from './sitePages.ts';
export const siteUrl = 'https://andreaslop.nl';
export const siteName = 'Andrea Slop Fotografie';
// Preview-afbeelding voor WhatsApp, Facebook en LinkedIn (public/og-image.jpg)
export const defaultOgImage = {
path: '/og-image.jpg',
width: 1200,
height: 630,
alt: 'Takjes paarse heide op een arm met een bloementattoo',
};
// Absolute URL zonder slash aan het eind (behalve de homepage), zonder query
// of hash (BR-SEO-02)
export function canonicalUrl(path: string, base: string = siteUrl): string {
const clean = path.split(/[?#]/)[0].replace(/\/+$/, '');
if (clean === '') {
return `${base}/`;
}
return base + (clean.startsWith('/') ? clean : `/${clean}`);
}
// Head-tags van een pagina uit het register (BR-SEO-01 t/m 04)
export function pageHead(path: RoutePath) {
const page = sitePages[path];
const title = `${page.title} | ${siteName}`;
const url = canonicalUrl(path);
const image = page.ogImage ?? defaultOgImage;
return {
meta: [
{ title },
{ name: 'description', content: page.description },
// noindex voor placeholders, tot de echte pagina live gaat
...(page.indexed ? [] : [{ name: 'robots', content: 'noindex' }]),
// Voor link-previews (WhatsApp, Facebook, LinkedIn)
{ property: 'og:title', content: title },
{ property: 'og:description', content: page.description },
{ property: 'og:url', content: url },
{ property: 'og:image', content: siteUrl + image.path },
{ property: 'og:image:alt', content: image.alt },
{ property: 'og:image:width', content: String(image.width) },
{ property: 'og:image:height', content: String(image.height) },
],
links: [{ rel: 'canonical', href: url }],
};
}
// JSON voor een <script type="application/ld+json">. <, > en & worden
// ge-escaped, zodat content het script-element nooit kan afsluiten (BR-SEO-05).
export function jsonLdScript(data: unknown): string {
return JSON.stringify(data)
.replace(/</g, '\\u003c')
.replace(/>/g, '\\u003e')
.replace(/&/g, '\\u0026');
}
// Gestructureerde data: een lokale fotograaf in Huizen. Bewust zonder
// e-mailadres, anders staat het alsnog leesbaar in de pagina.
export function professionalService(content: SiteContent) {
return {
'@context': 'https://schema.org',
'@type': 'ProfessionalService',
name: siteName,
url: `${siteUrl}/`,
logo: `${siteUrl}/logo.png`,
image: siteUrl + defaultOgImage.path,
description: sitePages['/'].description,
address: {
'@type': 'PostalAddress',
addressLocality: 'Huizen',
addressCountry: 'NL',
},
areaServed: { '@type': 'Place', name: 'Huizen' },
sameAs: visibleSocials(content.socials).map((social) => social.href),
};
}
// Tags die voor de hele site gelden, plus de gestructureerde data
export function siteHead(content: SiteContent) {
return {
meta: [
{ property: 'og:site_name', content: siteName },
{ property: 'og:locale', content: 'nl_NL' },
{ property: 'og:type', content: 'website' },
{ name: 'twitter:card', content: 'summary_large_image' },
],
scripts: [
{
type: 'application/ld+json',
children: jsonLdScript(professionalService(content)),
},
],
};
}