# Decap CMS Configuration

## Files

| File | Purpose |
| --- | --- |
| `public/admin/index.html` | **Staff workspace** (`/admin/`): a static task dashboard. Each card deep-links into the editor (for example `/admin/edit/#/collections/events/entries/event_list`). Includes a publishing explainer and a help section. No Decap code loads here. |
| `public/admin/workspace.css` | Styles for the workspace and the editor loading screen |
| `public/admin/workspace.js` | Redirects old Decap bookmarks (`/admin/#/…`) to `/admin/edit/#/…` |
| `public/admin/edit/index.html` | **Editor** (`/admin/edit/`): points Decap at `/admin/config.yml` via `<link rel="cms-config-url">`, shows a loading screen, and mounts Decap into `#nc-root` |
| `public/admin/editor-loader.js` | Injects Decap from unpkg, **pinned to `decap-cms@3.8.4`**. Hides the loading screen once Decap renders. After 20 s shows a slow-connection message, or an error message if the script fails to load. |
| `public/admin/config.yml` | Backend, media folders, and collections |

All admin pages are `noindex, nofollow`, and robots disallows `/admin`.

<p class="callout info">To upgrade Decap, change the pinned version in <code>editor-loader.js</code>, then test sign-in and every collection locally (<code>npx decap-server</code>) before deploying. An unpkg outage affects only the editor, never the public site.</p>

<p class="callout warning">The workspace cards hard-code collection and file <code>name</code>s in their URLs. If you rename a collection or file entry in <code>config.yml</code>, update the matching card link in <code>index.html</code>.</p>

## Backend and authentication

```yaml
backend:
  name: github
  repo: pmgasset/fortadamswebsite
  branch: main
  base_url: https://decap-oauth.fortadams.org   # OAuth proxy
local_backend: true
site_url: https://www.fortadams.org
```

- There's **no `publish_mode: editorial_workflow`**, so every Publish commits straight to `main` and deploys.
- The GitHub backend needs an **OAuth proxy**, because GitHub's OAuth flow requires a client secret. Setup:
  1. Create a **GitHub OAuth App** (org or user Settings → Developer settings → OAuth Apps). Set the callback URL to the proxy's callback endpoint.
  2. Deploy a proxy, for example the Cloudflare Worker [`sterlingwes/decap-proxy`](https://github.com/sterlingwes/decap-proxy) or [`i40west/netlify-cms-oauth`](https://github.com/i40west/netlify-cms-oauth), with `GITHUB_OAUTH_CLIENT_ID` and `GITHUB_OAUTH_CLIENT_SECRET`, on `decap-oauth.fortadams.org`.
  3. Keep `backend.base_url` pointing at it, and confirm the proxy is live before launch.
- Editors need write access to the repo.

## Collections

The header comment in `config.yml` says it: **keep collection, file, and field `name`s stable**, because they map to existing JSON keys and paths. Labels can change freely.

| Collection label (`name`) | File entry label (`name`) | Target | Media folder |
| --- | --- | --- | --- |
| Special Events (`events`) | Add or update events (`event_list`) | `content/events.json` | `public/images/events` |
| | Event Categories (`event_categories`) | `content/event-categories.json` | |
| Alerts & Booking (`settings`) | Update the announcement banner (`alert`) | `content/alert.json` | global: `public/images/staff` |
| | Update tour booking links (`tour_booking`) | `content/tour-booking.json` | |
| Staff & Board (`staff`) | Update staff & board (`directory`) | `content/staff.json` | global: `public/images/staff` |
| Sponsors & Partners (`sponsors`) | Update sponsor recognition (`annual_sponsors`) | `content/sponsors.json` | `public/images/sponsors` |

All collections are **file collections** (one JSON file each, with list widgets) and set `delete: false`, so editors can't delete the underlying files. Global options: `editor.preview: false` (no preview pane), `logo_url` (the Trust logo on the login screen), and `display_url` pointing at `/admin/`. Lists are `collapsed: true`, `required: false`, `default: []`.

Notable field configuration:

- **Alert message:** `pattern: ^.{0,120}$`.
- **Tour URLs:** regex patterns (see *FareHarbor Integration*).
- **Event `isPublished`:** `default: false`, so **new events start hidden** until the editor switches them on.
- **Event list:** `add_to_top: true`, `allow_reorder: false` (the site sorts by date).
- **Event category:** a `relation` widget into `event_categories` (`value_field: categories.*.name`). It stores the **name string**, so renames don't cascade.
- **Event dates:** `datetime`, `format: YYYY-MM-DDTHH:mm:ssZ`, `picker_utc: false`, displayed as `MMM D, YYYY` / `h:mm A`. The stored offset comes from the **editor's device time zone**, hence the "set your device to Eastern Time" hint.
- **Event id:** a `hidden` widget, never set by Decap for new entries. `getPublicEvents()` generates one.
- **Event `externalUrl`:** `^$|^https?://[^\s/?#]+[^\s]*$`. **`bookingUrl`:** `^$|^/(?!/)[^\s]*$` (site paths only, no protocol-relative `//`).
- **Staff `email`:** `^$|^[^\s@]+@[^\s@]+\.[^\s@]+$`.
- **Sponsor `year`:** `^[0-9]{4}$`. **Sponsor `website`:** same pattern as event `externalUrl`. `add_to_top: true`.

## Adding a CMS-editable field or area

1. Add the field to the JSON file in `content/` with a sensible default, so existing data stays valid.
2. Update the TypeScript interface and loader in `src/lib/`, treating the field as optional for older data.
3. Add the widget to `config.yml`. Mirror the constraints with `pattern`, `required`, and `hint`.
4. Render it in the component.
5. Test locally with `npx decap-server` (see *Local Development Setup*), then `npm run build`.

Keep new areas constrained: validated strings, booleans, lists, and images. Avoid rich-text or HTML fields that let editors break layouts or inject markup.