Adds the portfolio page
The ten live photos in a filterable masonry grid with an accessible lightbox, filters per shoot type kept in the URL (?shoot=), the shared Instagram block, and an indexed page with image gallery structured data and its own preview image. Soorten fotoshoots now only links to the portfolio for shoot types that have photos there. The filter bar stays on one row, so the web font loading no longer shifts the photos below it, and no photo loads before the page has: the grid fades in, so loading its photos early only delayed the fonts and the intro text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import portfolioContent from '../content/portfolioContent';
|
||||
import shootTypes from '../content/shootTypes';
|
||||
import type { ShootTypeId } from '../content/types';
|
||||
import {
|
||||
portfolioPhotos,
|
||||
shootTypeId,
|
||||
uniqueShootTypes,
|
||||
} from '../test/arbitraries';
|
||||
import {
|
||||
ALL_FILTER,
|
||||
filterOptions,
|
||||
filterPhotos,
|
||||
isShootTypeId,
|
||||
photoCountLabel,
|
||||
shootFromSearch,
|
||||
shootTypesWithPhotos,
|
||||
toGalleryItems,
|
||||
} from './portfolioFilters';
|
||||
|
||||
const photos = portfolioContent.photos;
|
||||
const allIds = shootTypes.map((type) => type.id);
|
||||
|
||||
describe('isShootTypeId', () => {
|
||||
it('accepts known ids only, exactly as written', () => {
|
||||
expect(isShootTypeId('gezin', allIds)).toBe(true);
|
||||
expect(isShootTypeId('Gezin', allIds)).toBe(false);
|
||||
expect(isShootTypeId('onzin', allIds)).toBe(false);
|
||||
expect(isShootTypeId(3, allIds)).toBe(false);
|
||||
expect(isShootTypeId(['gezin'], allIds)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shootTypesWithPhotos', () => {
|
||||
it('lists newborn, zwangerschap and gezin for the live photos', () => {
|
||||
expect(
|
||||
shootTypesWithPhotos(shootTypes, photos).map((t) => t.id),
|
||||
).toEqual(['newborn', 'zwangerschap', 'gezin']);
|
||||
});
|
||||
|
||||
it('keeps exactly the types with a photo, in list order (oracle)', () => {
|
||||
fc.assert(
|
||||
fc.property(uniqueShootTypes, portfolioPhotos, (types, list) => {
|
||||
const result = shootTypesWithPhotos(types, list);
|
||||
const expected = types.filter((type) =>
|
||||
list.map((p) => p.shootType).includes(type.id),
|
||||
);
|
||||
expect(result).toEqual(expected);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('does not change when the photos are narrowed to those types (idempotence)', () => {
|
||||
fc.assert(
|
||||
fc.property(uniqueShootTypes, portfolioPhotos, (types, list) => {
|
||||
const once = shootTypesWithPhotos(types, list);
|
||||
const ids = once.map((type) => type.id);
|
||||
const narrowed = list.filter((p) => ids.includes(p.shootType));
|
||||
expect(shootTypesWithPhotos(once, narrowed)).toEqual(once);
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shootFromSearch', () => {
|
||||
const available: ShootTypeId[] = ['newborn', 'zwangerschap', 'gezin'];
|
||||
|
||||
it('accepts an available id in any letter case', () => {
|
||||
expect(shootFromSearch('gezin', available)).toBe('gezin');
|
||||
expect(shootFromSearch(' Newborn ', available)).toBe('newborn');
|
||||
});
|
||||
|
||||
it('ignores unknown ids, types without photos and non-strings', () => {
|
||||
expect(shootFromSearch('loveshoot', available)).toBeUndefined();
|
||||
expect(shootFromSearch('<script>', available)).toBeUndefined();
|
||||
expect(shootFromSearch(undefined, available)).toBeUndefined();
|
||||
expect(shootFromSearch(['gezin'], available)).toBeUndefined();
|
||||
expect(shootFromSearch('', available)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns every available id for its own value (round-trip)', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.uniqueArray(shootTypeId, { minLength: 1 }),
|
||||
fc.constantFrom('', ' ', ' '),
|
||||
fc.boolean(),
|
||||
(ids, pad, upper) => {
|
||||
for (const id of ids) {
|
||||
const typed = upper ? id.toUpperCase() : id;
|
||||
expect(shootFromSearch(pad + typed + pad, ids)).toBe(
|
||||
id,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it('only ever returns an available id (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.anything(),
|
||||
fc.uniqueArray(shootTypeId),
|
||||
(value, ids) => {
|
||||
const result = shootFromSearch(value, ids);
|
||||
expect(result === undefined || ids.includes(result)).toBe(
|
||||
true,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterPhotos', () => {
|
||||
it('shows all photos without a shoot, or one type in its own order', () => {
|
||||
expect(filterPhotos(photos, undefined)).toEqual(photos);
|
||||
expect(filterPhotos(photos, 'gezin').map((p) => p.id)).toEqual([
|
||||
'f41a1579',
|
||||
'f41a7138',
|
||||
]);
|
||||
expect(filterPhotos(photos, 'loveshoot')).toEqual([]);
|
||||
});
|
||||
|
||||
it('keeps only that type, in the original order (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(portfolioPhotos, shootTypeId, (list, shoot) => {
|
||||
const result = filterPhotos(list, shoot);
|
||||
expect(result.every((p) => p.shootType === shoot)).toBe(true);
|
||||
const positions = result.map((p) => list.indexOf(p));
|
||||
expect(positions).toEqual([...positions].sort((a, b) => a - b));
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('changes nothing when filtered twice (idempotence)', () => {
|
||||
fc.assert(
|
||||
fc.property(portfolioPhotos, shootTypeId, (list, shoot) => {
|
||||
const once = filterPhotos(list, shoot);
|
||||
expect(filterPhotos(once, shoot)).toEqual(once);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('splits all photos over the types without losing any (oracle)', () => {
|
||||
fc.assert(
|
||||
fc.property(portfolioPhotos, (list) => {
|
||||
const total = allIds.reduce(
|
||||
(sum, id) => sum + filterPhotos(list, id).length,
|
||||
0,
|
||||
);
|
||||
expect(total).toBe(list.length);
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterOptions', () => {
|
||||
it('starts with Alles and labels each type with its short name', () => {
|
||||
const types = shootTypesWithPhotos(shootTypes, photos);
|
||||
expect(filterOptions(types, 'Alles')).toEqual([
|
||||
{ id: ALL_FILTER, label: 'Alles' },
|
||||
{ id: 'newborn', label: 'Newborn' },
|
||||
{ id: 'zwangerschap', label: 'Zwangerschap' },
|
||||
{ id: 'gezin', label: 'Gezin' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('has one option per type after Alles (invariant)', () => {
|
||||
fc.assert(
|
||||
fc.property(uniqueShootTypes, (types) => {
|
||||
const options = filterOptions(types, 'Alles');
|
||||
expect(options).toHaveLength(types.length + 1);
|
||||
expect(options[0].id).toBe(ALL_FILTER);
|
||||
expect(options.slice(1).map((o) => o.label)).toEqual(
|
||||
types.map((t) => t.name),
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toGalleryItems', () => {
|
||||
it('captions each photo with the full name of its shoot type', () => {
|
||||
const items = toGalleryItems(photos, shootTypes);
|
||||
expect(items[0].caption).toBe('Newbornshoot');
|
||||
expect(items[2].caption).toBe('Zwangerschapsshoot');
|
||||
expect(items[6].caption).toBe('Gezinsshoot');
|
||||
expect(items[0].thumb).toBe(photos[0].thumb);
|
||||
});
|
||||
|
||||
it('keeps order, ids and images, and takes the caption from the type (oracle)', () => {
|
||||
fc.assert(
|
||||
fc.property(portfolioPhotos, uniqueShootTypes, (list, types) => {
|
||||
const items = toGalleryItems(list, types);
|
||||
expect(items.map((i) => i.id)).toEqual(list.map((p) => p.id));
|
||||
items.forEach((item, i) => {
|
||||
expect(item.full).toBe(list[i].full);
|
||||
expect(item.caption).toBe(
|
||||
types.find((t) => t.id === list[i].shootType)
|
||||
?.shootLabel,
|
||||
);
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('photoCountLabel', () => {
|
||||
it('uses the singular only for one photo', () => {
|
||||
expect(photoCountLabel(1)).toBe('1 foto');
|
||||
expect(photoCountLabel(0)).toBe("0 foto's");
|
||||
expect(photoCountLabel(6)).toBe("6 foto's");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
import type {
|
||||
FilterOption,
|
||||
GalleryItem,
|
||||
PortfolioPhoto,
|
||||
ShootType,
|
||||
ShootTypeId,
|
||||
} from '../content/types.ts';
|
||||
|
||||
// The filter that shows every photo; it has no ?shoot= value
|
||||
export const ALL_FILTER = 'alles';
|
||||
|
||||
// Whether a value is one of the given shoot type ids (exactly as written)
|
||||
export function isShootTypeId(
|
||||
value: unknown,
|
||||
known: readonly ShootTypeId[],
|
||||
): value is ShootTypeId {
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
(known as readonly string[]).includes(value)
|
||||
);
|
||||
}
|
||||
|
||||
// The shoot types that have at least one photo, in the order of the list
|
||||
// (BR-FL-01). Only these get a filter, and a link from Soorten fotoshoots.
|
||||
export function shootTypesWithPhotos(
|
||||
shootTypes: readonly ShootType[],
|
||||
photos: readonly PortfolioPhoto[],
|
||||
): ShootType[] {
|
||||
return shootTypes.filter((type) =>
|
||||
photos.some((photo) => photo.shootType === type.id),
|
||||
);
|
||||
}
|
||||
|
||||
// The shoot type from ?shoot=, if it is one of `available` (BR-SP-02).
|
||||
// Letter case and surrounding spaces do not matter; anything else
|
||||
// (unknown id, a type without photos, number, missing) gives undefined, so
|
||||
// the page shows "Alles" and the URL's value is never shown.
|
||||
export function shootFromSearch(
|
||||
value: unknown,
|
||||
available: readonly ShootTypeId[],
|
||||
): ShootTypeId | undefined {
|
||||
if (typeof value !== 'string') return undefined;
|
||||
const wanted = value.trim().toLowerCase();
|
||||
return available.find((id) => id === wanted);
|
||||
}
|
||||
|
||||
// The photos of one shoot type in their own order, or all of them
|
||||
export function filterPhotos(
|
||||
photos: readonly PortfolioPhoto[],
|
||||
shoot: ShootTypeId | undefined,
|
||||
): PortfolioPhoto[] {
|
||||
return shoot === undefined
|
||||
? [...photos]
|
||||
: photos.filter((photo) => photo.shootType === shoot);
|
||||
}
|
||||
|
||||
// "Alles" first, then one choice per shoot type, labelled with its short name
|
||||
export function filterOptions(
|
||||
shootTypes: readonly ShootType[],
|
||||
allLabel: string,
|
||||
): FilterOption[] {
|
||||
return [
|
||||
{ id: ALL_FILTER, label: allLabel },
|
||||
...shootTypes.map((type) => ({ id: type.id, label: type.name })),
|
||||
];
|
||||
}
|
||||
|
||||
// Portfolio photos as items for the shared gallery blocks; the caption is
|
||||
// the full name of the shoot type ("Newbornshoot", BR-CP-01)
|
||||
export function toGalleryItems(
|
||||
photos: readonly PortfolioPhoto[],
|
||||
shootTypes: readonly ShootType[],
|
||||
): GalleryItem[] {
|
||||
return photos.map((photo) => ({
|
||||
id: photo.id,
|
||||
thumb: photo.thumb,
|
||||
full: photo.full,
|
||||
caption: shootTypes.find((type) => type.id === photo.shootType)
|
||||
?.shootLabel,
|
||||
}));
|
||||
}
|
||||
|
||||
// "1 foto" or "6 foto's", for the announcement after a filter change
|
||||
export function photoCountLabel(count: number): string {
|
||||
return count === 1 ? '1 foto' : `${count} foto's`;
|
||||
}
|
||||
Reference in New Issue
Block a user