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>
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
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
|
|
>;
|