Website 1.6.0: real photos for the demo church, photos sized to their frames

The demo church (and the eight demo profiles) used one generated "hills and
sun" SVG for every picture. Now 104 Unsplash stock photos (models; free under
the Unsplash License, credited in backend/demo-photos/CREDITS.md): a set per
profile, a portrait for every leader (before: only the pastor), a picture for
each event, and a photo for each message instead of the stand-in video's
thumbnail. Demo photos go through processImage like an upload, made once per
machine and copied; without demo-photos/ the illustration still stands in.

A message's thumbnailUrl that is one of the site's own uploads now comes
before the YouTube thumbnail; admins and the YouTube feed store YouTube's
address there, so a church's own messages are unchanged.

Faster on phones: the Community collage hero, the collage row, the team's
portraits and the ministry cards give the browser their real width (sizes),
so a phone no longer fetches the full-width photo for a small frame.

Checked: backend tests (131), Website e2e (130, baselines retaken;
Lighthouse mobile 90-98 performance, 100 accessibility and SEO), typecheck,
lint and both builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 14:31:57 +02:00
co-authored by Claude Opus 5.5
parent 28085d92ba
commit 2d4d9ea871
120 changed files with 1401 additions and 60 deletions
+95 -33
View File
@@ -1,7 +1,7 @@
/**
* The demo church (WEBSITE-1.0-PLAN §11, "Demo church"): a fictional church, fictional people and
* illustrated images (no photos of anyone), loaded into a template for development, the Hub's demo
* sites and the crosscode-site screenshots. `npm run demo -- --template bold`.
* stock photos (models, not anyone from a church), loaded into a template for development, the
* Hub's demo sites and the crosscode-site screenshots. `npm run demo -- --template bold`.
*
* 1.3.0: also the eight demo profiles (seeds.ts, `npm run demo -- --profile bold-plant`), which
* keep the church's own profile (Accounts' organisation settings), the site settings, the site
@@ -12,6 +12,7 @@
* been published unless told otherwise.
*/
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { CHURCH_SCHEMA, WEBSITE_TEMPLATES, type agent, type Church, type WebsiteTemplate } from '@crosscode/contracts';
@@ -20,7 +21,8 @@ import { churchProfile } from '../church/profile.js';
import type { SectionData } from '../site/sections.js';
import { publish } from '../site/snapshot.js';
import { TEMPLATE_HEADERS, TEMPLATE_VARIANTS, SECTION_TYPES, defaultDesign, type SiteDesign } from '../site/variants.js';
import { DEMO_SEEDS, type DemoSeed } from './seeds.js';
import { MAX_WIDTH, WIDTHS, processImage, type Sizes } from '../admin/media.js';
import { DEMO_SEEDS, type DemoPhotos, type DemoSeed } from './seeds.js';
export const DEMO_COLOURS = { primary: '#1d5c63', accent: '#e0a458' };
@@ -54,7 +56,7 @@ export function demoProfile(publicUrl: string): Church {
} as Church;
}
/** An illustrated "photo": hills, a sun and a path in the church's colours (SVG, no people). */
/** Hills, a sun and a path in the church's colours (SVG): what stands in for a demo photo that is missing. */
export function illustration(seed: number, w = 1600, h = 1000, colours: { primary: string; accent: string } = DEMO_COLOURS): string {
const hues = [colours.primary, colours.accent, '#7fb7be', '#f3e3c3', '#284b52'];
const c = (i: number) => hues[(seed + i) % hues.length];
@@ -73,24 +75,87 @@ type Ids = Record<string, string>;
const HEX = /^#[0-9a-f]{6}$/i;
async function demoMedia(ctx: Ctx, uploadDir: string, alts: Record<string, string>, colours: { primary: string; accent: string }): Promise<Ids> {
const items: [string, number][] = [['hero', 0], ['collage2', 1], ['collage3', 2], ['welcome', 3], ['pastor', 4], ['invite', 5], ['kids', 6], ['youth', 7], ['care', 8], ['music', 9]];
const ids: Ids = {};
fs.mkdirSync(path.join(uploadDir, 'demo'), { recursive: true });
for (const [key, seed] of items) {
export const defaultUploadDir = () => path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'uploads');
/**
* The demo's photos (Unsplash, free to use: credits in demo-photos/photos.json and CREDITS.md).
* Stock photos of models standing in for the fictional churches' people and places.
*/
export const DEMO_PHOTO_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'demo-photos');
type DemoPhoto = { file: string; alt: string; width: number; height: number };
let photoList: Record<string, DemoPhoto> | null = null;
export function demoPhotos(): Record<string, DemoPhoto> {
if (!photoList) {
try { photoList = JSON.parse(fs.readFileSync(path.join(DEMO_PHOTO_DIR, 'photos.json'), 'utf8')) as Record<string, DemoPhoto>; } catch { photoList = {}; }
}
return photoList;
}
/**
* One demo photo as a media asset, in the responsive sizes a real upload gets. The processed files
* stay in `<uploads>/demo/` (the demo replaces rows, not files), so a later demo reuses them.
* Without the photo (a checkout without demo-photos/), the illustration stands in.
*/
async function demoAsset(ctx: Ctx, uploadDir: string, key: string, alt: string, fallbackSeed: number, colours: { primary: string; accent: string }): Promise<string> {
const photo = demoPhotos()[key];
const source = photo && path.join(DEMO_PHOTO_DIR, photo.file);
if (!source || !fs.existsSync(source)) {
const filename = `demo/${key}.svg`;
const svg = illustration(seed, 1600, 1000, colours);
const svg = illustration(fallbackSeed, 1600, 1000, colours);
fs.writeFileSync(path.join(uploadDir, filename), svg);
const row = await ctx.db.mediaAsset.create({ data: { filename, mime: 'image/svg+xml', bytes: Buffer.byteLength(svg), width: 1600, height: 1000, alt: alts[key]! } });
ids[key] = row.id;
const row = await ctx.db.mediaAsset.create({ data: { filename, mime: 'image/svg+xml', bytes: Buffer.byteLength(svg), width: 1600, height: 1000, alt } });
return row.id;
}
const width = Math.min(photo.width, MAX_WIDTH);
const height = Math.round((photo.height * width) / photo.width);
const sizes: Sizes = WIDTHS.filter((w) => w < width).map((w) => ({ w, webp: `${key}-${w}.webp`, jpg: `${key}-${w}.jpg` }));
const names = [`${key}.webp`, ...sizes.flatMap((s) => [s.webp, s.jpg])];
// Made once per machine (in the temp folder, by the photo's size, so a replaced photo is made
// again) and copied: the e2e and the tests load the demo many times.
const made = path.join(os.tmpdir(), 'crosscode-website-demo', `${key}-${fs.statSync(source).size}`);
if (!names.every((f) => fs.existsSync(path.join(made, f)))) {
// Made in a folder of its own and renamed into place, so a demo loading at the same time
// never copies a half-written file.
const making = `${made}.${process.pid}.${Math.random().toString(36).slice(2)}`;
fs.mkdirSync(making, { recursive: true });
await processImage(fs.readFileSync(source), { ext: 'webp', mime: 'image/webp' }, path.join(making, key));
try { fs.renameSync(making, made); } catch { fs.rmSync(making, { recursive: true, force: true }); }
}
for (const f of names) {
const to = path.join(uploadDir, 'demo', f);
if (!fs.existsSync(to)) fs.copyFileSync(path.join(made, f), to);
}
const bytes = names.reduce((t, f) => t + fs.statSync(path.join(uploadDir, 'demo', f)).size, 0);
const row = await ctx.db.mediaAsset.create({ data: { filename: `demo/${key}.webp`, mime: 'image/webp', bytes, width, height, alt, sizes: sizes as never } });
return row.id;
}
/** The demo's pictures by slot (hero, collage2, collage3, welcome, pastor, invite, and the four ministries). */
async function demoMedia(ctx: Ctx, uploadDir: string, photos: DemoPhotos, pastorName: string, team: string[], colours: { primary: string; accent: string }): Promise<Ids> {
const slots: [string, string, string | null][] = [
['hero', photos.hero, null], ['collage2', photos.collage[0], null], ['collage3', photos.collage[1], null],
['welcome', photos.welcome, null], ['pastor', photos.pastor, pastorName], ['invite', photos.invite, null],
...photos.ministries.map((p, i) => [`ministry${i}`, p, null] as [string, string, string | null]),
...photos.team.map((p, i) => [`team${i}`, p, team[i] ?? null] as [string, string, string | null]),
...photos.messages.map((p, i) => [`message${i}`, p, null] as [string, string, string | null]),
...photos.events.map((p, i) => [`event${i}`, p, null] as [string, string, string | null]),
];
fs.mkdirSync(path.join(uploadDir, 'demo'), { recursive: true });
const ids: Ids = {};
const byPhoto = new Map<string, string>();
let n = 0;
for (const [slot, key, alt] of slots) {
// A photo used twice (a profile may) is one asset; the pastor's always gets their name.
const id = !alt && byPhoto.get(key) || await demoAsset(ctx, uploadDir, key, alt ?? demoPhotos()[key]?.alt ?? 'Illustration', n, colours);
if (!alt) byPhoto.set(key, id);
ids[slot] = id;
n++;
}
return ids;
}
export const defaultUploadDir = () => path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'uploads');
/** The development demo church (Acacia Hill), on any template: what a template alone loads. */
const CLASSIC: Omit<DemoSeed, 'template'> & { pastorName: string; ctaText: string; descriptions: Record<string, string>; alts: Record<string, string> } = {
const CLASSIC: Omit<DemoSeed, 'template'> & { pastorName: string; ctaText: string; descriptions: Record<string, string> } = {
id: 'classic', label: 'Acacia Hill (development)', alternate: false,
hero: { headline: 'A home for everyone on the hill', subline: 'Sundays at 08:30 and 10:00 in Westridge, Pretoria. Come as you are.', button: { label: 'Plan your visit', href: '/visit' } },
serviceNote: 'Kids church runs during the 10:00 service. Parking on Acacia Avenue and behind the hall.',
@@ -137,11 +202,7 @@ const CLASSIC: Omit<DemoSeed, 'template'> & { pastorName: string; ctaText: strin
give: 'How to give to Acacia Hill Church.',
contact: 'Find Acacia Hill Church in Westridge, Pretoria.',
},
alts: {
hero: 'The hills behind Acacia Hill at sunrise (illustration)', collage2: 'A path through the veld (illustration)', collage3: 'Evening over the valley (illustration)',
welcome: 'The church garden (illustration)', pastor: 'Illustration standing in for the pastor\'s photo', invite: 'A sunny Sunday morning (illustration)',
kids: 'Illustration for Kids church', youth: 'Illustration for Youth', care: 'Illustration for Care and prayer', music: 'Illustration for Worship',
},
photos: { hero: 'acacia-sunrise', collage: ['congregation-warm', 'coffee-friends'], welcome: 'welcome-hug', pastor: 'pastor-thandi', invite: 'church-light', ministries: ['kids-craft', 'youth-group', 'band-small', 'prayer-group'], team: ['team-pieter', 'team-lerato', 'team-johan'], messages: ['open-bible', 'mic-audience', 'pulpit'], events: ['friends-picnic', 'candles', 'meal-friends'] },
};
/** A demo profile's design: the template's defaults, or (alternate) its second recommendations and header. */
@@ -194,16 +255,11 @@ export async function loadDemo(ctx: Ctx, what: WebsiteTemplate | agent.WebsiteDe
const [pastorName] = seed.leaders[0]!;
const ministryNames = seed.ministries.map(([, n]) => t(n));
const alts = extra?.alts ?? {
hero: `${t(seed.hero.headline)} (illustration)`, collage2: 'A path through the veld (illustration)', collage3: 'Evening over the valley (illustration)',
welcome: `${short} (illustration)`, pastor: `Illustration standing in for ${pastorName}'s photo`, invite: 'A sunny Sunday morning (illustration)',
kids: `Illustration for ${ministryNames[0]}`, youth: `Illustration for ${ministryNames[1]}`, music: `Illustration for ${ministryNames[2]}`, care: `Illustration for ${ministryNames[3]}`,
};
const img = await demoMedia(ctx, uploadDir, alts, colours);
const speaker = extra?.pastorName ?? pastorName;
const img = await demoMedia(ctx, uploadDir, seed.photos, speaker, seed.leaders.slice(1).map(([name]) => name), colours);
const design = classic ? defaultDesign(seed.template) : seedDesign(seed.template, seed.alternate);
await db.siteDesign.create({ data: { id: 1, template: seed.template, variants: design.variants as never, home: design.home as never, style: design.style as never } });
const speaker = extra?.pastorName ?? pastorName;
const home: SectionData = {
hero: { headline: t(seed.hero.headline), subline: t(seed.hero.subline), images: [img.hero!, img.collage2!, img.collage3!], videoId: null, button: seed.hero.button },
serviceTimes: { heading: 'Join us this Sunday', note: t(seed.serviceNote) },
@@ -223,7 +279,7 @@ export async function loadDemo(ctx: Ctx, what: WebsiteTemplate | agent.WebsiteDe
{
kind: 'visit', slug: 'visit', title: 'Plan your visit', position: 1, description: d('visit', 'What to expect on your first Sunday at {name}.'), sections: [
{ type: 'text', data: { heading: 'What to expect', body: t(seed.visit.expect) } },
{ type: 'image-text', variant: 'image-text', data: { heading: 'Bringing children', body: t(seed.visit.kids), imageId: img.kids, button: null } },
{ type: 'image-text', variant: 'image-text', data: { heading: 'Bringing children', body: t(seed.visit.kids), imageId: img.ministry0, button: null } },
{ type: 'cta', data: { heading: t(seed.visit.cta), text: extra?.ctaText ?? 'Send us a message and we will get back to you.', button: { label: 'Contact us', href: '/contact' } } },
],
},
@@ -250,21 +306,27 @@ export async function loadDemo(ctx: Ctx, what: WebsiteTemplate | agent.WebsiteDe
for (const s of p.sections) await db.section.create({ data: { pageId: page.id, type: s.type, variant: s.variant ?? null, position: i++, data: s.data as never } });
}
const pictures = [img.kids!, img.youth!, img.music!, img.care!];
let n = 0;
for (const [slug, , summary] of seed.ministries) await db.ministry.create({ data: { slug, name: ministryNames[n]!, summary: t(summary), imageId: pictures[n]!, position: n++ } });
for (const [slug, , summary] of seed.ministries) await db.ministry.create({ data: { slug, name: ministryNames[n]!, summary: t(summary), imageId: img[`ministry${n}`]!, position: n++ } });
n = 0;
for (const [leader, role] of seed.leaders) await db.leader.create({ data: { name: leader, role, photoId: n === 0 ? img.pastor! : null, position: n++ } });
for (const [leader, role] of seed.leaders) await db.leader.create({ data: { name: leader, role, photoId: n === 0 ? img.pastor! : img[`team${n - 1}`] ?? null, position: n++ } });
const now = ctx.now();
const day = 864e5;
const series = await db.messageSeries.create({ data: { slug: seed.series[0], title: seed.series[1] } });
// Each message shows a photo (its video is a stand-in), at the 960 px size a card needs.
n = 0;
for (const [slug, title, ago, passage] of seed.messages) {
await db.message.create({ data: { slug, title, date: new Date(now.getTime() - ago * day), source: 'youtube', mediaUrl: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ', speaker, passage, seriesId: series.id, publishedAt: now } });
const photo = await db.mediaAsset.findUnique({ where: { id: img[`message${n++}`]! } });
const sizes = (photo?.sizes ?? []) as Sizes;
const file = sizes.find((s) => s.w === 960)?.webp;
const thumbnailUrl = photo ? `/api/uploads/${file ? `demo/${file}` : photo.filename}` : null;
await db.message.create({ data: { slug, title, date: new Date(now.getTime() - ago * day), source: 'youtube', mediaUrl: 'https://www.youtube.com/watch?v=aqz-KE-bpKQ', thumbnailUrl, speaker, passage, seriesId: series.id, publishedAt: now } });
}
n = 0;
for (const [slug, title, inDays, description] of seed.events) {
const startsAt = new Date(Math.floor((now.getTime() + inDays * day) / day) * day + 8 * 3600e3);
await db.simpleEvent.create({ data: { slug, title, startsAt, endsAt: new Date(startsAt.getTime() + 3 * 3600e3), location: t(seed.venue), description: t(description), publishedAt: now } });
await db.simpleEvent.create({ data: { slug, title, startsAt, endsAt: new Date(startsAt.getTime() + 3 * 3600e3), location: t(seed.venue), description: t(description), imageId: img[`event${n++}`] ?? null, publishedAt: now } });
}
return publish(ctx, { id: opts.publishedBy ?? 'demo', role: 'system' }, classic ? `Demo church on ${seed.template}` : `Demo: ${seed.label}`);
}
+30 -1
View File
@@ -32,7 +32,7 @@ export type DemoSeed = {
visit: { expect: string; kids: string; cta: string };
about: { story: string; quote: string; by: string };
give: string;
/** Four: [slug, name, summary]. Their pictures are the kids, youth, music and care illustrations, in order. */
/** Four: [slug, name, summary]. Their pictures are `photos.ministries`, in order. */
ministries: [string, string, string][];
/** Four: [name, role]. The first is the pastor on the home page and the speaker of the messages. */
leaders: [string, string][];
@@ -43,6 +43,27 @@ export type DemoSeed = {
events: [string, string, number, string][];
/** Where the events are. */
venue: string;
/** The photos (keys in `demo-photos/photos.json`): the hero, the collage's other two, and the rest. */
photos: DemoPhotos;
};
/**
* Which demo photo goes where. `ministries` follow the ministries' order; the first is also the
* picture on the Plan your visit page's "Bringing children". The pastor's photo is the first leader's.
*/
export type DemoPhotos = {
hero: string;
collage: [string, string];
welcome: string;
pastor: string;
invite: string;
ministries: [string, string, string, string];
/** The other three leaders' portraits, in the leaders' order. */
team: [string, string, string];
/** The three messages' thumbnails (their video is a stand-in), newest first. */
messages: [string, string, string];
/** The three events' pictures, in the events' order. */
events: [string, string, string];
};
const visitButton: Button = { label: 'Plan your visit', href: '/visit' };
@@ -82,6 +103,7 @@ export const DEMO_SEEDS: Record<WebsiteDemoProfile, DemoSeed> = {
['christmas-eve', 'Christmas Eve midnight mass', 27, 'The first Communion of Christmas, with carols from 23:15.'],
],
venue: '{name}',
photos: { hero: 'stone-church', collage: ['church-aisle', 'organ'], welcome: 'congregation-pews', pastor: 'pastor-margaret', invite: 'church-light', ministries: ['kids-drawing', 'candles', 'choir-church', 'visit-tea'], team: ['team-sipho', 'team-anne', 'team-david'], messages: ['sermon-collar', 'pulpit', 'church-quiet'], events: ['friends-picnic', 'candles', 'church-light'] },
},
'heritage-city': {
id: 'heritage-city', template: 'heritage', label: 'Heritage: a city-centre church with weekday services', alternate: true,
@@ -117,6 +139,7 @@ export const DEMO_SEEDS: Record<WebsiteDemoProfile, DemoSeed> = {
['city-carols', 'Carols for the city', 23, 'Readings and carols for everyone who works in {city}.'],
],
venue: '{name}',
photos: { hero: 'city-spire', collage: ['candles', 'congregation-pews'], welcome: 'church-white', pastor: 'pastor-peter', invite: 'church-doors', ministries: ['students-lecture', 'coffee-group', 'organ', 'soup-bowl'], team: ['team-claire', 'team-tom', 'team-nomsa'], messages: ['sermon-robe', 'pulpit', 'open-bible'], events: ['organ', 'candles', 'choir-church'] },
},
'bold-youth': {
id: 'bold-youth', template: 'bold', label: 'Bold: a young, music-led church', alternate: false,
@@ -152,6 +175,7 @@ export const DEMO_SEEDS: Record<WebsiteDemoProfile, DemoSeed> = {
['christmas-experience', 'The Christmas experience', 26, 'Music, lights and the Christmas story for the whole family.'],
],
venue: 'The {short} auditorium',
photos: { hero: 'band-big', collage: ['worship-hands', 'youth-group'], welcome: 'congregation-modern', pastor: 'pastor-naidoo', invite: 'coffee-friends', ministries: ['kids-teacher', 'youth-outdoors', 'band-stage', 'bible-study'], team: ['team-kagiso', 'team-megan', 'team-ruan'], messages: ['sermon-stage', 'mic-blue', 'mic-red'], events: ['worship-hands', 'youth-outdoors', 'band-big'] },
},
'bold-plant': {
id: 'bold-plant', template: 'bold', label: 'Bold: a new church plant meeting in a school', alternate: true,
@@ -187,6 +211,7 @@ export const DEMO_SEEDS: Record<WebsiteDemoProfile, DemoSeed> = {
['christmas-in-the-hall', 'Christmas in the hall', 24, 'A family carol service with mince pies.'],
],
venue: 'The school hall',
photos: { hero: 'congregation-hall', collage: ['friends-picnic', 'coffee-friends'], welcome: 'welcome-greeting', pastor: 'pastor-moore', invite: 'hall-chairs', ministries: ['toddlers', 'school-hall', 'guitar-singer', 'meal-friends'], team: ['team-ayesha', 'team-chris', 'team-grace'], messages: ['sermon-hall', 'mic-audience', 'open-bible'], events: ['congregation-hall', 'friends-picnic', 'candles'] },
},
'community-family': {
id: 'community-family', template: 'community', label: 'Community: a family church with small groups', alternate: false,
@@ -222,6 +247,7 @@ export const DEMO_SEEDS: Record<WebsiteDemoProfile, DemoSeed> = {
['christmas-family-service', 'Christmas family service', 25, 'Our nativity, sung by the kids, followed by tea.'],
],
venue: '{name}',
photos: { hero: 'meal-family', collage: ['kids-craft', 'family-walk'], welcome: 'welcome-hug', pastor: 'pastor-andile', invite: 'coffee-group', ministries: ['toddlers', 'teens', 'band-small', 'bible-coffee'], team: ['team-michelle', 'team-reddy', 'team-lwazi'], messages: ['bible-study', 'open-bible', 'mic-audience'], events: ['friends-picnic', 'kids-drawing', 'candles'] },
},
'community-town': {
id: 'community-town', template: 'community', label: 'Community: a country-town church serving its district', alternate: true,
@@ -257,6 +283,7 @@ export const DEMO_SEEDS: Record<WebsiteDemoProfile, DemoSeed> = {
['new-year-prayer', 'New Year prayer breakfast', 36, 'Pray for the year ahead over breakfast in the hall.'],
],
venue: '{name}',
photos: { hero: 'farm-road', collage: ['farm-bales', 'country-church'], welcome: 'meal-table', pastor: 'pastor-willem', invite: 'church-light', ministries: ['kids-class', 'youth-outdoors', 'choir-gospel', 'food-parcels'], team: ['team-elsie', 'team-bongani', 'team-marie'], messages: ['pulpit', 'church-quiet', 'open-bible'], events: ['farm-bales', 'candles', 'prayer-group'] },
},
'clean-modern': {
id: 'clean-modern', template: 'clean', label: 'Clean: a contemporary church, simply put', alternate: false,
@@ -292,6 +319,7 @@ export const DEMO_SEEDS: Record<WebsiteDemoProfile, DemoSeed> = {
['christmas-day', 'Christmas Day', 28, 'One family service at 09:00, about 45 minutes.'],
],
venue: '{name}',
photos: { hero: 'coffee-friends', collage: ['meal-table', 'guitar-singer'], welcome: 'bible-coffee', pastor: 'pastor-daniel', invite: 'church-light', ministries: ['kids-teacher', 'students-lecture', 'guitar-room', 'meal-friends'], team: ['team-refilwe', 'team-sam', 'team-nadia'], messages: ['sermon-dark', 'mic-white', 'open-bible'], events: ['coffee-group', 'candles', 'congregation-pews'] },
},
'clean-campus': {
id: 'clean-campus', template: 'clean', label: 'Clean: a church near the university', alternate: true,
@@ -327,6 +355,7 @@ export const DEMO_SEEDS: Record<WebsiteDemoProfile, DemoSeed> = {
['carols-on-campus', 'Carols on campus', 19, 'Carols on the library lawn for students who are still here.'],
],
venue: '{name}',
photos: { hero: 'campus-path', collage: ['students-lawn', 'supper-hall'], welcome: 'students-lecture', pastor: 'pastor-ian', invite: 'meal-table', ministries: ['family-picnic', 'bible-study', 'guitar-singer', 'students-fair'], team: ['team-lisa', 'team-thabo', 'team-priya'], messages: ['mic-crowd', 'mic-white', 'sermon-hall'], events: ['prayer-group', 'meal-friends', 'candles'] },
},
};
+8 -2
View File
@@ -82,8 +82,14 @@ function brandFor(church: Church | null, template: WebsiteTemplate) {
/** Where the site serves a YouTube video's thumbnail from (site/thumbnails.ts): visitors never ask YouTube. */
export const thumbnailPath = (videoId: string) => `/api/thumbnails/${videoId}.jpg`;
/** A message's thumbnail on the site: its YouTube video's, served from here; none for Spotify. */
export function messageThumbnail(m: { source: string; mediaUrl: string }) {
/**
* A message's thumbnail on the site: its YouTube video's, served from here; none for Spotify. A
* `thumbnailUrl` that is one of the site's own uploads comes first: the demo church's messages
* have photos, while their video is a stand-in (admins and the YouTube feed store YouTube's
* address there, which is never used).
*/
export function messageThumbnail(m: { source: string; mediaUrl: string; thumbnailUrl?: string | null }) {
if (m.thumbnailUrl && /^\/api\/uploads\/[\w./-]+$/.test(m.thumbnailUrl) && !m.thumbnailUrl.includes('..')) return m.thumbnailUrl;
const yt = m.source === 'spotify' ? null : youtubeId(m.mediaUrl);
return yt ? thumbnailPath(yt) : null;
}