webPage(type, path, extra) builds the schema.org page data every page needs: the canonical URL as @id and url, name and description from the page registry, the language, and page-specific fields last. aboutPage now uses it and gives exactly the same output. The Portfolio and Soorten fotoshoots pages build their structured data on it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
176 lines
6.2 KiB
TypeScript
176 lines
6.2 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 { AboutPageContent, SiteContent } from './content/types.ts';
|
|
import { knowsAboutList } from './lib/knowsAboutList.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');
|
|
}
|
|
|
|
// Stable ids, so the business on every page and Andrea on the about page
|
|
// refer to each other (BR-SD-03)
|
|
export const businessId = `${siteUrl}/#business`;
|
|
export const personId = `${siteUrl}/over-mij#andrea`;
|
|
|
|
const huizen = {
|
|
'@type': 'PostalAddress',
|
|
addressLocality: 'Huizen',
|
|
addressCountry: 'NL',
|
|
} as const;
|
|
|
|
// 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',
|
|
'@id': businessId,
|
|
name: siteName,
|
|
url: `${siteUrl}/`,
|
|
logo: `${siteUrl}/logo.png`,
|
|
image: siteUrl + defaultOgImage.path,
|
|
description: sitePages['/'].description,
|
|
address: huizen,
|
|
areaServed: { '@type': 'Place', name: 'Huizen' },
|
|
sameAs: visibleSocials(content.socials).map((social) => social.href),
|
|
founder: { '@id': personId },
|
|
};
|
|
}
|
|
|
|
// Andrea as a person (BR-SD-01..05). Optional lists are left out when empty;
|
|
// no e-mail address, for the same reason as above.
|
|
export function person(
|
|
content: AboutPageContent['person'],
|
|
site: SiteContent,
|
|
image: string,
|
|
) {
|
|
const sameAs = visibleSocials(site.socials).map((social) => social.href);
|
|
const knowsAbout = knowsAboutList(content.knowsAbout);
|
|
return {
|
|
'@type': 'Person',
|
|
'@id': personId,
|
|
name: content.name,
|
|
jobTitle: content.jobTitle,
|
|
image,
|
|
address: huizen,
|
|
url: canonicalUrl('/over-mij'),
|
|
worksFor: { '@id': businessId },
|
|
...(knowsAbout.length > 0 ? { knowsAbout } : {}),
|
|
...(sameAs.length > 0 ? { sameAs } : {}),
|
|
};
|
|
}
|
|
|
|
// The schema.org page types the site uses; add one here when a page needs it
|
|
export type WebPageType =
|
|
'WebPage' | 'AboutPage' | 'ContactPage' | 'ImageGallery' | 'CollectionPage';
|
|
|
|
// Structured data for a page: its canonical URL as @id, name and description
|
|
// from the page registry. Page-specific fields (mainEntity, about, ...) come
|
|
// in through `extra`, which is added last and keeps its type for callers.
|
|
export function webPage<Extra extends object = Record<never, never>>(
|
|
type: WebPageType,
|
|
path: RoutePath,
|
|
extra: Extra = {} as Extra,
|
|
) {
|
|
const page = sitePages[path];
|
|
return {
|
|
'@context': 'https://schema.org',
|
|
'@type': type,
|
|
'@id': canonicalUrl(path),
|
|
url: canonicalUrl(path),
|
|
name: page.title,
|
|
description: page.description,
|
|
inLanguage: 'nl-NL',
|
|
...extra,
|
|
};
|
|
}
|
|
|
|
// The about page with Andrea as its subject (BR-SD-06); her image is the
|
|
// page's preview image from the registry
|
|
export function aboutPage(
|
|
path: RoutePath,
|
|
content: AboutPageContent['person'],
|
|
site: SiteContent,
|
|
) {
|
|
const image = siteUrl + (sitePages[path].ogImage ?? defaultOgImage).path;
|
|
return webPage('AboutPage', path, {
|
|
mainEntity: person(content, site, image),
|
|
});
|
|
}
|
|
|
|
// A head script tag with structured data, escaped by jsonLdScript (BR-SD-07)
|
|
export function structuredDataScript(data: unknown) {
|
|
return {
|
|
type: 'application/ld+json',
|
|
children: jsonLdScript(data),
|
|
};
|
|
}
|
|
|
|
// 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: [structuredDataScript(professionalService(content))],
|
|
};
|
|
}
|