Files
crosscode-platform/apps/website/backend/src/site/starter.ts
T
joshuaandClaude Opus 5.5 79e1450df6 Website 1.2.0: starter pages on a new install, and a site icon
A new install had no pages, so the home page and its live preview showed
only the header and footer (found on cross-demo2). The backend now adds the
fixed pages with starter text at startup. Settings -> Site icon sets the
favicon, with a default from the church's colour and initial. The Latest
message's Card layout has its name; the media picker's placeholder has
enough contrast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 08:18:47 +02:00

89 lines
6.8 KiB
TypeScript

/**
* The fixed pages (WEBSITE-1.0-PLAN §6) with starter text, for a site that has no pages yet: a new
* install. Without them the home page had no sections (the site and its preview showed only the
* header and footer) and the other pages didn't exist. Terms and Safeguarding come from starter
* text too (§2), linked from the footer rather than the menu.
*
* Checked at startup (ensureStarterPages): a site with none of the fixed pages gets them all, one
* without a home page gets that. A page a church removed (archived) isn't brought back, except home,
* which can't be removed. Nothing is published: the pages are drafts like any other change. The text names no church, since a new install isn't
* always linked to its church profile yet; every section and block can be edited.
*/
import type { Ctx } from '../context.js';
import { audit } from '../lib/audit.js';
import type { SectionData } from './sections.js';
type Block = { type: string; data: Record<string, unknown> };
type StarterPage = { kind: string; slug: string; title: string; inNav?: boolean; description: string; sections: Block[] };
const VISIT = { label: 'Plan your visit', href: '/visit' };
export const STARTER_HOME: SectionData = {
hero: { headline: 'You are welcome here', subline: 'Join us this Sunday. Come as you are.', images: [], videoId: null, button: VISIT },
serviceTimes: { heading: 'Join us this Sunday', note: null },
welcome: {
heading: 'Welcome', mission: null, imageId: null, pastor: null,
body: 'We are a family of ordinary people who have found good news in Jesus. Whether you have followed him for years or are just curious, there is a seat for you here.',
},
ministries: { heading: 'Find your place', intro: 'There is something for every age and stage.' },
team: { heading: 'Our team', intro: null },
events: { heading: 'Coming up', count: 3 },
latestMessage: { heading: 'Latest message' },
invitation: { heading: 'We saved you a seat', text: 'New here? Let us know you are coming and we will meet you at the door.', button: VISIT, imageId: null },
};
const text = (heading: string | null, body: string): Block => ({ type: 'text', data: { heading, body } });
export const STARTER_PAGES: StarterPage[] = [
{ kind: 'home', slug: 'home', title: 'Home', description: 'Join us this Sunday. Come as you are.', sections: Object.entries(STARTER_HOME).map(([type, data]) => ({ type, data })) },
{
kind: 'visit', slug: 'visit', title: 'Plan your visit', description: 'What to expect on your first Sunday with us.', sections: [
text('What to expect', 'We sing together, pray, and hear a message from the Bible. Dress is casual, and there is coffee after the service.'),
{ type: 'cta', data: { heading: 'Questions before you come?', text: 'Get in touch and we will get back to you.', button: { label: 'Contact us', href: '/contact' } } },
],
},
{ kind: 'about', slug: 'about', title: 'About us', description: 'Our story, what we believe and what we value.', sections: [text('Our story', 'Tell your church\'s story here: how it started, what you believe and what you value.')] },
{ kind: 'ministries', slug: 'ministries', title: 'Ministries', description: 'Find your place in our church family.', sections: [] },
{ kind: 'leadership', slug: 'leadership', title: 'Leadership', description: 'The team who lead our church.', sections: [] },
{ kind: 'events', slug: 'events', title: 'Events', description: 'What is coming up at our church.', sections: [] },
{ kind: 'messages', slug: 'messages', title: 'Messages', description: 'Sunday messages from our church.', sections: [] },
{ kind: 'give', slug: 'give', title: 'Give', description: 'How to give to our church.', sections: [text('Giving', 'Thank you for giving. Add how to give here: your bank details, or links to SnapScan, Zapper or PayFast.')] },
{ kind: 'contact', slug: 'contact', title: 'Contact', description: 'How to find us and get in touch.', sections: [] },
{
kind: 'terms', slug: 'terms', title: 'Terms of use', inNav: false, description: 'The terms for using this website.', sections: [
text(null, 'This website is run by our church to share who we are, what we do and when we meet. You may use it for your own, personal purposes.\n\nWe do our best to keep it accurate and up to date, but things change: please check service times and events with us if you are unsure.\n\nLinks to other websites are for your convenience; we are not responsible for what they say.\n\nHow we handle personal information is in our privacy notice, linked at the bottom of every page.'),
],
},
{
kind: 'safeguarding', slug: 'safeguarding', title: 'Safeguarding', inNav: false, description: 'How we keep children and vulnerable adults safe.', sections: [
text(null, 'We are committed to the safety of every child and vulnerable adult in our care. Everyone who serves with children or vulnerable adults is screened and trained, and we follow a written safeguarding policy.\n\nIf you are worried about someone\'s safety, or about how anyone at our church has behaved, please speak to a member of our leadership team. If someone is in immediate danger, contact the police.'),
],
},
];
/**
* Adds the fixed pages a site is missing: all of them while it has none of them (only pages it made
* itself, or nothing at all), else just the home page if that's missing. A page whose address
* another page already has is left out. Custom pages move after them. Returns the kinds added.
*/
export async function ensureStarterPages(ctx: Ctx): Promise<string[]> {
const db = ctx.db;
const existing = await db.page.findMany({ select: { id: true, kind: true, slug: true, position: true, archivedAt: true } });
const fixed = existing.filter((p) => p.kind !== 'custom');
const wanted = fixed.length === 0 ? STARTER_PAGES : fixed.some((p) => p.kind === 'home' && !p.archivedAt) ? [] : STARTER_PAGES.filter((p) => p.kind === 'home');
const slugs = new Set(existing.map((p) => p.slug));
const adding = wanted.filter((p) => !slugs.has(p.slug));
if (!adding.length) return [];
// The site's own pages keep their order, after the fixed ones.
for (const p of existing.filter((x) => x.kind === 'custom')) await db.page.update({ where: { id: p.id }, data: { position: p.position + adding.length } });
let position = 0;
for (const p of adding) {
const page = await db.page.create({ data: { kind: p.kind as never, slug: p.slug, title: p.title, position: position++, description: p.description, inNav: p.inNav ?? true } });
let i = 0;
for (const s of p.sections) await db.section.create({ data: { pageId: page.id, type: s.type, position: i++, data: s.data as never } });
}
const kinds = adding.map((p) => p.kind);
await audit(ctx, { actorId: null, actorRole: 'system', action: 'starter_pages_added', targetType: 'page', metadata: { kinds } });
return kinds;
}