Files
AndreaSlopFotografie/web/src/lib/visiblePackages.ts
T
SluijsensandClaude Opus 5.5 30dab1af42 Adds the Prijzen section to the homepage
Shows the three live packages as cards with their price and what is
included. Each card links to the contact section with ?pakket=<id>, so
the contact form can preselect it. Invalid packages from the CMS are
skipped and the pakket value is only accepted when it names a package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:07:36 +02:00

30 lines
963 B
TypeScript

import type { PricingPackage } from '../content/types.ts';
const SLUG = /^[a-z0-9-]+$/;
// Whether a package meets the invariants in domain-entities.md
export function isValidPackage(pkg: PricingPackage): boolean {
return (
SLUG.test(pkg.id) &&
pkg.name.trim() !== '' &&
Number.isInteger(pkg.price) &&
pkg.price > 0 &&
pkg.features.length > 0 &&
pkg.features.every((feature) => feature.trim() !== '')
);
}
// The packages that can be shown: invalid ones from the CMS are skipped
// rather than breaking the page, and of two packages with the same id the
// first wins. The order stays the same (BR-PRICE-02).
export function visiblePackages(
packages: readonly PricingPackage[],
): PricingPackage[] {
const seen = new Set<string>();
return packages.filter((pkg) => {
if (!isValidPackage(pkg) || seen.has(pkg.id)) return false;
seen.add(pkg.id);
return true;
});
}