diff --git a/apps/website/CHANGELOG.md b/apps/website/CHANGELOG.md index 9932b3e..2c58e8b 100644 --- a/apps/website/CHANGELOG.md +++ b/apps/website/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog — Church Website +## [1.12.1] — 2026-12-01 + +No migration. No new environment settings. + +### Fixed + +- **The "With map" layouts showed no map** (Service times, Contact): the map needs the address's + `geo`, which Accounts' profile never has. `church/geocode.ts` now looks the address up on + OpenStreetMap's Nominatim (the street, else the suburb and city) for what visitors and the + preview are shown, and keeps it in AppSetting `church_geocode` with the address it was for + (looked up again when the address changes; one not found is tried again after a day). The + admin's copy of the profile is left as Accounts has it. + ## [1.12.0] — 2026-12-01 No migration (the layouts live in `SiteDesign.variants`). No new environment settings. diff --git a/apps/website/WHATS-NEW.md b/apps/website/WHATS-NEW.md index 3f96a11..c3bbfd7 100644 --- a/apps/website/WHATS-NEW.md +++ b/apps/website/WHATS-NEW.md @@ -3,6 +3,12 @@ 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.12.1 + +- **The map now shows.** The "With map" layouts for Service times and Contact find your church's + address on the map by themselves. If the map still doesn't show, check the address in **Church + details**. + ## 1.12.0 - **Choose how your Ministries, Leadership, Events, Messages and Contact pages look.** Each has diff --git a/apps/website/backend/package.json b/apps/website/backend/package.json index 2977f4e..119a150 100644 --- a/apps/website/backend/package.json +++ b/apps/website/backend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/website-backend", - "version": "1.12.0", + "version": "1.12.1", "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/church/geocode.ts b/apps/website/backend/src/church/geocode.ts new file mode 100644 index 0000000..cce6c63 --- /dev/null +++ b/apps/website/backend/src/church/geocode.ts @@ -0,0 +1,68 @@ +/** + * The church's place on the map. The "With map" layouts (Service times, Contact) need the address's + * `geo`, but Accounts' profile rarely has one (nothing there fills it in), so the map never showed. + * When the address has none, it's looked up once on OpenStreetMap's Nominatim (no Google, as the + * map itself) and kept in AppSetting `church_geocode` with the address it was for: a new address + * is looked up again, one that wasn't found is tried again after a day. Only what visitors are + * shown gets it; the admin's copy of the profile is left as Accounts has it. + */ +import type { Church } from '@crosscode/contracts'; +import type { Ctx } from '../context.js'; + +type Address = NonNullable; +type Geo = NonNullable; +type Stored = { query: string; geo: Geo | null; at: number }; + +const KEY = 'church_geocode'; +const RETRY_MS = 24 * 3600e3; +const TIMEOUT_MS = 4000; +const pending = new Map>(); + +const queryOf = (a: Address, full: boolean) => + (full ? [a.line1, a.line2, a.suburb, a.city, a.province, a.postalCode] : [a.suburb, a.city, a.province]).map((s) => s?.trim()).filter(Boolean).join(', '); + +async function lookup(ctx: Ctx, q: string, country: string): Promise { + const url = `https://nominatim.openstreetmap.org/search?format=jsonv2&limit=1&countrycodes=${encodeURIComponent(country.toLowerCase())}&q=${encodeURIComponent(q)}`; + const res = ctx.fetch + ? await ctx.fetch(url) + : await fetch(url, { headers: { accept: 'application/json', 'user-agent': 'CrossCode-Website/1.0 (church website map)' }, signal: AbortSignal.timeout(TIMEOUT_MS) }); + if (!res.ok) throw new Error(`Nominatim answered ${res.status}`); + const hits = (await res.json()) as { lat?: string; lon?: string }[]; + const lat = Number(hits[0]?.lat), lng = Number(hits[0]?.lon); + return Number.isFinite(lat) && Number.isFinite(lng) && Math.abs(lat) <= 90 && Math.abs(lng) <= 180 ? { lat, lng } : null; +} + +async function geocode(ctx: Ctx, a: Address): Promise { + const query = queryOf(a, true); + if (!query) return null; + const stored = await ctx.settings.json(KEY, null); + if (stored?.query === query && (stored.geo || ctx.now().getTime() - stored.at < RETRY_MS)) return stored.geo; + // Tests never reach the real Nominatim (they give ctx.fetch when they want a lookup). + if (!ctx.fetch && process.env.NODE_TEST_CONTEXT) return null; + let p = pending.get(query); + if (!p) { + p = (async () => { + try { + // The street can be too exact for OpenStreetMap: then the suburb and city. + const geo = (await lookup(ctx, query, a.country)) ?? (queryOf(a, false) ? await lookup(ctx, queryOf(a, false), a.country) : null); + await ctx.settings.set(KEY, JSON.stringify({ query, geo, at: ctx.now().getTime() } satisfies Stored)); + return geo; + } catch (e) { + console.warn('[church] address not found on the map:', (e as Error).message); + return stored?.query === query ? stored.geo : null; + } finally { + pending.delete(query); + } + })(); + pending.set(query, p); + } + return p; +} + +/** The profile with its address's `geo` filled in when it had none. Never throws. */ +export async function withGeo(ctx: Ctx, church: Church | null): Promise { + const a = church?.contact.address; + if (!church || !a || a.geo) return church; + const geo = await geocode(ctx, a).catch(() => null); + return geo ? { ...church, contact: { ...church.contact, address: { ...a, geo } } } : church; +} diff --git a/apps/website/backend/src/site/content.ts b/apps/website/backend/src/site/content.ts index 351e28c..65aee98 100644 --- a/apps/website/backend/src/site/content.ts +++ b/apps/website/backend/src/site/content.ts @@ -7,6 +7,7 @@ import { TEMPLATE_FONT_PAIRINGS, type Church, type CrosscodeEvent, type WebsiteTemplate } from '@crosscode/contracts'; import type { Ctx } from '../context.js'; import { churchProfile } from '../church/profile.js'; +import { withGeo } from '../church/geocode.js'; import { buildPalette, type Palette } from './palette.js'; import { buildSnapshot, framed, imageOf, mediaUrl, publishedSnapshot, type Image, type Snapshot } from './snapshot.js'; import { headerIsTransparent, TEMPLATE_STYLE, type Variant } from './variants.js'; @@ -156,13 +157,13 @@ async function liveEvents(ctx: Ctx): Promise { /** What visitors see: the latest published version, else Coming soon. */ export async function siteContent(ctx: Ctx): Promise { - const [church, published] = await Promise.all([churchProfile(ctx), publishedSnapshot(ctx)]); + const [church, published] = await Promise.all([churchProfile(ctx).then((c) => withGeo(ctx, c)), publishedSnapshot(ctx)]); return contentFrom(ctx, church, published); } /** The preview (§4): the working copy as it would look published, whatever was published before. */ export async function previewContent(ctx: Ctx, opts: { asTemplate?: WebsiteTemplate } = {}): Promise { - const [church, snapshot] = await Promise.all([churchProfile(ctx), buildSnapshot(ctx, opts)]); + const [church, snapshot] = await Promise.all([churchProfile(ctx).then((c) => withGeo(ctx, c)), buildSnapshot(ctx, opts)]); return contentFrom(ctx, church, { number: 0, publishedAt: ctx.now(), snapshot }); } diff --git a/apps/website/backend/tests/site.test.ts b/apps/website/backend/tests/site.test.ts index 6929034..68b0db9 100644 --- a/apps/website/backend/tests/site.test.ts +++ b/apps/website/backend/tests/site.test.ts @@ -128,6 +128,29 @@ describe('the public site\'s content', () => { }); } + it("finds the church's address on the map once when Accounts has no geo (the With map layouts)", async () => { + const h = await harness({ linked: false }); + const base = demoProfile('http://x.test'); + const address = { ...base.contact.address!, geo: null }; + await h.ctx.settings.set('church_profile_local', JSON.stringify({ ...base, contact: { ...base.contact, address } })); + const asked: string[] = []; + let answer: unknown[] = [{ lat: '-25.75', lon: '28.19' }]; + h.ctx.fetch = async (url) => { asked.push(url); return new Response(JSON.stringify(answer), { headers: { 'content-type': 'application/json' } }); }; + assert.deepEqual((await siteContent(h.ctx)).church?.contact.address?.geo, { lat: -25.75, lng: 28.19 }); + assert.deepEqual((await siteContent(h.ctx)).church?.contact.address?.geo, { lat: -25.75, lng: 28.19 }); + assert.equal(asked.length, 1, 'kept, not asked again'); + assert.match(asked[0]!, /^https:\/\/nominatim\.openstreetmap\.org\/search\?.*countrycodes=za.*12%20Acacia%20Avenue/); + // A new address that isn't found: the street, then the suburb and city; no geo, no map. + answer = []; + await h.ctx.settings.set('church_profile_local', JSON.stringify({ ...base, contact: { ...base.contact, address: { ...address, line1: '1 Nowhere Road' } } })); + assert.equal((await siteContent(h.ctx)).church?.contact.address?.geo, null); + assert.equal(asked.length, 3); + // A profile that has its geo already is left alone. + await h.ctx.settings.set('church_profile_local', JSON.stringify(base)); + assert.deepEqual((await siteContent(h.ctx)).church?.contact.address?.geo, base.contact.address!.geo); + assert.equal(asked.length, 3); + }); + for (const profile of agent.WEBSITE_DEMO_PROFILES) { it(`1.3.0: loads the ${profile} demo, keeping the church's own profile and naming it`, async () => { const h = await harness({ linked: false }); diff --git a/apps/website/frontend/package.json b/apps/website/frontend/package.json index 1b93b38..0bb13d8 100644 --- a/apps/website/frontend/package.json +++ b/apps/website/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/website-frontend", - "version": "1.12.0", + "version": "1.12.1", "private": true, "description": "Church Website: the church's public site in its template, and the admin", "scripts": { diff --git a/docs/VERSIONS.md b/docs/VERSIONS.md index 4c2b3fc..c48f18b 100644 --- a/docs/VERSIONS.md +++ b/docs/VERSIONS.md @@ -11,7 +11,7 @@ separately below; the two often differ. | What | Repo | Latest | Tag | Released | |------|------|--------|-----|----------| | Cross Events | `crosscode-platform` (`apps/events`) | **3.9.0** | `events@3.9.0` | 2026-12-01 | -| Church Website | `crosscode-platform` (`apps/website`) | **1.12.0** | `website@1.12.0` | 2026-12-01 | +| Church Website | `crosscode-platform` (`apps/website`) | **1.12.1** | `website@1.12.1` | 2026-12-01 | | Accounts | `crosscode-platform` (`apps/accounts`) | **1.10.0** | `accounts@1.10.0` | 2026-12-01 | | Server agent | `crosscode-platform` (`apps/agent`) | **1.7.0** | `agent@1.7.0` | 2026-11-30 | | Contracts | `crosscode-platform` (`packages/contracts`) | **1.24.0** | `contracts@1.24.0` | 2026-11-30 | @@ -31,7 +31,7 @@ on each run, so merging to `main` and pushing releases it. Its changes are liste | `@crosscode/demo` | `packages/demo` | 1.1.0 (the demo scenarios' churches, people and logos; ships with Accounts 1.9.0, Events 3.8.0 and Website 1.8.0) | | `@crosscode/seo` | `packages/seo` | 1.0.0 (released with Events 2.4.0) | | `@crosscode/ui` | `packages/ui` | 0.4.0 (fonts, `ChurchFooter`, `ColourField`; 0.2.0 with Accounts 1.7.0, 0.3.0 with Events 3.7.0, 0.4.0 with Accounts 1.10.0 and Website 1.9.0) | -| Website | `apps/website` | 1.12.0 (1.0.0–1.1.0 released 2026-11-26, 1.2.0–1.7.0 on 2026-11-27, 1.7.1 on 2026-11-28, 1.8.0 on 2026-11-30, 1.9.0 to 1.12.0 on 2026-12-01; tagged as `website@…`; see "Deployed / rolled out" for where it runs) | +| Website | `apps/website` | 1.12.1 (1.0.0–1.1.0 released 2026-11-26, 1.2.0–1.7.0 on 2026-11-27, 1.7.1 on 2026-11-28, 1.8.0 on 2026-11-30, 1.9.0 to 1.12.1 on 2026-12-01; tagged as `website@…`; see "Deployed / rolled out" for where it runs) | | App | `apps/app` | 0.0.0 on main (a placeholder); 0.1.0 on the branch `feat/app-scaffold`, being built from 2026-12-01 (phase 6; not released, merged and tagged `app@1.0.0` when the plan is built) | These shared packages ship inside the apps that use them, from the same checkout, so they don't @@ -39,6 +39,11 @@ need their own tags until something outside this repo depends on them. ## What each latest release was for +- **Website 1.12.1 (2026-12-01):** the "With map" layouts (Service times, Contact) showed no map, + because Accounts' profile has no `geo`; the Website now looks the address up on OpenStreetMap's + Nominatim and keeps it. No migration, no contracts change, works with any Accounts. Checked: the + Website backend tests (157). Not deployed yet. + - **Website 1.12.0 (2026-12-01):** the Ministries, Leadership, Events, Messages and Contact pages each get three layouts, set on the page in Pages or together under Template and style → Other pages, with the template's suggestion marked; a site saved before keeps its pages' look until