diff --git a/apps/website/CHANGELOG.md b/apps/website/CHANGELOG.md index 824ccd0..f636100 100644 --- a/apps/website/CHANGELOG.md +++ b/apps/website/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog — Church Website +## [1.2.0] — 2026-11-27 + +No migration, no new environment settings. Its first start on an existing site adds the missing +fixed pages (below). + +### Fixed + +- **A new install had no pages**, so its home page (and the live preview of it) showed only the + header and footer whatever was chosen under Template and style, and Plan your visit, About, Give, + Contact and the rest didn't exist. Only `npm run demo` made pages. Now the backend adds the fixed + pages at startup (`src/site/starter.ts`) with starter text: Home with every homepage section, + Plan your visit, About us, Ministries, Leadership, Events, Messages, Give, Contact, and Terms and + Safeguarding (footer links, not in the menu; WEBSITE-1.0-PLAN §2). All of them while a site has + none of them (pages it made itself move after them; an address already taken is skipped), else + only a missing home page. A removed page isn't brought back. They're drafts, published with the + site; the audit log says "Added the starter pages". Found on cross-demo2. +- **Template and style → Home page layout:** the Latest message's Card layout had no name. +- **Media picker:** the "No image" placeholder had too little contrast (WCAG AA). + +### Added + +- **Site icon** (Settings): a picture from the media library as the favicon, live at once + (setting `favicon_media_id`; `favicon` in the site content). Without one the site uses the + church's icon from its profile, else a default: the church's initial on its brand colour (a cross + before the church is known). Every page links `/site-icon?v=…`, which redirects to the icon or + serves the default SVG; the version changes with the icon. + ## [1.1.0] — 2026-11-26 No migration, no new settings, no backend changes. The admin redesigned as Cross Events' admin diff --git a/apps/website/WHATS-NEW.md b/apps/website/WHATS-NEW.md index cf43d67..c9e772d 100644 --- a/apps/website/WHATS-NEW.md +++ b/apps/website/WHATS-NEW.md @@ -3,6 +3,15 @@ What each version changes for the church, in plain language (read by the Hub like Cross Events' WHATS-NEW.md; a section shows once its version is tagged). +## 1.2.0 + +- **Your home page and the other pages are there from the start:** a new website now comes with + its home page, Plan your visit, About us, Give, Contact and the rest, with some starter text to + change. Before, a new website had no pages, so the home page and its preview were empty apart + from the header and footer. +- **Your own site icon:** under **Settings → Site icon**, choose the little picture that shows in + the browser tab and bookmarks. Until you do, your site shows your church's initial in its colour. + ## 1.1.0 - **An easier admin.** A menu with icons down the side, and a dashboard with a tile for every part diff --git a/apps/website/backend/package.json b/apps/website/backend/package.json index 7806e74..d32c7bf 100644 --- a/apps/website/backend/package.json +++ b/apps/website/backend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/website-backend", - "version": "1.1.0", + "version": "1.2.0", "description": "Church Website: the public site's content API, the admin API, publishing and uploads", "private": true, "type": "module", diff --git a/apps/website/backend/src/admin/settings.ts b/apps/website/backend/src/admin/settings.ts index 055c644..b1fc24e 100644 --- a/apps/website/backend/src/admin/settings.ts +++ b/apps/website/backend/src/admin/settings.ts @@ -1,7 +1,9 @@ /** * The site's own settings (WEBSITE-1.0-PLAN §10, "Settings"), live at once (they aren't the site's * design): the Coming soon line (§5), and the search engines' verification codes (ROADMAP-v3 §11: - * Google Search Console and Bing Webmaster Tools), shown as `` tags on the home page. Also the + * Google Search Console and Bing Webmaster Tools), shown as `` tags on the home page, and the + * site's icon (1.2.0: the favicon, a picture from the media library; without one the site uses the + * church's icon from its profile, else one made from its colour and initial). Also the * menu's order, and the audit log. */ import { z } from 'zod'; @@ -18,13 +20,14 @@ const schema = z.object({ comingSoonText: z.string().trim().max(300).optional(), googleVerification: code.optional(), bingVerification: code.optional(), + faviconId: z.string().uuid().nullable().optional(), }); -export type SiteSettings = { comingSoonText: string; googleVerification: string | null; bingVerification: string | null }; +export type SiteSettings = { comingSoonText: string; googleVerification: string | null; bingVerification: string | null; faviconId: string | null }; export async function getSettings(ctx: Ctx): Promise { - const [coming, google, bing] = await Promise.all([ctx.settings.get('coming_soon_text'), ctx.settings.get('google_verification'), ctx.settings.get('bing_verification')]); - return { comingSoonText: coming || 'Our new website is on its way.', googleVerification: google || null, bingVerification: bing || null }; + const [coming, google, bing, favicon] = await Promise.all([ctx.settings.get('coming_soon_text'), ctx.settings.get('google_verification'), ctx.settings.get('bing_verification'), ctx.settings.get('favicon_media_id')]); + return { comingSoonText: coming || 'Our new website is on its way.', googleVerification: google || null, bingVerification: bing || null, faviconId: favicon || null }; } export async function saveSettings(ctx: Ctx, body: unknown, by: { id: string; role: string }) { @@ -35,10 +38,14 @@ export async function saveSettings(ctx: Ctx, body: unknown, by: { id: string; ro throw new ApiError(400, 'VALIDATION', 'Some settings need another look.', fields); } const s = r.data; + if (s.faviconId && !(await ctx.db.mediaAsset.findUnique({ where: { id: s.faviconId } }))) { + throw new ApiError(400, 'VALIDATION', 'Some settings need another look.', { faviconId: 'That picture isn\'t in the media library' }); + } await ctx.settings.setMany({ ...(s.comingSoonText !== undefined ? { coming_soon_text: s.comingSoonText || null } : {}), ...(s.googleVerification !== undefined ? { google_verification: s.googleVerification || null } : {}), ...(s.bingVerification !== undefined ? { bing_verification: s.bingVerification || null } : {}), + ...(s.faviconId !== undefined ? { favicon_media_id: s.faviconId || null } : {}), }); await audit(ctx, { actorId: by.id, actorRole: by.role, action: 'settings_changed', targetType: 'settings', targetId: null, metadata: { fields: Object.keys(s) } }); return getSettings(ctx); @@ -59,7 +66,7 @@ export async function orderPages(ctx: Ctx, body: unknown, by: { id: string }) { } const ACTIONS: Record = { - site_published: 'Published the site', change_discarded: 'Discarded a change', version_restored: 'Restored a version', + site_published: 'Published the site', change_discarded: 'Discarded a change', version_restored: 'Restored a version', starter_pages_added: 'Added the starter pages', preview_link_created: 'Made a preview link', preview_link_revoked: 'Stopped a preview link', first_owner_signed_in: 'Signed in as the first Owner', admin_signed_in: 'Signed in', admin_signed_out: 'Signed out', admin_sign_in_refused: 'Was refused sign-in (no role here)', website_user_added: 'Gave someone access', diff --git a/apps/website/backend/src/index.ts b/apps/website/backend/src/index.ts index 5d27372..7c0f75d 100644 --- a/apps/website/backend/src/index.ts +++ b/apps/website/backend/src/index.ts @@ -11,6 +11,7 @@ import { createApp } from './app.js'; import { createCtx } from './context.js'; import { connectFromEnv, heartbeat, startHeartbeats } from './hub/client.js'; import { loadConfig } from './lib/config.js'; +import { ensureStarterPages } from './site/starter.js'; import { startYoutubeSync } from './site/youtube.js'; import { startFeedSync } from './feed/feed.js'; @@ -20,6 +21,10 @@ async function main() { if (!url) throw new Error('DATABASE_URL isn\'t set.'); const db = new PrismaClient({ adapter: new PrismaPg({ connectionString: url, connectionTimeoutMillis: 5000 }) }); const ctx = createCtx(config, db); + // A new install's fixed pages (home, Plan your visit, …), before anything is served. + await ensureStarterPages(ctx) + .then((kinds) => { if (kinds.length) console.log(`[website] Added the starter pages: ${kinds.join(', ')}.`); }) + .catch((e) => console.error('[website] Couldn\'t add the starter pages:', (e as Error).message)); const app = createApp(ctx); const server = app.listen(config.port, () => console.log(`[website] Listening on ${config.port} (${config.publicUrl}).`)); const stopHeartbeats = startHeartbeats(ctx); diff --git a/apps/website/backend/src/site/content.ts b/apps/website/backend/src/site/content.ts index 78e2550..60d3f59 100644 --- a/apps/website/backend/src/site/content.ts +++ b/apps/website/backend/src/site/content.ts @@ -8,7 +8,7 @@ import { TEMPLATE_FONT_PAIRINGS, type Church, type CrosscodeEvent, type WebsiteT import type { Ctx } from '../context.js'; import { churchProfile } from '../church/profile.js'; import { buildPalette, type Palette } from './palette.js'; -import { buildSnapshot, imageOf, publishedSnapshot, type Image, type Snapshot } from './snapshot.js'; +import { buildSnapshot, imageOf, mediaUrl, publishedSnapshot, type Image, type Snapshot } from './snapshot.js'; import { headerIsTransparent, TEMPLATE_STYLE, type Variant } from './variants.js'; export type SiteEvent = { @@ -50,6 +50,8 @@ type Common = { style: { fontPairing: string; corners: string }; /** Search engines' verification codes, for the home page's meta tags (§11). */ verification: { google: string | null; bing: string | null }; + /** 1.2.0: the site's own icon (Settings), else null: the church's icon, else one made for it. */ + favicon: string | null; }; export type SiteContent = @@ -158,13 +160,15 @@ export async function previewContent(ctx: Ctx, opts: { asTemplate?: WebsiteTempl } async function contentFrom(ctx: Ctx, church: Church | null, published: { number: number; publishedAt: Date; snapshot: Snapshot } | null): Promise { - const [google, bing] = await Promise.all([ctx.settings.get('google_verification'), ctx.settings.get('bing_verification')]); + const [google, bing, faviconId] = await Promise.all([ctx.settings.get('google_verification'), ctx.settings.get('bing_verification'), ctx.settings.get('favicon_media_id')]); const verification = { google: google || null, bing: bing || null }; + const icon = faviconId ? await ctx.db.mediaAsset.findUnique({ where: { id: faviconId } }) : null; + const favicon = icon ? mediaUrl(icon.filename) : null; if (!published) { const design = await ctx.db.siteDesign.findUnique({ where: { id: 1 }, select: { template: true } }); const template = (design?.template ?? 'heritage') as WebsiteTemplate; return { - mode: 'coming-soon', template, church, ...brandFor(church, template), verification, + mode: 'coming-soon', template, church, ...brandFor(church, template), verification, favicon, comingSoonText: (await ctx.settings.get('coming_soon_text')) || 'Our new website is on its way.', }; } @@ -175,5 +179,5 @@ async function contentFrom(ctx: Ctx, church: Church | null, published: { number: return [p.path, headerIsTransparent(template, snapshot.design.style.header, hero)]; })); const [messages, events] = await Promise.all([liveMessages(ctx), liveEvents(ctx)]); - return { mode: 'published', version: published.number, snapshot, transparentHeader, church, ...brandFor(church, template), verification, messages, events }; + return { mode: 'published', version: published.number, snapshot, transparentHeader, church, ...brandFor(church, template), verification, favicon, messages, events }; } diff --git a/apps/website/backend/src/site/starter.ts b/apps/website/backend/src/site/starter.ts new file mode 100644 index 0000000..954f427 --- /dev/null +++ b/apps/website/backend/src/site/starter.ts @@ -0,0 +1,88 @@ +/** + * 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 }; +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 { + 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; +} diff --git a/apps/website/backend/tests/settings.test.ts b/apps/website/backend/tests/settings.test.ts index f68c3d0..76a44d9 100644 --- a/apps/website/backend/tests/settings.test.ts +++ b/apps/website/backend/tests/settings.test.ts @@ -55,6 +55,18 @@ describe('settings, the menu and the audit log', () => { assert.equal((await go('put', '/settings', { googleVerification: '