Adds the shoot-type pages content and SEO foundation

Five pages under /soorten-fotoshoots/<id> with draft copy awaiting
Andrea's approval (DRAFT markers), structured data (Service,
BreadcrumbList, FAQPage), sitemap and Lighthouse entries. The overview
route moves to soorten-fotoshoots/index.tsx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-30 13:31:46 +01:00
co-authored by Claude Opus 5.5
parent 14164971f3
commit e5f4348178
78 changed files with 8729 additions and 110 deletions
+187
View File
@@ -0,0 +1,187 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import {
knownPlaceholders,
placeholderName,
plainText,
richText,
textWithPlaceholders,
} from '../test/arbitraries';
import { fillPlaceholders, fillRichText } from './fillPlaceholders';
const values = {
reactietermijn: '1-2 werkdagen',
aanbetaling: '€ 50',
locatie: 'Een newbornshoot is bij jou thuis.',
duur: '1-2 uur fotografie',
opleverduur: '2–3 weken',
};
// A value for every known placeholder; values never contain braces, as in
// the content
const allValues = fc
.tuple(...knownPlaceholders.map(() => plainText))
.map((texts) =>
Object.fromEntries(
knownPlaceholders.map((name, index) => [name, texts[index]]),
),
);
// Values for some names, known or not
const someValues = fc.dictionary(placeholderName, plainText, { maxKeys: 6 });
// Text in which no {name} appears, stray braces included
const withoutPlaceholder = fc
.string()
.filter((text) => !/\{[^{}]*\}/.test(text));
const hasKnownPlaceholder = (text: string) =>
knownPlaceholders.some((name) => text.includes(`{${name}}`));
describe('fillPlaceholders', () => {
it('fills in each placeholder', () => {
expect(
fillPlaceholders('Ik reageer binnen {reactietermijn}.', values),
).toBe('Ik reageer binnen 1-2 werkdagen.');
expect(fillPlaceholders('Aanbetaling {aanbetaling}.', values)).toBe(
'Aanbetaling € 50.',
);
expect(fillPlaceholders('{locatie}', values)).toBe(values.locatie);
expect(fillPlaceholders('{duur}', values)).toBe(values.duur);
expect(fillPlaceholders('Binnen {opleverduur}.', values)).toBe(
'Binnen 2–3 weken.',
);
});
it('fills in a repeated placeholder every time', () => {
expect(fillPlaceholders('{duur} en nog eens {duur}', values)).toBe(
'1-2 uur fotografie en nog eens 1-2 uur fotografie',
);
});
it('keeps unknown placeholders, stray braces and inherited names', () => {
expect(fillPlaceholders('{onbekend}', values)).toBe('{onbekend}');
expect(fillPlaceholders('{Duur} { duur}', values)).toBe(
'{Duur} { duur}',
);
expect(fillPlaceholders('{ en }', values)).toBe('{ en }');
expect(fillPlaceholders('}{', values)).toBe('}{');
expect(fillPlaceholders('{}', values)).toBe('{}');
expect(fillPlaceholders('{constructor} {toString}', values)).toBe(
'{constructor} {toString}',
);
expect(fillPlaceholders('{{duur}}', values)).toBe(
'{1-2 uur fotografie}',
);
});
it('inserts a value literally', () => {
expect(fillPlaceholders('{duur}', { duur: '$& $1 $$' })).toBe(
'$& $1 $$',
);
});
it('returns text without placeholders as it is (invariant)', () => {
fc.assert(
fc.property(
withoutPlaceholder,
fc.dictionary(fc.string(), fc.string()),
(text, given) => {
expect(fillPlaceholders(text, given)).toBe(text);
},
),
);
});
it('changes nothing when filled in a second time (idempotency)', () => {
fc.assert(
fc.property(textWithPlaceholders, someValues, (text, given) => {
const once = fillPlaceholders(text, given);
expect(fillPlaceholders(once, given)).toBe(once);
}),
);
});
it('leaves no known placeholder behind (invariant)', () => {
fc.assert(
fc.property(textWithPlaceholders, allValues, (text, given) => {
expect(hasKnownPlaceholder(fillPlaceholders(text, given))).toBe(
false,
);
}),
);
});
});
describe('fillRichText', () => {
it('fills in text pieces and link texts, and keeps the link target', () => {
expect(
fillRichText(
[
'Binnen {opleverduur}. ',
{
text: 'Vraag het binnen {reactietermijn}',
to: '/contact',
},
{
text: '{duur}',
to: '/soorten-fotoshoots',
hash: 'newborn',
},
],
values,
),
).toEqual([
'Binnen 2–3 weken. ',
{ text: 'Vraag het binnen 1-2 werkdagen', to: '/contact' },
{
text: '1-2 uur fotografie',
to: '/soorten-fotoshoots',
hash: 'newborn',
},
]);
});
it('fills every piece in its place and keeps links as links with their target (invariant)', () => {
fc.assert(
fc.property(richText, someValues, (text, given) => {
const filled = fillRichText(text, given);
expect(filled).toHaveLength(text.length);
filled.forEach((piece, index) => {
const before = text[index];
if (typeof before === 'string') {
expect(piece).toBe(fillPlaceholders(before, given));
} else {
expect(piece).toEqual({
...before,
text: fillPlaceholders(before.text, given),
});
}
});
}),
);
});
it('changes nothing when filled in a second time (idempotency)', () => {
fc.assert(
fc.property(richText, someValues, (text, given) => {
const once = fillRichText(text, given);
expect(fillRichText(once, given)).toEqual(once);
}),
);
});
it('leaves no known placeholder behind (invariant)', () => {
fc.assert(
fc.property(richText, allValues, (text, given) => {
fillRichText(text, given).forEach((piece) => {
expect(
hasKnownPlaceholder(
typeof piece === 'string' ? piece : piece.text,
),
).toBe(false);
});
}),
);
});
});
+31
View File
@@ -0,0 +1,31 @@
import type { RichText } from '../content/types.ts';
// A placeholder: a name between braces, with no brace inside
const PLACEHOLDER = /\{([^{}]*)\}/g;
// Fills in every {name} whose name is one of the values, so a figure that
// is data (reply time, deposit, duration, ...) is written in one place only
// (D8, NFR-ST-04). Unknown placeholders and other text stay as they are;
// only own properties count, so {constructor} is no placeholder. The values
// are inserted literally ($& and the like mean nothing here).
export function fillPlaceholders(
text: string,
values: Readonly<Record<string, string>>,
): string {
return text.replace(PLACEHOLDER, (match, name: string) =>
Object.hasOwn(values, name) ? values[name] : match,
);
}
// The same for running text: the text pieces and the link texts are filled
// in, link targets stay as they are
export function fillRichText(
text: RichText,
values: Readonly<Record<string, string>>,
): RichText {
return text.map((piece) =>
typeof piece === 'string'
? fillPlaceholders(piece, values)
: { ...piece, text: fillPlaceholders(piece.text, values) },
);
}
+33
View File
@@ -0,0 +1,33 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import { richText } from '../test/arbitraries';
import { richTextToPlain } from './richTextToPlain';
describe('richTextToPlain', () => {
it('reads links by their text, without adding spaces', () => {
expect(
richTextToPlain([
'Staat je vraag er niet tussen? ',
{ text: 'Stuur gerust een berichtje', to: '/contact' },
'.',
]),
).toBe('Staat je vraag er niet tussen? Stuur gerust een berichtje.');
expect(richTextToPlain([])).toBe('');
expect(richTextToPlain(['Alleen tekst'])).toBe('Alleen tekst');
});
it('is the text pieces and link texts joined, as long as they are together (invariant)', () => {
fc.assert(
fc.property(richText, (text) => {
const pieces = text.map((piece) =>
typeof piece === 'string' ? piece : piece.text,
);
const plain = richTextToPlain(text);
expect(plain).toBe(pieces.join(''));
expect(plain.length).toBe(
pieces.reduce((sum, piece) => sum + piece.length, 0),
);
}),
);
});
});
+10
View File
@@ -0,0 +1,10 @@
import type { RichText } from '../content/types.ts';
// The text a visitor reads: text pieces as they are, links by their text,
// joined without anything in between (spaces belong to the text). For
// places that take plain text only, such as the FAQ in structured data.
export function richTextToPlain(text: RichText): string {
return text
.map((piece) => (typeof piece === 'string' ? piece : piece.text))
.join('');
}
+10
View File
@@ -9,6 +9,7 @@ import {
shootContactLink,
shootPortfolioLink,
} from './shootLinks';
import { shootPackage } from './shootPackage';
import { visiblePackages } from './visiblePackages';
const shoot = (id: string) => shootTypes.find((item) => item.id === id)!;
@@ -58,6 +59,15 @@ describe('shootContactLink', () => {
}),
);
});
it('agrees with shootPackage (invariant)', () => {
fc.assert(
fc.property(shootType, fc.array(anyPackage), (item, list) => {
const link = shootContactLink(item, list);
expect(link.search?.pakket).toBe(shootPackage(item, list)?.id);
}),
);
});
});
describe('shootPortfolioLink', () => {
+4 -6
View File
@@ -1,7 +1,7 @@
import type { PricingPackage, ShootType } from '../content/types.ts';
import type { RoutePath } from '../navigation.ts';
import type { PageMeta } from '../sitePages.ts';
import { visiblePackages } from './visiblePackages.ts';
import { shootPackage } from './shootPackage.ts';
// Where "Stuur een berichtje" goes: the contact page, with the shoot's
// package preselected when that package is shown (BR-SF-01..03, FR-CP-09)
@@ -9,11 +9,9 @@ export function shootContactLink(
shoot: ShootType,
packages: readonly PricingPackage[],
) {
const shown = visiblePackages(packages).some(
(pkg) => pkg.id === shoot.packageId,
);
return shown && shoot.packageId !== undefined
? { to: '/contact' as const, search: { pakket: shoot.packageId } }
const pkg = shootPackage(shoot, packages);
return pkg !== undefined
? { to: '/contact' as const, search: { pakket: pkg.id } }
: { to: '/contact' as const };
}
+63
View File
@@ -0,0 +1,63 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import packages from '../content/packages';
import shootTypes from '../content/shootTypes';
import { anyPackage, shootType } from '../test/arbitraries';
import { shootPackage } from './shootPackage';
import { visiblePackages } from './visiblePackages';
const shoot = (id: string) => shootTypes.find((item) => item.id === id)!;
describe('shootPackage', () => {
it('finds the package of the three shoots that have one', () => {
expect(shootPackage(shoot('newborn'), packages)).toMatchObject({
id: 'newborn',
price: 185,
});
expect(shootPackage(shoot('zwangerschap'), packages)).toMatchObject({
id: 'zwangerschap',
price: 175,
});
expect(shootPackage(shoot('gezin'), packages)).toMatchObject({
id: 'gezin',
price: 175,
});
});
it('finds none for Loveshoot and Portret', () => {
expect(shootPackage(shoot('loveshoot'), packages)).toBeUndefined();
expect(shootPackage(shoot('portret'), packages)).toBeUndefined();
});
it('finds none when the package is removed or invalid', () => {
expect(
shootPackage(
shoot('gezin'),
packages.filter((pkg) => pkg.id !== 'gezin'),
),
).toBeUndefined();
expect(
shootPackage(
shoot('newborn'),
packages.map((pkg) =>
pkg.id === 'newborn' ? { ...pkg, price: 0 } : pkg,
),
),
).toBeUndefined();
});
it('is undefined or a shown package with the id of the shoot (invariant)', () => {
fc.assert(
fc.property(shootType, fc.array(anyPackage), (item, list) => {
const result = shootPackage(item, list);
const shown = visiblePackages(list);
const expected = shown.some((pkg) => pkg.id === item.packageId);
expect(result !== undefined).toBe(expected);
if (result !== undefined) {
expect(result.id).toBe(item.packageId);
expect(shown).toContain(result);
}
}),
);
});
});
+12
View File
@@ -0,0 +1,12 @@
import type { PricingPackage, ShootType } from '../content/types.ts';
import { visiblePackages } from './visiblePackages.ts';
// The package a shoot points to, if that package is shown; a removed or
// invalid package, or none, gives undefined, and the page then shows
// "Prijs op aanvraag" (FR-ST-07, SECURITY-15)
export function shootPackage(
shoot: ShootType,
packages: readonly PricingPackage[],
): PricingPackage | undefined {
return visiblePackages(packages).find((pkg) => pkg.id === shoot.packageId);
}
+369
View File
@@ -0,0 +1,369 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import sleepingBaby from '../assets/portfolio/f41a8700.jpg';
import packages from '../content/packages';
import shootPageShared from '../content/shootPageShared';
import loveshootPage from '../content/shootPages/loveshoot';
import newbornPage from '../content/shootPages/newborn';
import shootTypes from '../content/shootTypes';
import siteContent from '../content/siteContent';
import type { ContentImage, RichText } from '../content/types';
import {
anyPackage,
anySiteContent,
contentImage,
knownPlaceholders,
plainText,
shootPageContent,
shootPageShared as anyShared,
shootType,
shootTypeId,
} from '../test/arbitraries';
import { shootPackage } from './shootPackage';
import { SHOOT_TYPE_IDS, shootPagePath } from './shootPages';
import {
MOSAIC_MIN_PHOTOS,
PROCESS_STEP_ORDER,
shootPageView,
type ShootPageSources,
type ShootPageView,
} from './shootPageView';
import { visiblePackages } from './visiblePackages';
const NBSP = ' ';
const sources: ShootPageSources = {
shootTypes,
packages,
shared: shootPageShared,
site: siteContent,
portfolioShoots: ['newborn'],
};
// Shoot types with unique ids, some with a detail photo
const shoots = fc.uniqueArray(
fc
.tuple(shootType, fc.option(contentImage, { nil: undefined }))
.map(([shoot, detailImage]) =>
detailImage === undefined ? shoot : { ...shoot, detailImage },
),
{ selector: (shoot) => shoot.id, maxLength: 5 },
);
// The sources as the CMS could deliver them. The reply time has no braces,
// as in the content: it is filled in as a value.
const anySources: fc.Arbitrary<ShootPageSources> = fc.record({
shootTypes: shoots,
packages: fc.array(anyPackage, { maxLength: 6 }),
shared: anyShared,
site: fc.tuple(anySiteContent, plainText).map(([site, replyTime]) => ({
...site,
contactForm: { ...site.contactForm, replyTime },
})),
portfolioShoots: fc.subarray([...SHOOT_TYPE_IDS]),
});
// A shoot id (mostly one of the sources), the sources, and page content
// that mostly belongs to that shoot, its photos repeating the shoot's own
const viewCase = anySources.chain((given) => {
const ids = given.shootTypes.map((shoot) => shoot.id);
const id =
ids.length > 0
? fc.oneof(
{ arbitrary: fc.constantFrom(...ids), weight: 4 },
shootTypeId,
)
: shootTypeId;
return id.chain((shootId) => {
const shoot = given.shootTypes.find((item) => item.id === shootId);
const reuse =
shoot === undefined
? []
: [
shoot.image,
...(shoot.detailImage ? [shoot.detailImage] : []),
];
return fc.record({
id: fc.constant(shootId),
sources: fc.constant(given),
page: fc.oneof(
{ arbitrary: shootPageContent(shootId, reuse), weight: 4 },
shootPageContent(undefined, reuse),
),
});
});
});
// A case for which the view exists
const resolvedCase = viewCase.filter(
({ id, page, sources: given }) =>
page.id === id && given.shootTypes.some((shoot) => shoot.id === id),
);
const build = (c: {
id: Parameters<typeof shootPageView>[0];
page: Parameters<typeof shootPageView>[1];
sources: ShootPageSources;
}) => shootPageView(c.id, c.page, c.sources) as ShootPageView;
const plain = (text: RichText) =>
text.map((piece) => (typeof piece === 'string' ? piece : piece.text));
// Every text in which placeholders are filled in
const filledTexts = (view: ShootPageView) => [
...view.stories.flatMap((story) => [
story.eyebrow,
story.title,
...story.paragraphs.flatMap(plain),
]),
...view.process.steps.map((step) => step.text),
...(view.faq?.items ?? []).flatMap((item) => [
item.question,
...plain(item.answer),
]),
view.offer.depositNote,
];
// The photos the story blocks and the package block show
const usedElsewhere = (view: ShootPageView): ContentImage[] => [
...view.stories.flatMap((story) =>
story.image === undefined ? [] : [story.image],
),
view.offer.image,
];
describe('shootPageView with the real content', () => {
it('builds the newborn page with its package, filled texts and mosaic', () => {
const view = shootPageView('newborn', newbornPage, sources)!;
expect(view.path).toBe('/soorten-fotoshoots/newborn');
expect(view.breadcrumb).toEqual({
label: 'Kruimelpad',
items: [
{ label: 'Home', to: '/' },
{ label: 'Soorten fotoshoots', to: '/soorten-fotoshoots' },
{ label: 'Newborn', to: '/soorten-fotoshoots/newborn' },
],
});
expect(view.offer.pkg?.price).toBe(185);
expect(view.offer.bookLink).toEqual({
to: '/contact',
search: { pakket: 'newborn' },
});
expect(view.closing.link).toEqual(view.offer.bookLink);
expect(view.offer.askLink).toEqual({ to: '/contact' });
expect(view.offer.depositNote).toBe(
`Aanbetaling €${NBSP}50, restbedrag na de shoot.`,
);
expect(view.offer.image).toBe(shootTypes[0].detailImage);
expect(view.process.steps.map((step) => step.id)).toEqual(
PROCESS_STEP_ORDER,
);
expect(view.process.steps[0].text).toBe(
'Stuur een berichtje. Ik reageer binnen 1-2 werkdagen.',
);
expect(view.process.steps[2].text).toBe(
`Met een aanbetaling van €${NBSP}50 staat je datum vast.`,
);
expect(view.process.steps[3].text).toBe(newbornPage.process.duration);
// The sleeping baby is in a story block already (D14)
expect(view.photos?.images).toEqual(
newbornPage.photos.images.filter(
(image) => image.src !== sleepingBaby,
),
);
expect(view.photos?.images).toHaveLength(3);
expect(view.photos?.portfolioLink).toEqual({
to: '/portfolio',
search: { shoot: 'newborn' },
});
expect(view.faq?.items.length).toBe(newbornPage.faq.items.length);
});
it('builds the loveshoot page without package and without mosaic', () => {
const view = shootPageView('loveshoot', loveshootPage, sources)!;
expect(view.offer.pkg).toBeUndefined();
expect(view).not.toHaveProperty('offer.pkg');
expect(view.offer.bookLink).toEqual({ to: '/contact' });
expect(view.closing.link).toEqual({ to: '/contact' });
expect(view.offer.onRequest.price).toBe('Prijs op aanvraag');
expect(view.photos).toBeUndefined();
expect(view.breadcrumb.items.at(-1)).toEqual({
label: 'Loveshoot',
to: '/soorten-fotoshoots/loveshoot',
});
});
it('gives undefined for a missing shoot type or content of another shoot', () => {
expect(
shootPageView('newborn', newbornPage, {
...sources,
shootTypes: shootTypes.filter(
(shoot) => shoot.id !== 'newborn',
),
}),
).toBeUndefined();
expect(
shootPageView('loveshoot', newbornPage, sources),
).toBeUndefined();
});
it('leaves out the FAQ without questions and the portfolio link when the portfolio does not show the shoot', () => {
const view = shootPageView(
'newborn',
{ ...newbornPage, faq: { ...newbornPage.faq, items: [] } },
{ ...sources, portfolioShoots: [] },
)!;
expect(view.faq).toBeUndefined();
expect(view.photos).toBeDefined();
expect(view.photos).not.toHaveProperty('portfolioLink');
});
});
describe('shootPageView', () => {
it('is undefined exactly when the shoot type is missing or the content is of another shoot (invariant)', () => {
fc.assert(
fc.property(viewCase, ({ id, page, sources: given }) => {
const view = shootPageView(id, page, given);
const exists =
page.id === id &&
given.shootTypes.some((shoot) => shoot.id === id);
expect(view !== undefined).toBe(exists);
if (view !== undefined) {
expect(view.id).toBe(id);
expect(view.shoot.id).toBe(id);
expect(view.path).toBe(shootPagePath(id));
}
}),
);
});
it('always has the six steps in their fixed order, whatever the content order (invariant)', () => {
fc.assert(
fc.property(resolvedCase, (c) => {
const view = build(c);
expect(view.process.steps.map((step) => step.id)).toEqual(
PROCESS_STEP_ORDER,
);
view.process.steps.forEach((step) => {
expect(step.title).toBe(
c.sources.shared.process.steps[step.id].title,
);
});
}),
);
});
it('leaves no known placeholder in any text (invariant)', () => {
fc.assert(
fc.property(resolvedCase, (c) => {
for (const text of filledTexts(build(c))) {
for (const name of knownPlaceholders) {
expect(text).not.toContain(`{${name}}`);
}
}
}),
);
});
it('shows each remaining page photo once, in order, never one used elsewhere, or no photos below the minimum (invariant)', () => {
fc.assert(
fc.property(resolvedCase, (c) => {
const view = build(c);
const used = new Set(usedElsewhere(view).map((i) => i.src));
const remaining = new Set(
c.page.photos.images
.map((image) => image.src)
.filter((src) => !used.has(src)),
);
if (remaining.size < MOSAIC_MIN_PHOTOS) {
expect(view.photos).toBeUndefined();
return;
}
const images = view.photos!.images;
const srcs = images.map((image) => image.src);
expect(new Set(srcs).size).toBe(srcs.length);
expect(new Set(srcs)).toEqual(remaining);
expect(srcs.some((src) => used.has(src))).toBe(false);
// An ordered subset: each photo is a page photo, found
// after the one before it
let from = 0;
for (const image of images) {
const at = c.page.photos.images.indexOf(image, from);
expect(at).toBeGreaterThanOrEqual(from);
from = at + 1;
}
}),
);
});
it('shows the package exactly when shootPackage finds one (invariant)', () => {
fc.assert(
fc.property(resolvedCase, (c) => {
const view = build(c);
expect(view.offer.pkg).toBe(
shootPackage(view.shoot, c.sources.packages),
);
}),
);
});
it('only ever preselects a shown package (invariant)', () => {
fc.assert(
fc.property(resolvedCase, (c) => {
const view = build(c);
const shown = visiblePackages(c.sources.packages).map(
(pkg) => pkg.id,
);
for (const link of [view.offer.bookLink, view.closing.link]) {
expect(link.to).toBe('/contact');
if (link.search !== undefined) {
expect(shown).toContain(link.search.pakket);
expect(link.search.pakket).toBe(view.offer.pkg?.id);
}
}
}),
);
});
it('ends the breadcrumb with this page, after Home and the overview (invariant)', () => {
fc.assert(
fc.property(resolvedCase, (c) => {
const view = build(c);
expect(view.breadcrumb.items.map((item) => item.to)).toEqual([
'/',
'/soorten-fotoshoots',
view.path,
]);
expect(view.breadcrumb.items.at(-1)?.label).toBe(
view.shoot.name,
);
}),
);
});
it('links the photos to the portfolio exactly when the portfolio shows the shoot (invariant)', () => {
fc.assert(
fc.property(resolvedCase, (c) => {
const view = build(c);
if (view.photos === undefined) return;
expect(view.photos.portfolioLink !== undefined).toBe(
c.sources.portfolioShoots.includes(c.id),
);
}),
);
});
it('has a FAQ exactly when there are questions, all of them in order (invariant)', () => {
fc.assert(
fc.property(resolvedCase, (c) => {
const view = build(c);
expect(view.faq !== undefined).toBe(
c.page.faq.items.length > 0,
);
expect((view.faq?.items ?? []).map((item) => item.id)).toEqual(
c.page.faq.items.map((item) => item.id),
);
}),
);
});
});
+232
View File
@@ -0,0 +1,232 @@
import type {
ContentImage,
FaqItem,
PricingPackage,
ProcessStepId,
RichText,
ShootPageContent,
ShootPageShared,
ShootType,
ShootTypeId,
SiteContent,
StoryBlock,
} from '../content/types.ts';
import type { RoutePath } from '../navigation.ts';
import { fillPlaceholders, fillRichText } from './fillPlaceholders.ts';
import { formatPrice } from './formatPrice.ts';
import { shootContactLink, shootPortfolioLink } from './shootLinks.ts';
import { shootPackage } from './shootPackage.ts';
import {
SHOOT_TYPES_PATH,
shootPagePath,
type ShootPagePath,
} from './shootPages.ts';
// The six steps of the process timeline, always in this order (FR-ST-04)
export const PROCESS_STEP_ORDER: readonly ProcessStepId[] = [
'aanvragen',
'datum',
'aanbetaling',
'shoot',
'bewerking',
'oplevering',
];
// The fewest photos the photo section needs; with fewer left it is not
// shown (D15). Proposed 2, confirmed in Functional Design of unit 2.
export const MOSAIC_MIN_PHOTOS = 2;
export interface BreadcrumbItem {
label: string;
to: RoutePath;
}
export interface ProcessStep {
id: ProcessStepId;
title: string;
text: string;
}
// Everything a shoot page is built from besides its own content
export interface ShootPageSources {
shootTypes: readonly ShootType[];
packages: readonly PricingPackage[];
shared: ShootPageShared;
site: SiteContent;
// The shoot types that link to the portfolio (live and with photos)
portfolioShoots: readonly ShootTypeId[];
}
// A shoot page with everything decided: placeholders filled, steps in
// order, photos chosen, package and links resolved. The sections and the
// structured data are both built from it, so they cannot disagree (D9).
export interface ShootPageView {
id: ShootTypeId;
path: ShootPagePath;
shoot: ShootType;
// The last item is this page
breadcrumb: { label: string; items: BreadcrumbItem[] };
intro: ShootPageContent['intro'];
stories: StoryBlock[];
// Always six, in PROCESS_STEP_ORDER
process: {
eyebrow: string;
title: string;
lead: string;
steps: ProcessStep[];
};
// Left out below MOSAIC_MIN_PHOTOS; no photo that is used elsewhere on
// the page
photos?: {
eyebrow: string;
title: string;
images: ContentImage[];
portfolioLink?: ReturnType<typeof shootPortfolioLink>;
};
// Left out when there are no questions
faq?: { eyebrow: string; title: string; lead: RichText; items: FaqItem[] };
offer: {
eyebrow: string;
title: string;
// The shoot's detail photo, else its main photo
image: ContentImage;
// Present exactly when the shoot's package is shown
pkg?: PricingPackage;
onRequest: ShootPageShared['offer']['onRequest'];
bookLabel: string;
askLabel: string;
bookLink: ReturnType<typeof shootContactLink>;
askLink: { to: '/contact' };
depositNote: string;
};
closing: {
title: string;
lead: RichText;
buttonLabel: string;
link: ReturnType<typeof shootContactLink>;
};
}
// The page photos left for the photo section: without the photos the story
// blocks and the package block already show, each photo once, in their own
// order (D14)
function remainingPhotos(
photos: readonly ContentImage[],
usedElsewhere: readonly ContentImage[],
): ContentImage[] {
const taken = new Set(usedElsewhere.map((image) => image.src));
return photos.filter((image) => {
if (taken.has(image.src)) return false;
taken.add(image.src);
return true;
});
}
// The view of one shoot page, or undefined when the shoot type is missing
// or the content belongs to another shoot; the route then shows the
// not-found page (SECURITY-15)
export function shootPageView(
id: ShootTypeId,
page: ShootPageContent,
sources: ShootPageSources,
): ShootPageView | undefined {
const shoot = sources.shootTypes.find((item) => item.id === id);
if (shoot === undefined || page.id !== id) return undefined;
const { shared, site, packages } = sources;
const path = shootPagePath(id);
// Every figure that is data comes from its own source (D8, NFR-ST-04)
const values = {
reactietermijn: site.contactForm.replyTime,
aanbetaling: formatPrice(shared.deposit.amount),
locatie: page.process.location,
duur: page.process.duration,
opleverduur: page.process.deliveryTime,
};
const fill = (text: string) => fillPlaceholders(text, values);
const stories = page.stories.map((story) => ({
...story,
eyebrow: fill(story.eyebrow),
title: fill(story.title),
paragraphs: story.paragraphs.map((text) => fillRichText(text, values)),
}));
const faqItems = page.faq.items.map((item) => ({
...item,
question: fill(item.question),
answer: fillRichText(item.answer, values),
}));
const offerImage = shoot.detailImage ?? shoot.image;
const photos = remainingPhotos(page.photos.images, [
...stories.flatMap((story) =>
story.image === undefined ? [] : [story.image],
),
offerImage,
]);
const pkg = shootPackage(shoot, packages);
const contactLink = shootContactLink(shoot, packages);
return {
id,
path,
shoot,
breadcrumb: {
label: shared.breadcrumb.label,
items: [
{ label: shared.breadcrumb.home, to: '/' },
{ label: shared.breadcrumb.overview, to: SHOOT_TYPES_PATH },
{ label: shoot.name, to: path },
],
},
intro: page.intro,
stories,
process: {
eyebrow: shared.process.eyebrow,
title: shared.process.title,
lead: shared.process.lead,
steps: PROCESS_STEP_ORDER.map((stepId) => ({
id: stepId,
title: shared.process.steps[stepId].title,
text: fill(shared.process.steps[stepId].text),
})),
},
...(photos.length >= MOSAIC_MIN_PHOTOS
? {
photos: {
eyebrow: shared.photos.eyebrow,
title: page.photos.title,
images: photos,
...(sources.portfolioShoots.includes(id)
? { portfolioLink: shootPortfolioLink(shoot) }
: {}),
},
}
: {}),
...(faqItems.length > 0
? {
faq: {
eyebrow: shared.faq.eyebrow,
title: page.faq.title,
lead: shared.faq.lead,
items: faqItems,
},
}
: {}),
offer: {
eyebrow: page.offer.eyebrow,
title: page.offer.title,
image: offerImage,
...(pkg !== undefined ? { pkg } : {}),
onRequest: shared.offer.onRequest,
bookLabel: shared.offer.bookLabel,
askLabel: shared.offer.askLabel,
bookLink: contactLink,
askLink: { to: '/contact' },
depositNote: fill(shared.deposit.note),
},
closing: { ...page.closing, link: contactLink },
};
}
+131
View File
@@ -0,0 +1,131 @@
import fc from 'fast-check';
import { describe, expect, it } from 'vitest';
import { shootTypeId, slugInput } from '../test/arbitraries';
import {
SHOOT_TYPE_IDS,
SHOOT_TYPES_PATH,
shootIdFromPath,
shootIdFromSlug,
shootPagePath,
} from './shootPages';
// Paths as they could reach the app: a slug below the overview, with or
// without slashes after it, the overview itself, or anything else
const pathInput = fc.oneof(
fc
.tuple(
slugInput.filter((slug) => typeof slug === 'string'),
fc.constantFrom('', '/', '//'),
)
.map(([slug, end]) => `${SHOOT_TYPES_PATH}/${slug as string}${end}`),
fc.constantFrom(SHOOT_TYPES_PATH, `${SHOOT_TYPES_PATH}/`, '/', ''),
fc.string(),
);
describe('shootPagePath and SHOOT_TYPE_IDS', () => {
it('lists the five shoot types, each with a page below the overview', () => {
expect(SHOOT_TYPE_IDS).toEqual([
'newborn',
'zwangerschap',
'gezin',
'loveshoot',
'portret',
]);
expect(SHOOT_TYPE_IDS.map(shootPagePath)).toEqual([
'/soorten-fotoshoots/newborn',
'/soorten-fotoshoots/zwangerschap',
'/soorten-fotoshoots/gezin',
'/soorten-fotoshoots/loveshoot',
'/soorten-fotoshoots/portret',
]);
});
});
describe('shootIdFromSlug', () => {
it('knows every shoot type by its exact id', () => {
for (const id of SHOOT_TYPE_IDS) {
expect(shootIdFromSlug(id)).toBe(id);
}
});
it('ignores other cases, padding, slashes and non-text values', () => {
expect(shootIdFromSlug('Newborn')).toBeUndefined();
expect(shootIdFromSlug(' newborn')).toBeUndefined();
expect(shootIdFromSlug('newborn/')).toBeUndefined();
expect(shootIdFromSlug('onzin')).toBeUndefined();
expect(shootIdFromSlug('constructor')).toBeUndefined();
expect(shootIdFromSlug(['newborn'])).toBeUndefined();
expect(shootIdFromSlug(undefined)).toBeUndefined();
});
it('gives back the id it was given (round trip)', () => {
fc.assert(
fc.property(shootTypeId, (id) => {
expect(shootIdFromSlug(id)).toBe(id);
}),
);
});
it('gives a known id for exactly that slug, or undefined, and never throws (invariant)', () => {
fc.assert(
fc.property(slugInput, (slug) => {
const result = shootIdFromSlug(slug);
if (result !== undefined) {
expect(SHOOT_TYPE_IDS).toContain(result);
expect(result).toBe(slug);
}
}),
);
});
});
describe('shootIdFromPath', () => {
it('finds the shoot type of its page, with one trailing slash tolerated', () => {
expect(shootIdFromPath('/soorten-fotoshoots/newborn')).toBe('newborn');
expect(shootIdFromPath('/soorten-fotoshoots/portret')).toBe('portret');
expect(shootIdFromPath('/soorten-fotoshoots/newborn/')).toBe('newborn');
});
it('gives undefined for any other path', () => {
expect(shootIdFromPath('/soorten-fotoshoots/onzin')).toBeUndefined();
expect(shootIdFromPath('/soorten-fotoshoots')).toBeUndefined();
expect(shootIdFromPath('/soorten-fotoshoots/')).toBeUndefined();
expect(shootIdFromPath('/soorten-fotoshoots/Newborn')).toBeUndefined();
expect(
shootIdFromPath('/soorten-fotoshoots/newborn/extra'),
).toBeUndefined();
expect(
shootIdFromPath('/soorten-fotoshoots/newborn//'),
).toBeUndefined();
expect(
shootIdFromPath('/soorten-fotoshoots%2Fnewborn'),
).toBeUndefined();
expect(
shootIdFromPath('/soorten-fotoshoots/newborn%2Fextra'),
).toBeUndefined();
expect(shootIdFromPath('/newborn')).toBeUndefined();
expect(shootIdFromPath('')).toBeUndefined();
});
it('gives back the id of every shoot page path (round trip)', () => {
fc.assert(
fc.property(shootTypeId, (id) => {
expect(shootIdFromPath(shootPagePath(id))).toBe(id);
}),
);
});
it('gives a known id only for its exact page path, or undefined, and never throws (invariant)', () => {
fc.assert(
fc.property(pathInput, (path) => {
const result = shootIdFromPath(path);
if (result !== undefined) {
expect(SHOOT_TYPE_IDS).toContain(result);
expect(shootPagePath(result)).toBe(
path.endsWith('/') ? path.slice(0, -1) : path,
);
}
}),
);
});
});
+51
View File
@@ -0,0 +1,51 @@
import type { ShootTypeId } from '../content/types.ts';
import type { RoutePath } from '../navigation.ts';
import { isShootTypeId } from './portfolioFilters.ts';
// The overview of all shoot types; each shoot page is one level below it
export const SHOOT_TYPES_PATH = '/soorten-fotoshoots';
// Every shoot type id once. As a record, a new id in ShootTypeId is a type
// error until it is listed here.
const everyShootTypeId: Record<ShootTypeId, true> = {
newborn: true,
zwangerschap: true,
gezin: true,
loveshoot: true,
portret: true,
};
export const SHOOT_TYPE_IDS: readonly ShootTypeId[] = Object.keys(
everyShootTypeId,
) as ShootTypeId[];
export type ShootPagePath = `${typeof SHOOT_TYPES_PATH}/${ShootTypeId}`;
// The page of one shoot type, e.g. '/soorten-fotoshoots/newborn' (FR-ST-01)
export function shootPagePath(id: ShootTypeId): ShootPagePath {
return `${SHOOT_TYPES_PATH}/${id}`;
}
// The inverse: a known id for exactly a known slug (letter case, spaces and
// slashes count), anything else gives undefined; never throws (SECURITY-05)
export function shootIdFromSlug(slug: unknown): ShootTypeId | undefined {
return isShootTypeId(slug, SHOOT_TYPE_IDS) ? slug : undefined;
}
// The shoot type of a shoot page path: exactly '/soorten-fotoshoots/<id>',
// with one trailing slash tolerated; any other path gives undefined
export function shootIdFromPath(pathname: string): ShootTypeId | undefined {
const prefix = `${SHOOT_TYPES_PATH}/`;
if (!pathname.startsWith(prefix)) return undefined;
const rest = pathname.slice(prefix.length);
return shootIdFromSlug(rest.endsWith('/') ? rest.slice(0, -1) : rest);
}
type Assert<T extends true> = T;
// Compile-time guard: every shoot page path is a route. A new shoot type
// without a route file is a type error here. Exported only because
// noUnusedLocals rejects an unused local type.
export type EveryShootHasARoute = Assert<
ShootPagePath extends RoutePath ? true : false
>;