app: announcements, devotionals and events' screens; @crosscode/seo 1.1.0 (APP-1.0-PLAN §5-§7)
Public pages: Home with today's devotional, the latest announcements (pinned first) and what's on; Announcements and each one's page (markdown without HTML, a button, Article JSON-LD; members-only ones ask for a sign-in and are noindex); Devotional (the passage in full with its copyright line, Read in YouVersion, the prayer), each day's page, the archive by month and the Acknowledgements; Events and each one's page (Register on the Events site for Cross Events', a canonical to the origin, Event JSON-LD on the App's own). A sitemap of the public pages, named in robots.txt. Admin: Announcements (schedule, end, pin, campus, who sees it, also send it), Events (simple events, Linked products: publish and show events from), and Devotionals (Cross Code's or our own, Sync now, a month's days, writing, the CSV import with its preview, keep or replace days already filled). @crosscode/seo 1.1.0: articleJsonLd. The backend gives the App's own address and the sitemap's list, and a simple event's crosscode.event/1 for its page. Checked in a browser on a throwaway PostgreSQL: the pages for a visitor, the JSON-LD, a members-only announcement asking for a sign-in, the sitemap, a Content admin publishing an announcement and a Devotional writer saving one; no page errors. 94 backend tests, 19 seo tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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 `<link rel="canonical">` (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<EventItem | nul
|
||||
return copy ? fromImported(copy) : null;
|
||||
}
|
||||
const e = await ctx.db.simpleEvent.findUnique({ where: { slug: key } });
|
||||
return e && e.publishedAt && e.publishedAt <= ctx.now() ? fromSimple(e) : null;
|
||||
if (!e || !e.publishedAt || e.publishedAt > 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 ──
|
||||
|
||||
@@ -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<Church, 'name' | 'shortName'> | null): string {
|
||||
@@ -44,5 +46,6 @@ export async function appInfo(ctx: Ctx): Promise<AppInfo> {
|
||||
},
|
||||
modules,
|
||||
timezone: church?.timezone ?? ctx.config.timezone,
|
||||
url: ctx.config.publicUrl,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user