Content Management System (CMS)
Relevant source files
The following files were used as context for generating this wiki page:
The Content Management System (CMS) within this project provides a structured framework for managing site content dynamically. It utilizes a Cloudflare D1 database backend to store "content blocks" which can be edited, versioned, and published via a dedicated admin interface. The system supports a draft-to-publish workflow, ensuring that changes can be previewed or revised before going live.
The CMS is primarily designed to manage Markdown-based text content and associated assets (like URLs) for various site sections. It includes specialized implementations for general page content and specific features like the "Campaign Spotlight."
Sources: src/app/admin/cms/page.tsx:88-90, migrations/0011_cms_content_blocks.sql:1-4, context.md:14-15
Data Architecture
The CMS relies on two primary tables within the D1 database: content_blocks and content_revisions. These tables manage the current state and the historical progression of content.
Database Schema
The schema defines strict constraints for content keys and statuses, ensuring data integrity across the system.
| Field | Type | Constraints | Description |
|---|---|---|---|
key | TEXT | PRIMARY KEY | Unique identifier for a specific content block. |
page | TEXT | NOT NULL | The page where the content is rendered. |
section | TEXT | NOT NULL | The specific section within the page. |
title | TEXT | NOT NULL | Descriptive title for the block. |
body_md | TEXT | NOT NULL | The current content (stored as raw Markdown). |
status | TEXT | CHECK ('draft', 'published') | Workflow state of the block. |
published_body_md | TEXT | NULL | Snapshot of the body when last published. |
version | INTEGER | DEFAULT 1 | Incremental version counter. |
updated_at | TEXT | NOT NULL | Timestamp of the last modification. |
published_at | TEXT | NULL | Timestamp of the last successful publication. |
updated_by | TEXT | DEFAULT 'admin' | Identifier for the user who made the change. |
Sources: migrations/0011_cms_content_blocks.sql:8-20
Relationship Diagram
The following diagram illustrates the relationship between current content blocks and their historical revisions.
Note: Revisions are created every time a block is saved as a draft or published.
Sources: migrations/0011_cms_content_blocks.sql:8-33
Admin Interface and Workflow
The CMS provides a web-based editor located at /admin/cms and /admin/content. These interfaces allow administrators to fetch, edit, and manage the lifecycle of content blocks.
Content Lifecycle Flow
The system enforces a specific flow where content is first saved as a draft before it can be moved to a published state.
Key Admin Functions
- List/Load: Fetches blocks, optionally filtered by page slug. It also aggregates a list of available pages for navigation.
- Endpoint:
GET /api/admin/cms/list - Sources: functions/api/admin/cms/list.ts:21-48
- Endpoint:
- Save Draft: Upserts a record in
content_blocks. It sets the status to'draft', increments the version, and adds an entry tocontent_revisions.- Endpoint:
POST /api/admin/cms/save - Sources: functions/api/admin/cms/save.ts:38-76
- Endpoint:
- Publish: Finalizes content by copying the current
body_mdtopublished_body_md. It updates thepublished_attimestamp and adds a publication revision.- Endpoint:
POST /api/admin/cms/publish - Sources: functions/api/admin/cms/publish.ts:35-59
- Endpoint:
Feature-Specific CMS Modules
Beyond general blocks, the CMS includes specialized logic for complex UI components.
Campaign Spotlight Editor
A dedicated editor (/admin/fundraiser-preview) manages the homepage campaign spotlight. Unlike simple text blocks, this uses a serialized JSON object within the body_md field to store complex configuration like goal amounts, raised amounts, and CTA links.
| Logic Step | File Reference | Action |
|---|---|---|
| Validation | src/app/admin/fundraiser-preview/page.tsx:75-76 | Checks for required fields and logical consistency before saving. |
| Serialization | src/app/admin/fundraiser-preview/page.tsx:103 | Converts form state into a Markdown-compatible string for storage. |
| Preview | src/app/admin/fundraiser-preview/page.tsx:220-221 | Renders a CampaignSpotlightCard component locally for visual verification. |
Sources: src/app/admin/fundraiser-preview/page.tsx:1-236
Section Bundling
The interface at /admin/content utilizes a SectionBundle structure, which pairs a live block with its corresponding draft block to allow administrators to compare differences before publishing.
Sources: src/app/admin/content/page.tsx:28-32
API Endpoints Summary
The CMS functionality is exposed via protected API routes requiring an x-admin-token.
| Method | Endpoint | Description |
|---|---|---|
GET | /api/admin/cms/list | Returns all blocks or blocks for a specific page. |
POST | /api/admin/cms/save | Upserts content and sets status to draft. |
POST | /api/admin/cms/publish | Makes draft content live by updating published_body_md. |
GET | /api/admin/content | Fetches SectionBundle arrays for a specific slug. |
Sources: functions/api/admin/cms/list.ts:21, functions/api/admin/cms/save.ts:11, functions/api/admin/cms/publish.ts:11, src/app/admin/content/page.tsx:50-54
Summary
The CMS is a robust content management layer that bridges the Gap between static site deployment and dynamic content updates. By leveraging Cloudflare D1 and a strict revision-based architecture, it provides safe content iterations. Administrators can manage standard site copy or complex feature configurations (like fundraisers) through specialized editors, ensuring all public-facing content is vetted through the draft-and-publish workflow.