diff --git a/apps/app/CHANGELOG.md b/apps/app/CHANGELOG.md index 8463818..4f023e6 100644 --- a/apps/app/CHANGELOG.md +++ b/apps/app/CHANGELOG.md @@ -2,8 +2,9 @@ ## [Unreleased] -Being built for `app@1.0.0` (docs/APP-1.0-PLAN.md). Three migrations so far (`20261201000000_init`, -`20261202000000_house_of_prayer`, `20261203000000_prayer_requests`). +Being built for `app@1.0.0` (docs/APP-1.0-PLAN.md). Four migrations so far (`20261201000000_init`, +`20261202000000_house_of_prayer`, `20261203000000_prayer_requests`, `20261204000000_content`). +Ships `@crosscode/seo` 1.1.0 (`articleJsonLd`, workspace). ### Added @@ -77,5 +78,28 @@ Being built for `app@1.0.0` (docs/APP-1.0-PLAN.md). Three migrations so far (`20 - Screens: Ask for prayer (who sees it, the emergency numbers, South African by default), Pray for others, My prayer requests, and the admin's Prayer requests (waiting, open, escalated, closed, settings). The Prayer tab shows with either prayer module. +- **Announcements** (plan §5, `src/content/announcements.ts`): title, markdown text (shown without + HTML, `react-markdown`), image, an optional button, a campus from the church profile, everyone or + members only, pinned, a publish time and an end. Public ones are pages of their own (canonical, + Article JSON-LD, in the sitemap); members-only ones ask for a sign-in and are noindex. Content + admins write them (`/admin/announcements`). "Also send it" by email or WhatsApp is saved, and + sent once at the publish time with §8. The heartbeat counts the last 30 days. +- **Devotionals** (plan §6, `src/content/devotionals.ts`): Cross Code's from the Hub + (`crosscode-devotionals`, 01:15, and Sync now: the next 2 weeks from today in the church's + timezone, with the licence; exactly those days replaced, earlier ones kept, so a Hub outage + changes nothing), or the church's own (Settings → Devotionals, AppSetting `devotionals_source`), + written by Devotional writers or imported from the Hub's CSV (a preview first; days already + filled kept or replaced). Only KJV and BSB. The passage in full with its copyright line (and a + disclaimer where there is one) and Read in YouVersion; today's from midnight or the most recent; + the archive by month; members-only ones; the Acknowledgements page; Article JSON-LD. +- **Events** (plan §7, `src/events/`): simple events made by Content admins in the church's + timezone (`/admin/events`), and the event feed both ways, as the Website's: the App's own published + as `crosscode.event/1` (`/api/feed/v1/events`, removals for 90 days, `event.changed` to siblings), + and read-only copies of Cross Events' and the Website's (`event-feed`, every 15 minutes and on + their `event.changed`) with Register on the Events site and a canonical to the origin. Event + JSON-LD on the App's own events only. Linked products: publish, and show events from each sibling. +- Home shows today's devotional, the latest announcements (pinned first) and what's on. A sitemap + of the public pages (`/sitemap.xml`, never prayer, members-only items or imported events), named + in robots.txt. `GET /api/v1/app` gives the App's own address (`url`). - `env.template.json` (read by the Hub at the tag), `ecosystem.config.example.cjs` (ports 5400 / 3400 in development). diff --git a/apps/app/README.md b/apps/app/README.md index 698eb31..f811ca0 100644 --- a/apps/app/README.md +++ b/apps/app/README.md @@ -8,7 +8,7 @@ and notification settings need a sign-in through the church's Accounts. The admi **State:** being built (from 2026-12-01) on the branch `feat/app-scaffold`, which is merged into main only when `app@1.0.0` is done (main keeps a placeholder until then). Not released; -`app@1.0.0` is tagged when the plan is built. Done so far (the foundation, plan §1, §2, §10, §12, the House of Prayer, §3, and prayer requests, §4): +`app@1.0.0` is tagged when the plan is built. Done so far (the foundation, plan §1, §2, §10, §12, the House of Prayer, §3, prayer requests, §4, and announcements, devotionals and events, §5–§7): - **Backend:** Express + Prisma + pg-boss (ES modules, as the Website). Registers with the Hub (`CCP-` licence key, product `app`) and sends the heartbeat with the active-member band the App @@ -37,10 +37,12 @@ main only when `app@1.0.0` is done (main keeps a placeholder until then). Not re - **Prayer requests** (§4, `backend/src/requests/`): private to the prayer team by default, or shared with members after approval; redact, don't share, reply, escalate to Pastoral care; "I prayed" counts; closing after 30 days, deleted a year later; every view of a sender access-logged. +- **Announcements, devotionals and events** (§5–§7, `backend/src/content/`, `backend/src/events/`): + announcements for everyone or members; Cross Code's devotionals from the Hub each night (the next + 2 weeks) or the church's own with the CSV import, KJV and BSB only, Read in YouVersion; simple + events and the event feed both ways; Article and Event JSON-LD and a sitemap for the public pages. -**Still to come** (plan §5–§15): announcements, -devotionals (Cross Code's from the Hub: the next 2 weeks, today included, fetched each night; and -the church's own), events and the feed, email and WhatsApp, the rest of the admin, the export, +**Still to come** (plan §8–§15): email and WhatsApp (sending the outbox), the rest of the admin, the export, backups, the demo church and scenarios, `scripts/products/app.sh`, e2e and Lighthouse. - `backend/`: `npm run dev`, `npm test` (Node's test runner through tsx), `npm run build`. The diff --git a/apps/app/backend/src/content/devotionals.ts b/apps/app/backend/src/content/devotionals.ts index 0e95e99..fe595c7 100644 --- a/apps/app/backend/src/content/devotionals.ts +++ b/apps/app/backend/src/content/devotionals.ts @@ -81,6 +81,14 @@ export async function archive(ctx: Ctx, month: string, signedIn: boolean) { return rows.map((d) => ({ date: d.date, title: d.title, reference: d.reference, membersOnly: d.membersOnly })); } +/** The public days up to today from the chosen source (the last year), for the sitemap. */ +export async function publicDevotionalDays(ctx: Ctx) { + const [source, tz] = await Promise.all([devotionalSource(ctx), churchTimezone(ctx)]); + const today = localDate(ctx.now(), tz); + const rows = await ctx.db.devotional.findMany({ where: { source, membersOnly: false, date: { gte: addDays(today, -365), lte: today } }, select: { date: true, updatedAt: true }, orderBy: { date: 'desc' } }); + return rows.map((d) => ({ date: d.date, updatedAt: d.updatedAt.toISOString() })); +} + /** Every translation the App's devotionals quote, with its full notice (the Acknowledgements page). */ export async function acknowledgements(ctx: Ctx) { const used = new Set((await ctx.db.devotional.findMany({ select: { translation: true } })).map((d) => d.translation)); diff --git a/apps/app/backend/src/content/routes.ts b/apps/app/backend/src/content/routes.ts index 0d09d30..ede2d4d 100644 --- a/apps/app/backend/src/content/routes.ts +++ b/apps/app/backend/src/content/routes.ts @@ -29,9 +29,9 @@ import { currentSession, requireRole } from '../auth/sessions.js'; import { enabledModules } from '../modules.js'; import { publishOn, syncAll } from '../events/feed.js'; import { adminEvents, deleteEvent, eventBody, eventByKey, saveEvent, upcoming } from '../events/service.js'; -import { adminAnnouncements, announcementBody, announcementBySlug, currentAnnouncements, saveAnnouncement } from './announcements.js'; +import { adminAnnouncements, announcementBody, announcementBySlug, currentAnnouncements, saveAnnouncement, visibleWhere } from './announcements.js'; import { - acknowledgements, adminMonth, archive, deleteOwn, devotionalBody, devotionalOn, devotionalStatus, importCsv, saveOwn, setDevotionalSource, SyncError, + acknowledgements, adminMonth, archive, deleteOwn, devotionalBody, devotionalOn, devotionalStatus, importCsv, publicDevotionalDays, saveOwn, setDevotionalSource, SyncError, syncCrosscode, todaysDevotional, } from './devotionals.js'; @@ -99,6 +99,23 @@ export function contentRouter(ctx: Ctx) { return { devotional }; })); + // What the sitemap lists (ROADMAP-v3 §11): public pages of the modules that are on, never members-only ones or imported events. + r.get('/v1/sitemap', handle(async (_req, res) => { + res.set('Cache-Control', 'public, max-age=600'); + const on = await enabledModules(ctx); + const now = ctx.now(); + const [announcements, devotionals, events] = await Promise.all([ + on.includes('announcements') ? ctx.db.announcement.findMany({ where: { ...visibleWhere(now, false) }, select: { slug: true, updatedAt: true } }) : [], + on.includes('devotionals') ? publicDevotionalDays(ctx) : [], + on.includes('events') ? ctx.db.simpleEvent.findMany({ where: { publishedAt: { not: null, lte: now }, startsAt: { gte: new Date(now.getTime() - 30 * 864e5) } }, select: { slug: true, updatedAt: true } }) : [], + ]); + return { + announcements: announcements.map((a) => ({ slug: a.slug, updatedAt: a.updatedAt.toISOString() })), + devotionals, + events: events.map((e) => ({ key: e.slug, updatedAt: e.updatedAt.toISOString() })), + }; + })); + r.use('/v1/events', requireModule(ctx, 'events')); r.get('/v1/events', handle(async (_req, res) => { res.set('Cache-Control', 'public, max-age=60'); diff --git a/apps/app/backend/src/events/service.ts b/apps/app/backend/src/events/service.ts index 97f6a80..fce9add 100644 --- a/apps/app/backend/src/events/service.ts +++ b/apps/app/backend/src/events/service.ts @@ -12,7 +12,7 @@ import { ApiError } from '../http.js'; import { churchTimezone } from '../church/profile.js'; import { slugify, uniqueSlug } from '../lib/slug.js'; import { isDate, localParts, zonedTime } from '../lib/zoned.js'; -import { markRemoved, notifyLinks } from './feed.js'; +import { markRemoved, notifyLinks, toCrosscodeEvent } from './feed.js'; const DAY = 864e5; @@ -35,6 +35,8 @@ export type EventItem = { registration: { label: string; url: string } | null; /** The origin's page, for `` (imported events only). */ canonical: string | null; + /** A simple event as `crosscode.event/1`, for its page's Event JSON-LD (the origin's page only). */ + crosscode?: CrosscodeEvent; }; export function fromSimple(e: SimpleEvent): EventItem { @@ -79,7 +81,9 @@ export async function eventByKey(ctx: Ctx, key: string): Promise ctx.now()) return null; + const installId = await ctx.settings.get('hub_install_id'); + return { ...fromSimple(e), ...(installId ? { crosscode: toCrosscodeEvent(ctx, e, installId) } : {}) }; } // ── The admin's simple events ── diff --git a/apps/app/backend/src/public/app.ts b/apps/app/backend/src/public/app.ts index 3f09b8d..070d9ea 100644 --- a/apps/app/backend/src/public/app.ts +++ b/apps/app/backend/src/public/app.ts @@ -23,6 +23,8 @@ export type AppInfo = { modules: string[]; /** The church's timezone (the profile's, else APP_TIMEZONE): days and slots are in it (§1). */ timezone: string; + /** The App's own address (APP_URL), for canonicals, the sitemap and JSON-LD. */ + url: string; }; export function shortNameFor(church: Pick | null): string { @@ -44,5 +46,6 @@ export async function appInfo(ctx: Ctx): Promise { }, modules, timezone: church?.timezone ?? ctx.config.timezone, + url: ctx.config.publicUrl, }; } diff --git a/apps/app/backend/tests/content.test.ts b/apps/app/backend/tests/content.test.ts index 85036ba..ed7cc5d 100644 --- a/apps/app/backend/tests/content.test.ts +++ b/apps/app/backend/tests/content.test.ts @@ -261,3 +261,20 @@ describe('events', () => { assert.deepEqual((await visitor.get('/api/v1/events')).body.events, []); }); }); + +describe('the sitemap', () => { + it('lists public announcements, devotionals and the App\'s own events; never members-only ones', async () => { + const { editor, writer, visitor } = await setup(); + await editor.post('/api/v1/admin/announcements', announcement()); + await editor.post('/api/v1/admin/announcements', announcement({ title: 'Members only', audience: 'members' })); + await editor.post('/api/v1/admin/events', event()); + await writer.put('/api/v1/admin/devotionals/settings', { source: 'church' }); + await writer.post('/api/v1/admin/devotionals', { date: '2026-12-01', title: 'A', reference: 'John 3:16', translation: 'BSB', passageText: 'x', body: 'y' }); + await writer.post('/api/v1/admin/devotionals', { date: '2026-11-30', title: 'B', reference: 'John 3:17', translation: 'BSB', passageText: 'x', body: 'y', membersOnly: true }); + const map = (await visitor.get('/api/v1/sitemap')).body; + assert.deepEqual(map.announcements.map((a: { slug: string }) => a.slug), ['family-camp-registrations-open']); + assert.deepEqual(map.devotionals.map((d: { date: string }) => d.date), ['2026-12-01']); + assert.deepEqual(map.events.map((e: { key: string }) => e.key), ['family-camp-2026-12-12']); + assert.equal((await visitor.get('/api/v1/app')).body.url, 'https://app.hope.test'); + }); +}); diff --git a/apps/app/frontend/package.json b/apps/app/frontend/package.json index ff2acda..9203775 100644 --- a/apps/app/frontend/package.json +++ b/apps/app/frontend/package.json @@ -17,7 +17,8 @@ "lucide-react": "^0.536.0", "next": "^16.4.6", "react": "^19.3.1", - "react-dom": "^19.3.1" + "react-dom": "^19.3.1", + "react-markdown": "^10.1.0" }, "devDependencies": { "@eslint/eslintrc": "^3", diff --git a/apps/app/frontend/src/app/acknowledgements/page.tsx b/apps/app/frontend/src/app/acknowledgements/page.tsx new file mode 100644 index 0000000..46ff212 --- /dev/null +++ b/apps/app/frontend/src/app/acknowledgements/page.tsx @@ -0,0 +1,27 @@ +import type { Metadata } from "next"; +import { AppShell } from "@/components/AppShell"; +import { requireModule } from "@/lib/module"; +import { backendGet } from "@/lib/prayerServer"; + +export const metadata: Metadata = { title: "Acknowledgements" }; + +type Translation = { id: string; name: string; acknowledgement: string; disclaimer: string | null }; + +/** Each quoted Bible translation's full notice, in its publisher's own words (APP-1.0-PLAN §6, contracts 1.22.0). */ +export default async function Acknowledgements() { + await requireModule("devotionals"); + const data = await backendGet<{ translations: Translation[] }>("/api/v1/devotionals/acknowledgements"); + return ( + +

Acknowledgements

+

The Bible translations the App's devotionals quote.

+ {(data?.translations ?? []).map((t) => ( +
+

{t.name} ({t.id})

+

{t.acknowledgement}

+ {t.disclaimer &&

{t.disclaimer}

} +
+ ))} +
+ ); +} diff --git a/apps/app/frontend/src/app/admin/announcements/page.tsx b/apps/app/frontend/src/app/admin/announcements/page.tsx new file mode 100644 index 0000000..09590e1 --- /dev/null +++ b/apps/app/frontend/src/app/admin/announcements/page.tsx @@ -0,0 +1,20 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { AdminAnnouncements } from "@/components/admin/AdminAnnouncements"; +import { requireAdmin } from "@/lib/admin"; + +export const metadata: Metadata = { title: "Announcements · Admin", robots: { index: false, follow: false } }; + +/** Announcements in the admin (APP-1.0-PLAN §5, §10): Content admins, Owner and Church admin. */ +export default async function AdminAnnouncementsPage() { + const { app } = await requireAdmin(["content_admin"], "announcements"); + return ( +
+
+ ← Dashboard +

Announcements

+
+ ({ slug: c.slug, name: c.name }))} /> +
+ ); +} diff --git a/apps/app/frontend/src/app/admin/devotionals/page.tsx b/apps/app/frontend/src/app/admin/devotionals/page.tsx new file mode 100644 index 0000000..fc469ba --- /dev/null +++ b/apps/app/frontend/src/app/admin/devotionals/page.tsx @@ -0,0 +1,20 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { AdminDevotionals } from "@/components/admin/AdminDevotionals"; +import { churchToday, requireAdmin } from "@/lib/admin"; + +export const metadata: Metadata = { title: "Devotionals · Admin", robots: { index: false, follow: false } }; + +/** Devotionals in the admin (APP-1.0-PLAN §6, §10): Devotional writers, Owner and Church admin. */ +export default async function AdminDevotionalsPage() { + const { app } = await requireAdmin(["devotional_writer"], "devotionals"); + return ( +
+
+ ← Dashboard +

Devotionals

+
+ +
+ ); +} diff --git a/apps/app/frontend/src/app/admin/events/page.tsx b/apps/app/frontend/src/app/admin/events/page.tsx new file mode 100644 index 0000000..b176092 --- /dev/null +++ b/apps/app/frontend/src/app/admin/events/page.tsx @@ -0,0 +1,20 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { AdminEvents } from "@/components/admin/AdminEvents"; +import { churchToday, requireAdmin } from "@/lib/admin"; + +export const metadata: Metadata = { title: "Events · Admin", robots: { index: false, follow: false } }; + +/** Events in the admin (APP-1.0-PLAN §7, §10): Content admins, Owner and Church admin. */ +export default async function AdminEventsPage() { + const { app } = await requireAdmin(["content_admin"], "events"); + return ( +
+
+ ← Dashboard +

Events

+
+ +
+ ); +} diff --git a/apps/app/frontend/src/app/admin/page.tsx b/apps/app/frontend/src/app/admin/page.tsx index f0a427a..8ea4783 100644 --- a/apps/app/frontend/src/app/admin/page.tsx +++ b/apps/app/frontend/src/app/admin/page.tsx @@ -101,6 +101,11 @@ export default async function Admin() { House of Prayer: the week, who prays when, rules, campaigns, testimonies› )} + {([["announcements", "/admin/announcements", "Announcements", ["content_admin"]], ["events", "/admin/events", "Events and Linked products", ["content_admin"]], ["devotionals", "/admin/devotionals", "Devotionals: Cross Code's or our own, the CSV import", ["devotional_writer"]]] as const).map(([module, href, label, roles]) => + o?.modules.includes(module) && me.activeRoles.some((r) => ["owner", "church_admin", ...roles].includes(r)) ? ( + {label}› + ) : null, + )} {o?.modules.includes("prayer-requests") && me.activeRoles.some((r) => ["owner", "church_admin", "prayer_coordinator", "pastoral_care"].includes(r)) && ( Prayer requests: approval, escalations, replies, settings› diff --git a/apps/app/frontend/src/app/announcements/[slug]/page.tsx b/apps/app/frontend/src/app/announcements/[slug]/page.tsx new file mode 100644 index 0000000..b74fb53 --- /dev/null +++ b/apps/app/frontend/src/app/announcements/[slug]/page.tsx @@ -0,0 +1,60 @@ +import type { Metadata } from "next"; +import { notFound } from "next/navigation"; +import { ExternalLink } from "lucide-react"; +import { AppShell } from "@/components/AppShell"; +import { Markdown } from "@/components/Markdown"; +import { AnnouncementJsonLd } from "@/components/content/Article"; +import { SignInFor } from "@/components/content/SignInFor"; +import { plain, type Announcement } from "@/lib/content"; +import { loadOne } from "@/lib/contentServer"; +import { loadApp } from "@/lib/load"; +import { requireModule } from "@/lib/module"; +import { truncate } from "@/lib/text"; + +type Props = { params: Promise<{ slug: string }> }; +const load = async (slug: string) => (/^[a-z0-9-]{1,80}$/.test(slug) ? loadOne(`/api/v1/announcements/${slug}`, "announcement") : null); + +export async function generateMetadata({ params }: Props): Promise { + const a = await load((await params).slug); + if (!a || a === "signin") return { title: "Announcement", robots: { index: false, follow: false } }; + return { + title: a.title, + description: truncate(plain(a.body), 155), + ...(a.membersOnly ? { robots: { index: false, follow: false } } : { alternates: { canonical: `/announcements/${a.slug}` }, openGraph: { title: a.title, ...(a.imageUrl ? { images: [a.imageUrl] } : {}) } }), + }; +} + +/** One announcement (APP-1.0-PLAN §5): public ones are pages of their own; members-only ones ask for a sign-in. */ +export default async function AnnouncementPage({ params }: Props) { + await requireModule("announcements"); + const { slug } = await params; + const [a, app] = await Promise.all([load(slug), loadApp()]); + if (!a) notFound(); + if (a === "signin") { + return ( + +

Announcement

+ +
+ ); + } + const published = new Intl.DateTimeFormat("en-ZA", { timeZone: app.timezone, day: "numeric", month: "long", year: "numeric" }).format(new Date(a.publishedAt)); + return ( + +
+ {a.imageUrl && } +
+

{a.title}

+

{published}{a.membersOnly ? " · for members" : ""}

+
+ {a.body} + {a.button && ( + + {a.button.label} + + )} +
+ +
+ ); +} diff --git a/apps/app/frontend/src/app/announcements/page.tsx b/apps/app/frontend/src/app/announcements/page.tsx new file mode 100644 index 0000000..041bd70 --- /dev/null +++ b/apps/app/frontend/src/app/announcements/page.tsx @@ -0,0 +1,27 @@ +import type { Metadata } from "next"; +import { AppShell } from "@/components/AppShell"; +import { AnnouncementCard } from "@/components/content/Cards"; +import { loadAnnouncements } from "@/lib/contentServer"; +import { loadApp } from "@/lib/load"; +import { requireModule } from "@/lib/module"; + +export async function generateMetadata(): Promise { + const app = await loadApp(); + return { title: "Announcements", description: `News from ${app.church?.name ?? "the church"}.` }; +} + +/** Announcements (APP-1.0-PLAN §5): pinned first, then the newest. Members see the members-only ones too. */ +export default async function Announcements() { + await requireModule("announcements"); + const list = await loadAnnouncements(); + return ( + +

Announcements

+ {list.length ? ( +
{list.map((a) => )}
+ ) : ( +

No announcements right now.

+ )} +
+ ); +} diff --git a/apps/app/frontend/src/app/devotional/[date]/page.tsx b/apps/app/frontend/src/app/devotional/[date]/page.tsx new file mode 100644 index 0000000..001d00b --- /dev/null +++ b/apps/app/frontend/src/app/devotional/[date]/page.tsx @@ -0,0 +1,43 @@ +import type { Metadata } from "next"; +import { notFound } from "next/navigation"; +import { AppShell } from "@/components/AppShell"; +import { DevotionalJsonLd } from "@/components/content/Article"; +import { DevotionalView } from "@/components/content/DevotionalView"; +import { SignInFor } from "@/components/content/SignInFor"; +import { plain, type Devotional } from "@/lib/content"; +import { loadOne } from "@/lib/contentServer"; +import { loadApp } from "@/lib/load"; +import { requireModule } from "@/lib/module"; +import { truncate } from "@/lib/text"; + +type Props = { params: Promise<{ date: string }> }; +const load = async (date: string) => (/^\d{4}-\d{2}-\d{2}$/.test(date) ? loadOne(`/api/v1/devotionals/${date}`, "devotional") : null); + +export async function generateMetadata({ params }: Props): Promise { + const d = await load((await params).date); + if (!d || d === "signin") return { title: "Devotional", robots: { index: false, follow: false } }; + return { title: d.title, description: truncate(`${d.passage.reference}: ${plain(d.body)}`, 155), ...(d.membersOnly ? { robots: { index: false, follow: false } } : { alternates: { canonical: `/devotional/${d.date}` } }) }; +} + +/** One day's devotional (APP-1.0-PLAN §6), from the archive or the link in its email or WhatsApp. */ +export default async function DevotionalOn({ params }: Props) { + await requireModule("devotionals"); + const { date } = await params; + const [d, app] = await Promise.all([load(date), loadApp()]); + if (!d) notFound(); + return ( + + {d === "signin" ? ( + <> +

Devotional

+ + + ) : ( + <> + + + + )} +
+ ); +} diff --git a/apps/app/frontend/src/app/devotional/archive/page.tsx b/apps/app/frontend/src/app/devotional/archive/page.tsx new file mode 100644 index 0000000..019066d --- /dev/null +++ b/apps/app/frontend/src/app/devotional/archive/page.tsx @@ -0,0 +1,54 @@ +import type { Metadata } from "next"; +import Link from "next/link"; +import { AppShell } from "@/components/AppShell"; +import { loadApp } from "@/lib/load"; +import { requireModule } from "@/lib/module"; +import { dayName } from "@/lib/prayer"; +import { backendGet } from "@/lib/prayerServer"; + +export const metadata: Metadata = { title: "Devotionals: the archive" }; + +type Day = { date: string; title: string; reference: string; membersOnly: boolean }; + +const shift = (month: string, n: number) => { + const [y, m] = month.split("-").map(Number); + const d = new Date(Date.UTC(y!, m! - 1 + n, 1)); + return `${d.getUTCFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, "0")}`; +}; + +/** The archive by month (APP-1.0-PLAN §6), with today's always first. */ +export default async function Archive({ searchParams }: { searchParams: Promise<{ month?: string }> }) { + await requireModule("devotionals"); + const app = await loadApp(); + const thisMonth = new Intl.DateTimeFormat("en-CA", { timeZone: app.timezone, year: "numeric", month: "2-digit" }).format(new Date()).slice(0, 7); + const q = (await searchParams).month; + const month = q && /^\d{4}-(0[1-9]|1[0-2])$/.test(q) && q <= thisMonth ? q : thisMonth; + const data = await backendGet<{ days: Day[] }>(`/api/v1/devotionals?month=${month}`); + const label = new Intl.DateTimeFormat("en-ZA", { month: "long", year: "numeric", timeZone: "UTC" }).format(new Date(`${month}-15T12:00:00Z`)); + return ( + +

Devotionals

+ Today's devotional + + {data?.days.length ? ( +
    + {data.days.map((d) => ( +
  • + + {dayName(d.date, { weekday: "short", day: "numeric", month: "short" })}{d.membersOnly ? " · members" : ""} + {d.title} + {d.reference} + +
  • + ))} +
+ ) : ( +

No devotionals this month.

+ )} +
+ ); +} diff --git a/apps/app/frontend/src/app/devotional/page.tsx b/apps/app/frontend/src/app/devotional/page.tsx index ebbd041..edb708d 100644 --- a/apps/app/frontend/src/app/devotional/page.tsx +++ b/apps/app/frontend/src/app/devotional/page.tsx @@ -1,17 +1,38 @@ import type { Metadata } from "next"; +import Link from "next/link"; import { AppShell } from "@/components/AppShell"; -import { ComingSoon } from "@/components/ComingSoon"; +import { DevotionalJsonLd } from "@/components/content/Article"; +import { DevotionalView } from "@/components/content/DevotionalView"; +import { plain } from "@/lib/content"; +import { loadToday } from "@/lib/contentServer"; +import { loadApp } from "@/lib/load"; import { requireModule } from "@/lib/module"; +import { truncate } from "@/lib/text"; -export const metadata: Metadata = { title: "Devotional" }; +export async function generateMetadata(): Promise { + const d = await loadToday(); + if (!d) return { title: "Devotional" }; + return { title: d.title, description: truncate(`${d.passage.reference}: ${plain(d.body)}`, 155), ...(d.membersOnly ? { robots: { index: false, follow: false } } : { alternates: { canonical: `/devotional/${d.date}` } }) }; +} -/** Today's devotional and the archive (APP-1.0-PLAN §6). */ +/** Today's devotional (APP-1.0-PLAN §6): from midnight in the church's timezone; the most recent when today has none. */ export default async function Devotional() { await requireModule("devotionals"); + const [d, app] = await Promise.all([loadToday(), loadApp()]); return ( -

Devotional

- Today's Bible passage and devotional will show here, with Read in YouVersion. + {d ? ( + <> + {!d.today &&

There's no devotional for today yet. Here's the latest one.

} + + + + ) : ( + <> +

Devotional

+

There are no devotionals yet. They'll show here each morning.

Back home
+ + )}
); } diff --git a/apps/app/frontend/src/app/events/[key]/page.tsx b/apps/app/frontend/src/app/events/[key]/page.tsx new file mode 100644 index 0000000..66a0693 --- /dev/null +++ b/apps/app/frontend/src/app/events/[key]/page.tsx @@ -0,0 +1,53 @@ +import type { Metadata } from "next"; +import { notFound } from "next/navigation"; +import { MapPin } from "lucide-react"; +import { eventJsonLd, jsonLdString } from "@crosscode/seo"; +import { AppShell } from "@/components/AppShell"; +import { RegisterButton } from "@/components/content/Cards"; +import { eventWhen, type EventItem } from "@/lib/content"; +import { loadOne } from "@/lib/contentServer"; +import { loadApp } from "@/lib/load"; +import { requireModule } from "@/lib/module"; +import { truncate } from "@/lib/text"; + +type Props = { params: Promise<{ key: string }> }; +const load = async (key: string) => (/^[a-z0-9-]{1,120}$/.test(key) ? loadOne(`/api/v1/events/${key}`, "event") : null); + +export async function generateMetadata({ params }: Props): Promise { + const e = await load((await params).key); + if (!e || e === "signin") return { title: "Event" }; + return { + title: e.title, + description: truncate(e.summary ?? e.description ?? eventWhen(e), 155), + // An imported event points search engines at its origin (§7): one event, not one per product. + alternates: { canonical: e.canonical ?? `/events/${e.key}` }, + ...(e.imageUrl ? { openGraph: { title: e.title, images: [e.imageUrl] } } : {}), + }; +} + +/** One event (APP-1.0-PLAN §7): Cross Events' show "Register on the Events site"; registering and paying stay there. */ +export default async function EventPage({ params }: Props) { + await requireModule("events"); + const [e, app] = await Promise.all([load((await params).key), loadApp()]); + if (!e || e === "signin") notFound(); + return ( + +
+ {e.imageUrl && } +
+

{e.title}

+ {e.cancelled &&

This event is cancelled.

} +

{eventWhen(e)}

+ {e.location &&

{e.location}

} +
+ + {e.description &&

{e.description}

} + {e.source !== "app" &&

From the church's {e.source === "events" ? "Events site" : "website"}.

} +
+ {/* Only the origin's page carries the Event JSON-LD (packages/seo). */} + {e.crosscode && app.church && ( + " })).not.toContain(""); }); }); + +describe("articleJsonLd", () => { + const base = { url: "https://app.acaciahill.test/devotional/2026-12-01", headline: "Abide", datePublished: "2026-12-01", publisher: { name: "Acacia Hill", url: "https://acaciahill.test", logoUrl: "https://acaciahill.test/logo.svg" } }; + + it("names the article, its page, its author and the church", () => { + const ld = articleJsonLd({ ...base, author: "Pastor Sam", about: "John 15:1-5", description: "Abide in me." }); + expect(ld).toMatchObject({ + "@type": "Article", headline: "Abide", url: base.url, mainEntityOfPage: { "@id": base.url }, datePublished: "2026-12-01", dateModified: "2026-12-01", + author: { "@type": "Person", name: "Pastor Sam" }, publisher: { name: "Acacia Hill", logo: { url: "https://acaciahill.test/logo.svg" } }, + about: { name: "John 15:1-5" }, description: "Abide in me.", + }); + }); + + it("credits the church when there's no author, and cuts a long headline", () => { + const ld = articleJsonLd({ ...base, headline: "x".repeat(200) }); + expect(ld.author).toEqual(ld.publisher); + expect((ld.headline as string).length).toBe(110); + expect(jsonLdString(ld)).not.toContain("