Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions .github/workflows/cms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: CMS

on:
push:
branches: [main]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

env:
WRANGLER_SEND_METRICS: "false"

jobs:
cms-changes:
runs-on: ubuntu-latest
outputs:
cms: ${{ steps.filter.outputs.cms }}
posts: ${{ steps.filter.outputs.posts }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Detect CMS and post changes
id: filter
env:
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
run: |
if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ] || ! git cat-file -e "$BASE^{commit}" 2>/dev/null; then
echo "cms=true" >> "$GITHUB_OUTPUT"
echo "posts=true" >> "$GITHUB_OUTPUT"
exit 0
fi
changed="$(git diff --name-only "$BASE" "$GITHUB_SHA")"
if grep -qE '^(cms/|\.github/workflows/cms\.yml$)' <<<"$changed"; then
echo "cms=true" >> "$GITHUB_OUTPUT"
else
echo "cms=false" >> "$GITHUB_OUTPUT"
fi
if grep -qE '^src/content/posts/' <<<"$changed"; then
echo "posts=true" >> "$GITHUB_OUTPUT"
else
echo "posts=false" >> "$GITHUB_OUTPUT"
fi

cms-test:
needs: cms-changes
if: ${{ !cancelled() && (needs.cms-changes.result != 'success' || needs.cms-changes.outputs.cms == 'true') }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: cms
steps:
- uses: actions/checkout@v7

- name: Install tools from mise.toml (Node.js, Bun)
uses: jdx/mise-action@v5

- name: Check cms/.nvmrc matches mise.toml
run: test "v$(cat .nvmrc)" = "$(node --version)" || { echo "cms/.nvmrc ($(cat .nvmrc)) differs from mise.toml node ($(node --version)); Cloudflare Pages reads cms/.nvmrc"; exit 1; }

- name: Install CMS test dependencies
run: bun install --frozen-lockfile

- name: Check formatting
run: bun run format:check

- name: Unit tests
run: bun run test:unit

- name: Install Playwright browsers
run: bunx playwright install --with-deps chromium

- name: Integration tests (static admin served locally)
run: bun run test:integration

- name: E2E smoke (loads Sveltia from the CDN)
run: bun run test:e2e

- name: Upload test results
uses: actions/upload-artifact@v7
if: failure()
with:
name: cms-playwright-results
path: cms/test-results/
retention-days: 7

cms-compat:
needs: cms-changes
if: ${{ !cancelled() && (needs.cms-changes.result != 'success' || needs.cms-changes.outputs.cms == 'true') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- name: Install tools from mise.toml (Node.js, Bun)
uses: jdx/mise-action@v5

- name: Install blog dependencies
run: bun install --frozen-lockfile

- name: Build the blog with the CMS fixture and golden posts
run: bash cms/scripts/compat-check.sh

content-guard:
needs: cms-changes
if: ${{ !cancelled() && (needs.cms-changes.result != 'success' || needs.cms-changes.outputs.posts == 'true') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Install tools from mise.toml (Node.js, Bun)
uses: jdx/mise-action@v5

- name: Install blog dependencies
run: bun install --frozen-lockfile

- name: Build the blog (schema check of every post)
run: bun run build

- name: Check posts for CMS serializer damage
env:
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
run: bash cms/scripts/content-guard.sh "$BASE"
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## 2026-11-15 08:43

| Check | Status | Details |
|-------|--------|---------|
| Lint | ✓ PASS | 0 errors |
| Build | ✓ PASS | 27 pages built, 5 pages indexed (Pagefind) |
| Unit Tests | ✓ PASS | 75 tests passed |
| E2E Tests | ✓ PASS | 96 tests passed |
| Lighthouse | ✓ PASS | 99.7% performance (avg) |

### Lighthouse Performance (local build)

| Page | Scores (3 runs) |
|------|-----------------|
| / (index) | 100%, 100%, 100% |
| /about | 99%, 99%, 99% |
| /posts | 100%, 100%, 99% |
| /archives (soft 404, not linked) | 100%, 100%, 100% |
| /404 | 100%, 100%, 100% |

**Diagnostics:** None for the blog. Live site not measured (Turnstile gate). CMS checks in `cms/`: format clean, 17 unit, 2 integration, 1 e2e smoke, compat-check passed (run locally with `CMS_PORT=8789` because another local service holds 8787).

Changes: Add the Sveltia CMS admin in `cms/` (pinned 0.266.0 with SRI, editorial workflow, date-only dates, empty optional fields omitted), its unit, integration, e2e and compat tests, the content guard, and the `CMS` workflow (`cms-changes`, `cms-test`, `cms-compat`, `content-guard`).

## 2026-11-15 07:58

| Check | Status | Details |
Expand Down
8 changes: 8 additions & 0 deletions cms/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
dist/
.astro/
.wrangler/
.env*
.dev.vars
test-results/
playwright-report/
1 change: 1 addition & 0 deletions cms/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26.13.0
5 changes: 5 additions & 0 deletions cms/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
test-results/
playwright-report/
bun.lock
test/fixtures/
10 changes: 10 additions & 0 deletions cms/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"arrowParens": "avoid",
"semi": true,
"tabWidth": 2,
"printWidth": 80,
"singleQuote": false,
"trailingComma": "es5",
"bracketSpacing": true,
"endOfLine": "lf"
}
29 changes: 29 additions & 0 deletions cms/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Parent: ../AGENTS.md -->

# cms

## Purpose

Owner-only post editor: Sveltia CMS as a static admin page, deployed by the Cloudflare Pages project `blog-cms` (root directory `cms`, no build command, output `public`) to `cms.blog.kulkarni.cloud`, behind Cloudflare Access. Own `package.json` and `bun.lock` (test tooling only, no workspaces) and own CI (`.github/workflows/cms.yml`). The blog never builds or lints this directory (`tsconfig.json` exclude, `eslint.config.js` ignore).

## Key Files

| File | Description |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `public/admin/index.html` | Loads `@sveltia/cms` at an exact version from unpkg with `integrity` (sha384) and `crossorigin`; `noindex` |
| `public/admin/config.yml` | GitHub backend `comdotlinux/blog`, branch `main`, `publish_mode: editorial_workflow` (branch `cms/posts/<slug>` plus a PR per post); `output.omit_empty_optional_fields: true`; collection `posts` in `src/content/posts`, date-only `pubDatetime`/`modDatetime`, `draft` default false, raw Markdown body first |
| `package.json` | Scripts `serve`, `format:check`, `test:unit`, `test:integration`, `test:e2e`, `test:compat`; exact pins |
| `vitest.config.ts` | Unit tests in `test/unit/` |
| `playwright.config.ts` | Projects `integration` (HTTP only) and `e2e` (Chromium, 1 retry for the CDN); web server `python3 -m http.server` on `CMS_PORT` (default 8787) |
| `scripts/compat-check.sh` | Copies `test/fixtures/compat-post.md` and the golden new entry into `../src/content/posts/zz-cms-compat-*.md`, builds the blog, greps the HTML (table, `hello.ts` label, callout div, image, no `{%`), then moves the two files to `../.trash/` |
| `scripts/content-guard.sh` | Run by the `content-guard` CI job on post changes: no `{%` in posts, removed `file=` fence lines must be re-added, changed posts need `title`, `description`, `pubDatetime` and no empty-string values |
| `test/fixtures/` | Spike 1 fixture and the files Sveltia wrote in Spike 1 (`golden/`) |

## For AI Agents

- Keep `config.yml` field names a subset of the blog's `posts` schema keys (`src/content.config.ts`); `test/unit/config.test.ts` enforces it.
- Never remove `omit_empty_optional_fields`: without it Sveltia writes `modDatetime: ''`, which fails the blog build.
- Upgrading Sveltia means a new version and a new sha384 in `index.html` (see `README.md`), then all tests.
- Do not add a build step or runtime secrets. Pages runs with `SKIP_DEPENDENCY_INSTALL=1`.
- Branch prefix is Sveltia's `cms/posts/`. Post PRs are merged or closed on GitHub, never with Sveltia's Publish or Discard (both delete branches).
- `wrangler` installed anywhere under a checkout that has a stale `.wrangler/deploy/config.json` refuses `pages dev`; the tests here use `python3 -m http.server` instead.
45 changes: 45 additions & 0 deletions cms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Blog CMS

An owner-only web editor for the blog's posts, built on [Sveltia CMS](https://sveltiacms.app/). It is a static admin page (`public/admin/`) served by the Cloudflare Pages project `blog-cms` at `https://cms.blog.kulkarni.cloud/admin/`, behind Cloudflare Access. There is no build step and no server code; Sveltia talks to GitHub from the browser with a fine-grained personal access token.

## Writing a post

1. Open `https://cms.blog.kulkarni.cloud/admin/`, pass Cloudflare Access, then "Sign In Using Access Token" with your PAT (Contents read and write, Metadata read, this repository only).
2. Create or edit a post under Posts and save. Sveltia commits it to its own branch `cms/posts/<slug>` and opens a pull request against `main`. Nothing reaches `main` until that pull request is merged.
3. Check the blog's Cloudflare Pages preview for the branch (alias `cms-posts-<slug>.blog-7qk.pages.dev`) and the CI checks on the pull request.
4. **Merge or close the pull request on GitHub.** Never use Sveltia's **Publish** or **Discard**: Publish merges and then deletes the branch, Discard closes the pull request and deletes the unmerged branch. Log every merged or closed branch in `.trash/MOVED.md` (name, PR number, head SHA) as restorable from its PR.

Field notes:

- `pubDatetime` and `modDatetime` are dates only (`2026-11-15`), written unquoted. Existing posts keep their full timestamps unless you edit the field.
- `draft` defaults to `false`; the branch is the draft.
- `ogImage`, `canonicalURL`, `hideEditPost`, `hideToc` and `timezone` are not in the form; add them by hand if needed.
- Images: upload by hand to `public/assets/YYYYMMDD/` and link `/assets/YYYYMMDD/<file>`.
- The body editor opens in raw Markdown. Keep it there for tables, `file="..."` code labels and `> [!NOTE]` callouts.

## Local development

Everything runs from this directory with the versions in the repository's `mise.toml`.

```sh
bun install --frozen-lockfile
bun run format:check
bun run test:unit # config.yml against the blog schema, golden outputs, admin page pins
bun run test:integration # serves public/ with python3 http.server, checks /admin/ and /admin/config.yml
bun run test:e2e # loads the admin page in Chromium; needs network for the Sveltia CDN
bun run test:compat # builds the blog with test/fixtures and greps the rendered HTML
```

The local server listens on port 8787; set `CMS_PORT` to use another port. `test:compat` needs the blog's dependencies installed at the repository root; it moves the posts it added to `../.trash/<timestamp>-cms-compat/` afterwards.

To try the editor against your working copy, serve `public/` (`bun run serve`), open `http://127.0.0.1:8787/admin/` in a Chromium-based browser and choose "Work with Local Repository" with the repository root.

## Upgrading Sveltia

`public/admin/index.html` pins an exact version from unpkg with a `sha384` integrity hash. To upgrade, change the version and replace the hash with the output of:

```sh
curl -sL https://unpkg.com/@sveltia/cms@<version>/dist/sveltia-cms.js | openssl dgst -sha384 -binary | base64
```

Then run all tests above.
Loading
Loading