diff --git a/.github/workflows/cms.yml b/.github/workflows/cms.yml new file mode 100644 index 0000000..1291fe5 --- /dev/null +++ b/.github/workflows/cms.yml @@ -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" diff --git a/CHANGELOG.md b/CHANGELOG.md index 2392cf8..d994b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 | diff --git a/cms/.gitignore b/cms/.gitignore new file mode 100644 index 0000000..1441aab --- /dev/null +++ b/cms/.gitignore @@ -0,0 +1,8 @@ +node_modules/ +dist/ +.astro/ +.wrangler/ +.env* +.dev.vars +test-results/ +playwright-report/ diff --git a/cms/.nvmrc b/cms/.nvmrc new file mode 100644 index 0000000..1dda03d --- /dev/null +++ b/cms/.nvmrc @@ -0,0 +1 @@ +26.13.0 diff --git a/cms/.prettierignore b/cms/.prettierignore new file mode 100644 index 0000000..c51a6b3 --- /dev/null +++ b/cms/.prettierignore @@ -0,0 +1,5 @@ +node_modules/ +test-results/ +playwright-report/ +bun.lock +test/fixtures/ diff --git a/cms/.prettierrc b/cms/.prettierrc new file mode 100644 index 0000000..ba85e2b --- /dev/null +++ b/cms/.prettierrc @@ -0,0 +1,10 @@ +{ + "arrowParens": "avoid", + "semi": true, + "tabWidth": 2, + "printWidth": 80, + "singleQuote": false, + "trailingComma": "es5", + "bracketSpacing": true, + "endOfLine": "lf" +} diff --git a/cms/AGENTS.md b/cms/AGENTS.md new file mode 100644 index 0000000..8000d7e --- /dev/null +++ b/cms/AGENTS.md @@ -0,0 +1,29 @@ + + +# 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/` 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. diff --git a/cms/README.md b/cms/README.md new file mode 100644 index 0000000..89aa6ca --- /dev/null +++ b/cms/README.md @@ -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/` 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-.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/`. +- 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/-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@/dist/sveltia-cms.js | openssl dgst -sha384 -binary | base64 +``` + +Then run all tests above. diff --git a/cms/bun.lock b/cms/bun.lock new file mode 100644 index 0000000..dd0ea53 --- /dev/null +++ b/cms/bun.lock @@ -0,0 +1,160 @@ +{ + "lockfileVersion": 2, + "configVersion": 1, + "workspaces": { + "": { + "name": "blog-cms", + "devDependencies": { + "@playwright/test": "1.65.0", + "prettier": "3.9.10", + "vitest": "5.1.0", + "yaml": "2.9.1", + }, + }, + }, + "packages": { + "@emnapi/core": ["@emnapi/core@2.0.0-beta.2", "", { "dependencies": { "@emnapi/wasi-threads": "2.2.0", "tslib": "^2.4.0" } }, "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A=="], + + "@emnapi/runtime": ["@emnapi/runtime@2.0.0-beta.2", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw=="], + + "@emnapi/wasi-threads": ["@emnapi/wasi-threads@2.2.0", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw=="], + + "@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.3", "", {}, "sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g=="], + + "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.6.0", "", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="], + + "@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="], + + "@napi-rs/wasm-runtime": ["@napi-rs/wasm-runtime@1.2.6", "", { "dependencies": { "@tybys/wasm-util": "^0.10.3" }, "peerDependencies": { "@emnapi/core": "^1.7.1 || 2.0.0-beta.2", "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2" } }, "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw=="], + + "@oxc-project/types": ["@oxc-project/types@0.156.0", "", {}, "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw=="], + + "@playwright/test": ["@playwright/test@1.65.0", "", { "dependencies": { "playwright": "1.65.0" }, "bin": { "playwright": "cli.js" } }, "sha512-iGURLGuKDLakSEl7Pgfv8h7f+XLT+V861Wfhz0zlEl5nyFuKUopdkFBPKqTllTUp06aOwPuH8iuUEb3yp3MpbQ=="], + + "@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.2.19", "", { "os": "android", "cpu": "arm" }, "sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A=="], + + "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.2.19", "", { "os": "android", "cpu": "arm64" }, "sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA=="], + + "@rolldown/binding-darwin-arm64": ["@rolldown/binding-darwin-arm64@1.2.19", "", { "os": "darwin", "cpu": "arm64" }, "sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g=="], + + "@rolldown/binding-darwin-x64": ["@rolldown/binding-darwin-x64@1.2.19", "", { "os": "darwin", "cpu": "x64" }, "sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg=="], + + "@rolldown/binding-freebsd-x64": ["@rolldown/binding-freebsd-x64@1.2.19", "", { "os": "freebsd", "cpu": "x64" }, "sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA=="], + + "@rolldown/binding-linux-arm-gnueabihf": ["@rolldown/binding-linux-arm-gnueabihf@1.2.19", "", { "os": "linux", "cpu": "arm" }, "sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw=="], + + "@rolldown/binding-linux-arm64-gnu": ["@rolldown/binding-linux-arm64-gnu@1.2.19", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA=="], + + "@rolldown/binding-linux-arm64-musl": ["@rolldown/binding-linux-arm64-musl@1.2.19", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg=="], + + "@rolldown/binding-linux-ppc64-gnu": ["@rolldown/binding-linux-ppc64-gnu@1.2.19", "", { "os": "linux", "cpu": "ppc64", "libc": "glibc" }, "sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q=="], + + "@rolldown/binding-linux-s390x-gnu": ["@rolldown/binding-linux-s390x-gnu@1.2.19", "", { "os": "linux", "cpu": "s390x", "libc": "glibc" }, "sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw=="], + + "@rolldown/binding-linux-x64-gnu": ["@rolldown/binding-linux-x64-gnu@1.2.19", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q=="], + + "@rolldown/binding-linux-x64-musl": ["@rolldown/binding-linux-x64-musl@1.2.19", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A=="], + + "@rolldown/binding-openharmony-arm64": ["@rolldown/binding-openharmony-arm64@1.2.19", "", { "os": "none", "cpu": "arm64" }, "sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA=="], + + "@rolldown/binding-wasm32-wasi": ["@rolldown/binding-wasm32-wasi@1.2.19", "", { "dependencies": { "@emnapi/core": "2.0.0-beta.2", "@emnapi/runtime": "2.0.0-beta.2", "@napi-rs/wasm-runtime": "1.2.6" }, "cpu": "none" }, "sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg=="], + + "@rolldown/binding-win32-arm64-msvc": ["@rolldown/binding-win32-arm64-msvc@1.2.19", "", { "os": "win32", "cpu": "arm64" }, "sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ=="], + + "@rolldown/binding-win32-x64-msvc": ["@rolldown/binding-win32-x64-msvc@1.2.19", "", { "os": "win32", "cpu": "x64" }, "sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag=="], + + "@rolldown/pluginutils": ["@rolldown/pluginutils@1.1.1", "", {}, "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA=="], + + "@tybys/wasm-util": ["@tybys/wasm-util@0.10.4", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A=="], + + "@types/chai": ["@types/chai@5.2.3", "", { "dependencies": { "@types/deep-eql": "*", "assertion-error": "^2.0.1" } }, "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA=="], + + "@types/deep-eql": ["@types/deep-eql@4.0.2", "", {}, "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw=="], + + "@types/estree": ["@types/estree@1.0.10", "", {}, "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g=="], + + "@vitest/mocker": ["@vitest/mocker@5.1.0", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.31", "@vitest/spy": "5.1.0", "estree-walker": "^3.0.3", "magic-string": "^1.4.3" }, "peerDependencies": { "msw": "^2.4.9 || ^3.0.0", "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" }, "optionalPeers": ["msw", "vite"] }, "sha512-5umB9/jlWcqVS6fsrFmv5Gdnpu6wAUio/lEOwAmvB7v+lFo/IW2B9FhAD0p19GCULTgMzLCdUmuCDCnAzWgppQ=="], + + "@vitest/spy": ["@vitest/spy@5.1.0", "", {}, "sha512-2DPO5OMHWKrBngC+fCmTQqemNF0gidRhp3lxbBmRhW+M1XJrfgPpqNqWVevXtn2f2ufD5ZaR1B6B641aAlcX5A=="], + + "assertion-error": ["assertion-error@2.0.1", "", {}, "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA=="], + + "chai": ["chai@6.3.0", "", {}, "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg=="], + + "detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="], + + "es-module-lexer": ["es-module-lexer@2.3.2", "", {}, "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw=="], + + "estree-walker": ["estree-walker@3.0.3", "", { "dependencies": { "@types/estree": "^1.0.0" } }, "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g=="], + + "expect-type": ["expect-type@1.4.0", "", {}, "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA=="], + + "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], + + "fsevents": ["fsevents@2.3.3", "", { "os": "darwin", "hasInstallScript": true }, "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw=="], + + "lightningcss": ["lightningcss@1.33.0", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.33.0", "lightningcss-darwin-arm64": "1.33.0", "lightningcss-darwin-x64": "1.33.0", "lightningcss-freebsd-x64": "1.33.0", "lightningcss-linux-arm-gnueabihf": "1.33.0", "lightningcss-linux-arm64-gnu": "1.33.0", "lightningcss-linux-arm64-musl": "1.33.0", "lightningcss-linux-x64-gnu": "1.33.0", "lightningcss-linux-x64-musl": "1.33.0", "lightningcss-win32-arm64-msvc": "1.33.0", "lightningcss-win32-x64-msvc": "1.33.0" } }, "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA=="], + + "lightningcss-android-arm64": ["lightningcss-android-arm64@1.33.0", "", { "os": "android", "cpu": "arm64" }, "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg=="], + + "lightningcss-darwin-arm64": ["lightningcss-darwin-arm64@1.33.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg=="], + + "lightningcss-darwin-x64": ["lightningcss-darwin-x64@1.33.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ=="], + + "lightningcss-freebsd-x64": ["lightningcss-freebsd-x64@1.33.0", "", { "os": "freebsd", "cpu": "x64" }, "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg=="], + + "lightningcss-linux-arm-gnueabihf": ["lightningcss-linux-arm-gnueabihf@1.33.0", "", { "os": "linux", "cpu": "arm" }, "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ=="], + + "lightningcss-linux-arm64-gnu": ["lightningcss-linux-arm64-gnu@1.33.0", "", { "os": "linux", "cpu": "arm64", "libc": "glibc" }, "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg=="], + + "lightningcss-linux-arm64-musl": ["lightningcss-linux-arm64-musl@1.33.0", "", { "os": "linux", "cpu": "arm64", "libc": "musl" }, "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ=="], + + "lightningcss-linux-x64-gnu": ["lightningcss-linux-x64-gnu@1.33.0", "", { "os": "linux", "cpu": "x64", "libc": "glibc" }, "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg=="], + + "lightningcss-linux-x64-musl": ["lightningcss-linux-x64-musl@1.33.0", "", { "os": "linux", "cpu": "x64", "libc": "musl" }, "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw=="], + + "lightningcss-win32-arm64-msvc": ["lightningcss-win32-arm64-msvc@1.33.0", "", { "os": "win32", "cpu": "arm64" }, "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA=="], + + "lightningcss-win32-x64-msvc": ["lightningcss-win32-x64-msvc@1.33.0", "", { "os": "win32", "cpu": "x64" }, "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA=="], + + "magic-string": ["magic-string@1.4.5", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.6.0" } }, "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w=="], + + "nanoid": ["nanoid@3.3.20", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ=="], + + "obug": ["obug@3.0.0", "", {}, "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw=="], + + "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], + + "picomatch": ["picomatch@4.0.7", "", {}, "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA=="], + + "playwright": ["playwright@1.65.0", "", { "dependencies": { "playwright-core": "1.65.0" }, "bin": { "playwright": "cli.js" } }, "sha512-F3AMWcR44qMBt4kq+6Kb6mX7bjGXshktKFOPULd7reED6ZJWevjbNRqysP7q+AATE9kdPEZBibex1BYsvpVoeA=="], + + "playwright-core": ["playwright-core@1.65.0", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-vNSKgH6YqtN7cdT/L334zo0a+YwkrpicyrHJlWWPIm/Q+Nn2SWInil01oT0mbu96U4GgoRtCYQD9CzJQgju+lA=="], + + "postcss": ["postcss@8.5.33", "", { "dependencies": { "nanoid": "^3.3.20", "picocolors": "^1.1.1", "source-map-js": "^1.2.2" } }, "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ=="], + + "prettier": ["prettier@3.9.10", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-skGHTH1Yb9QvaTC4hWnRTzEYtCpApF0UMBPz+t/0ZPzP8ihefo/btKd+QA7pUE0fEwA1SbS/NmhyEcstdXOIdA=="], + + "rolldown": ["rolldown@1.2.19", "", { "dependencies": { "@oxc-project/types": "=0.156.0", "@rolldown/pluginutils": "^1.0.0" }, "optionalDependencies": { "@rolldown/binding-android-arm-eabi": "1.2.19", "@rolldown/binding-android-arm64": "1.2.19", "@rolldown/binding-darwin-arm64": "1.2.19", "@rolldown/binding-darwin-x64": "1.2.19", "@rolldown/binding-freebsd-x64": "1.2.19", "@rolldown/binding-linux-arm-gnueabihf": "1.2.19", "@rolldown/binding-linux-arm64-gnu": "1.2.19", "@rolldown/binding-linux-arm64-musl": "1.2.19", "@rolldown/binding-linux-ppc64-gnu": "1.2.19", "@rolldown/binding-linux-s390x-gnu": "1.2.19", "@rolldown/binding-linux-x64-gnu": "1.2.19", "@rolldown/binding-linux-x64-musl": "1.2.19", "@rolldown/binding-openharmony-arm64": "1.2.19", "@rolldown/binding-wasm32-wasi": "1.2.19", "@rolldown/binding-win32-arm64-msvc": "1.2.19", "@rolldown/binding-win32-x64-msvc": "1.2.19" }, "bin": { "rolldown": "./bin/cli.mjs" } }, "sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA=="], + + "source-map-js": ["source-map-js@1.2.2", "", {}, "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw=="], + + "std-env": ["std-env@4.3.0", "", {}, "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag=="], + + "tinybench": ["tinybench@6.2.3", "", {}, "sha512-Al01C2JIBnO2CXCAPbpAl6sUiOZHeThGtHYNTa51JRw9PyWOCdr+9Ong05R4qg/Sk3+H645E8ov1h2c58ityNw=="], + + "tinyexec": ["tinyexec@1.3.1", "", {}, "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA=="], + + "tinyglobby": ["tinyglobby@0.2.17", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="], + + "tslib": ["tslib@2.9.1", "", {}, "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA=="], + + "vite": ["vite@8.3.8", "", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", "postcss": "^8.5.32", "rolldown": "~1.2.18", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.7.1 || ^0.8.0", "esbuild": "^0.27.0 || ^0.28.0", "jiti": ">=1.21.0", "less": "^4.0.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA=="], + + "vitest": ["vitest@5.1.0", "", { "dependencies": { "@types/chai": "^5.2.2", "@vitest/mocker": "5.1.0", "chai": "^6.3.0", "es-module-lexer": "^2.3.2", "expect-type": "^1.4.0", "magic-string": "^1.4.3", "obug": "^3.0.0", "picomatch": "^4.0.7", "std-env": "^4.3.0", "tinybench": "^6.2.2", "tinyexec": "^1.3.1", "tinyglobby": "^0.2.17", "why-is-node-running": "3.2.1" }, "peerDependencies": { "@edge-runtime/vm": "*", "@opentelemetry/api": "^1.9.0", "@types/node": "^22.0.0 || >=24.0.0", "@vitest/browser-playwright": "5.1.0", "@vitest/browser-preview": "5.1.0", "@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0", "@vitest/coverage-istanbul": "5.1.0", "@vitest/coverage-v8": "5.1.0", "@vitest/ui": "5.1.0", "happy-dom": "*", "jsdom": "*", "vite": "^6.4.0 || ^7.0.0 || ^8.0.0" }, "optionalPeers": ["@edge-runtime/vm", "@opentelemetry/api", "@types/node", "@vitest/browser-playwright", "@vitest/browser-preview", "@vitest/browser-webdriverio", "@vitest/coverage-istanbul", "@vitest/coverage-v8", "@vitest/ui", "happy-dom", "jsdom"], "bin": { "vitest": "./vitest.mjs" } }, "sha512-MzmNFnrwa8v8lF1bLxw3UJ4EREwVOVb75VqJZmUDRjJ6EluK/x9th7qTbaeDk41WxE1GxWqmTXcdsfobfH5sOA=="], + + "why-is-node-running": ["why-is-node-running@3.2.1", "", { "bin": { "why-is-node-running": "cli.js" } }, "sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ=="], + + "yaml": ["yaml@2.9.1", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw=="], + } +} diff --git a/cms/package.json b/cms/package.json new file mode 100644 index 0000000..c87e32a --- /dev/null +++ b/cms/package.json @@ -0,0 +1,20 @@ +{ + "name": "blog-cms", + "private": true, + "type": "module", + "packageManager": "bun@1.4.4", + "scripts": { + "serve": "python3 -m http.server ${CMS_PORT:-8787} --bind 127.0.0.1 --directory public", + "format:check": "prettier --check .", + "test:unit": "vitest run", + "test:integration": "playwright test --project=integration", + "test:e2e": "playwright test --project=e2e", + "test:compat": "bash scripts/compat-check.sh" + }, + "devDependencies": { + "@playwright/test": "1.65.0", + "prettier": "3.9.10", + "vitest": "5.1.0", + "yaml": "2.9.1" + } +} diff --git a/cms/playwright.config.ts b/cms/playwright.config.ts new file mode 100644 index 0000000..783d6c4 --- /dev/null +++ b/cms/playwright.config.ts @@ -0,0 +1,26 @@ +import { defineConfig, devices } from "@playwright/test"; + +const baseURL = `http://127.0.0.1:${process.env.CMS_PORT ?? "8787"}`; + +export default defineConfig({ + testDir: "test/e2e", + forbidOnly: !!process.env.CI, + reporter: process.env.CI ? "github" : "list", + use: { baseURL }, + projects: [ + { name: "integration", testMatch: "integration.spec.ts" }, + { + name: "e2e", + testMatch: "smoke.spec.ts", + // The admin shell loads Sveltia from the unpkg CDN; one retry absorbs a CDN blip. + retries: 1, + use: { ...devices["Desktop Chrome"] }, + }, + ], + webServer: { + // Cloudflare Pages serves cms/public as static files; a plain static server is equivalent here. + command: "bun run serve", + url: `${baseURL}/admin/`, + reuseExistingServer: !process.env.CI, + }, +}); diff --git a/cms/public/admin/config.yml b/cms/public/admin/config.yml new file mode 100644 index 0000000..5b1f209 --- /dev/null +++ b/cms/public/admin/config.yml @@ -0,0 +1,39 @@ +# Sveltia CMS configuration. Reference: https://sveltiacms.app/en/docs +backend: + name: github + repo: comdotlinux/blog + branch: main +# Each new post gets its own branch cms/posts/ and a pull request. +publish_mode: editorial_workflow +output: + # Without this every save writes `modDatetime: ''`, which the blog schema rejects. + omit_empty_optional_fields: true +media_folder: public/assets +public_folder: /assets +collections: + - name: posts + label: Posts + folder: src/content/posts + extension: md + format: frontmatter + create: true + slug: "{{slug}}" + fields: + - { name: title, label: Title, widget: string } + - { name: author, label: Author, widget: string, default: comdotlinux } + - name: pubDatetime + label: Published + widget: datetime + time_format: false + date_format: YYYY-MM-DD + - name: modDatetime + label: Modified + widget: datetime + time_format: false + date_format: YYYY-MM-DD + required: false + - { name: featured, label: Featured, widget: boolean, default: false } + - { name: draft, label: Draft, widget: boolean, default: false } + - { name: tags, label: Tags, widget: list } + - { name: description, label: Description, widget: string } + - { name: body, label: Body, widget: markdown, modes: [raw, rich_text] } diff --git a/cms/public/admin/index.html b/cms/public/admin/index.html new file mode 100644 index 0000000..5dae8aa --- /dev/null +++ b/cms/public/admin/index.html @@ -0,0 +1,21 @@ + + + + + + + Blog CMS + + + + + + diff --git a/cms/scripts/compat-check.sh b/cms/scripts/compat-check.sh new file mode 100755 index 0000000..c0ed17c --- /dev/null +++ b/cms/scripts/compat-check.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# Builds the blog with the Spike 1 fixture and Sveltia's golden new entry as posts, +# then checks that the rendered HTML keeps the blog's Markdown dialect. +# Restores without deleting: added posts are moved to .trash/-cms-compat/. +set -euo pipefail + +cms_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +root="$(cd "$cms_dir/.." && pwd)" +posts="$root/src/content/posts" +stamp="$(date -u +%Y%m%dT%H%M%SZ)" +declare -A sources=( + [zz-cms-compat-fixture]="$cms_dir/test/fixtures/compat-post.md" + [zz-cms-compat-new]="$cms_dir/test/fixtures/golden/spike-compat-new-b.md" +) + +for slug in "${!sources[@]}"; do + if [ -e "$posts/$slug.md" ]; then + echo "refusing to overwrite $posts/$slug.md" >&2 + exit 1 + fi +done + +restore() { + local trash="$root/.trash/$stamp-cms-compat" + mkdir -p "$trash" + for slug in "${!sources[@]}"; do + if [ -e "$posts/$slug.md" ]; then + mv "$posts/$slug.md" "$trash/" + echo "- $stamp: cms compat-check moved src/content/posts/$slug.md to .trash/$stamp-cms-compat/" >> "$root/.trash/MOVED.md" + fi + done +} +trap restore EXIT + +for slug in "${!sources[@]}"; do cp "${sources[$slug]}" "$posts/$slug.md"; done + +(cd "$root" && bun run build) + +failures=0 +check() { + local name="$1" actual="$2" op="$3" expected="$4" + if [ "$actual" "$op" "$expected" ]; then + echo "ok $name ($actual)" + else + echo "FAIL $name ($actual, expected $op $expected)" + failures=$((failures + 1)) + fi +} + +for slug in "${!sources[@]}"; do + html="$root/dist/posts/$slug/index.html" + echo "== $slug" + check "table" "$(grep -c ']*class="callout' "$html" | wc -l)" -ge 1 + check "image /assets/20221126/" "$(grep -o ']*/assets/20221126/' "$html" | wc -l)" -ge 1 + check "no Markdoc tags" "$(grep -c '{%' "$html" || true)" -eq 0 +done + +[ "$failures" -eq 0 ] || { echo "$failures compat check(s) failed"; exit 1; } +echo "compat checks passed" diff --git a/cms/scripts/content-guard.sh b/cms/scripts/content-guard.sh new file mode 100755 index 0000000..343a525 --- /dev/null +++ b/cms/scripts/content-guard.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# Guards post changes against CMS serializer damage (plan pre-mortem scenario 1). +# Usage: content-guard.sh [base-sha]. Without a usable base, every post is checked. +set -euo pipefail + +root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +cd "$root" +base="${1:-}" +failures=0 +fail() { echo "FAIL $*"; failures=$((failures + 1)); } + +if grep -rn '{%' src/content/posts; then + fail "Markdoc tags ({%) in src/content/posts" +fi + +if [ -n "$base" ] && [ "$base" != "0000000000000000000000000000000000000000" ] && git cat-file -e "$base^{commit}" 2>/dev/null; then + mapfile -t changed < <(git diff --name-only --diff-filter=AM "$base" HEAD -- 'src/content/posts/*.md' 'src/content/posts/*.mdx') + diff_text="$(git diff "$base" HEAD -- src/content/posts)" + while IFS= read -r removed; do + [ -z "$removed" ] && continue + grep -qxF "+${removed:1}" <<<"$diff_text" || fail "fence label removed and not re-added: ${removed:1}" + done < <(grep -E '^-```.*file=' <<<"$diff_text" || true) +else + mapfile -t changed < <(git ls-files 'src/content/posts/*.md' 'src/content/posts/*.mdx') +fi + +for file in "${changed[@]}"; do + frontmatter="$(awk 'NR==1 && $0!="---" {exit} NR>1 && $0=="---" {exit} NR>1 {print}' "$file")" + [ -n "$frontmatter" ] || { fail "$file: no frontmatter"; continue; } + grep -qE '^pubDatetime: ' <<<"$frontmatter" || fail "$file: no pubDatetime" + grep -qE '^title: ' <<<"$frontmatter" || fail "$file: no title" + grep -qE '^description: ' <<<"$frontmatter" || fail "$file: no description" + if grep -nE ":[[:space:]]*(''|\"\")[[:space:]]*$" <<<"$frontmatter"; then + fail "$file: empty string value in frontmatter" + fi +done + +echo "checked ${#changed[@]} post file(s)" +[ "$failures" -eq 0 ] || { echo "$failures content-guard check(s) failed"; exit 1; } +echo "content-guard passed" diff --git a/cms/test/e2e/integration.spec.ts b/cms/test/e2e/integration.spec.ts new file mode 100644 index 0000000..e876c23 --- /dev/null +++ b/cms/test/e2e/integration.spec.ts @@ -0,0 +1,23 @@ +import { expect, test } from "@playwright/test"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; + +test("admin page is served with the pinned script and integrity", async ({ + request, +}) => { + const res = await request.get("/admin/"); + expect(res.status()).toBe(200); + const html = await res.text(); + expect(html).toContain("https://unpkg.com/@sveltia/cms@"); + expect(html).toMatch(/integrity="sha384-[A-Za-z0-9+/=]{64}"/); +}); + +test("config.yml is served unchanged", async ({ request }) => { + const res = await request.get("/admin/config.yml"); + expect(res.status()).toBe(200); + const local = readFileSync( + join(import.meta.dirname, "../../public/admin/config.yml"), + "utf8" + ); + expect(await res.text()).toBe(local); +}); diff --git a/cms/test/e2e/smoke.spec.ts b/cms/test/e2e/smoke.spec.ts new file mode 100644 index 0000000..6f80d6e --- /dev/null +++ b/cms/test/e2e/smoke.spec.ts @@ -0,0 +1,14 @@ +import { expect, test } from "@playwright/test"; + +// Needs network: Sveltia itself comes from the unpkg CDN (pinned version, SRI). +test("admin shell renders the Sveltia sign-in screen", async ({ page }) => { + const errors: string[] = []; + page.on("console", msg => { + if (msg.type() === "error") errors.push(msg.text()); + }); + await page.goto("/admin/"); + await expect( + page.getByRole("button", { name: /Sign In with \W*GitHub/ }) + ).toBeVisible({ timeout: 30_000 }); + expect(errors.filter(e => /integrity|config/i.test(e))).toEqual([]); +}); diff --git a/cms/test/fixtures/compat-post.md b/cms/test/fixtures/compat-post.md new file mode 100644 index 0000000..45a3e54 --- /dev/null +++ b/cms/test/fixtures/compat-post.md @@ -0,0 +1,35 @@ +--- +title: CMS compat fixture +author: comdotlinux +pubDatetime: 2026-11-01 +featured: false +draft: false +tags: + - cms + - tools +description: A fixture post exercising the blog Markdown dialect. +--- + +## A heading for the fixture + +A paragraph with a [link to asdf](https://asdf-vm.com/) and some `inline code`. + +| Tool | Purpose | +| ---- | ------- | +| asdf | versions | +| afx | packages | + +```ts file="hello.ts" +export const hello = (name: string) => `hello ${name}`; +``` + +```shell bash +asdf install nodejs latest +``` + +> [!NOTE] +> This is a callout in Obsidian syntax. + +![Gradle logo](/assets/20221126/gradle-logo.png) + +The end. diff --git a/cms/test/fixtures/golden/on-the-topic-of-tools-their-versions-and-automated-installations.md b/cms/test/fixtures/golden/on-the-topic-of-tools-their-versions-and-automated-installations.md new file mode 100644 index 0000000..4d99d3d --- /dev/null +++ b/cms/test/fixtures/golden/on-the-topic-of-tools-their-versions-and-automated-installations.md @@ -0,0 +1,242 @@ +--- +title: On the topic of tools, their versions & automated installations +author: comdotlinux +pubDatetime: 2022-10-08T16:55:12.000+00:00 +featured: false +draft: false +tags: + - afx + - asdf + - commandline + - github + - linux + - tools +description: Tools +--- + +Impatient? then these are the tools we will discuss + +- [asdf](https://asdf-vm.com/) install it once and then after a few commands you have the tools installed. + +- [afx](https://babarot.me/afx/) the command-line package manager + +We developers love tools, we like to create them, use them and hope that they make our lives better as we are going about our day doing the things we do. You know don't you? "Working Hard or Hardly Working": I don't know who said that but I use it every chance I get. + +![So many tools and tool boxes](/assets/20221008/so-many-tools-and-tool-boxes-high-quality-digital-art.png) + +## Intro + +Ever since the proliferation of GitHub and releases it has been quite easy to release a tool and post the binaries as release attachments. There was some work involved, you had to create a release (some GitHub additions to git tags), and then get the upload URL and upload the assets. But there were a host of tools to help with the process, and they helped but still some fiddling was required and not everyone who had the time to do so had the itch to not only scratch to tool, but also it's automation, or if they did they depended on tools that also were not updated if they had problems. + +And then came GitHub actions, and they streamlined everything for nearly everyone to set it up once and the simply make changes, then release and the actions would take care of testing with different architectures, creating the final build, packaging and uploading the assets to the created release. Not to mention that they are now free for any public repository. + +This is all great and are nice advancements to the high friction process of making software outside a large team, on your own, however what got lost in the process was the earlier ease of (sorry windows) installing nearly any required software by doing this + +```shell bash +# For Debian / Ubuntu and their derivatives +sudo apt install batcat + +# For Fedora and other ditros using RPM packaging + +sudo dnf install bat + +# for mac (I think after installing homebrew once) + +brew install bat +``` + +--- + +## Possible Approaches + +So what to do then? There's great software out there just waiting for us to use, but not as easy to use as above? Well 2 options really + +- Install the tools Manually + - Easy, just list the tools somewhere on a gist, manually install. + - Not easy update though. + - Cannot easily share with others and spread the joy. +- Use another tool to manage the tools + - Setup Once and then every time it get's easier + - Easy To Share + - Commit to your repo and everyone from your team can have the same versions + - Can also be used with you private repo for the next time you need a new setup. Like me when distro hopping. + +So, If you don't want to install manually then the following tools are for you! + +--- + +## [ASDF](https://asdf-vm.com/) + +> Manage multiple runtime versions with a single CLI tool + +It's simple really, let's go though + +- Install [asdf](https://asdf-vm.com/guide/getting-started.html#_1-install-dependencies) (required only once :)) + +- Get all available plugins and find the tool you are looking for + - e.g. + - `asdf plugin list all | grep github-cli` + - `asdf plugin add github-cli` +- Create a file called `.tool-versions` + - As the name indicates, this file contains the tools and their versions to install + - e.g. + - `github-cli 2.16.1` +- Then run `asdf install` +- (Optional) if you want the command to be available everywhere in your home directory + - run `asdf global github-cli 2.16.1` + - This simply creates / updates the `.tool-versions` in your home directory + - just check by running `cat ~/.tool-versions` + +That's it GitHub cli should be available, try running `gh` to check + +[Here](https://github.com/asdf-vm/asdf-plugins#plugin-list) you can find all the plugins available, there are many and now available for you to use. + +To create plugins is not that difficult either, see [here](https://github.com/asdf-vm/asdf/blob/master/docs/plugins/create.md), there are even some plugins that I've created just search for `comdotinux` there. + +`asdf` allows to have different versions of tools in different directories and simply switching to them change to those versions. + +--- + +## [AFX](https://github.com/b4b4r07/afx) + +> AFX is a command-line package manager. afx can allow us to manage almost all things available on GitHub, Gist and so on. + +So Let's Go + +- Install [afx](https://babarot.me/afx/getting-started) - (Only Required Once) + +- Create a file named `~/.config/afx/github.yaml` + +- Fill In the following + +```yaml +github: + - name: stedolan/jq + description: Command-line JSON processor + owner: stedolan + repo: jq + release: + name: jq + tag: jq-1.6 + command: + link: + - from: '\*jq\*' + to: jq +``` + +- Run `afx install` + +That's it `jq` is installed, updating is also easy, update the version, run afx install. +To uninstall, remove the section from yaml and run `afx uninstall` + +## AFX Sample Config + +Here's my current config yaml, as you can see it's much easier to install mostly anything with afx, like [prettyping](https://github.com/denilsonsa/prettyping) which does not have a release but is a shell script that you can install using `afx` + +```yaml +github: + - name: b4b4r07/enhancd + description: A next-generation cd command with your interactive filter + owner: b4b4r07 + repo: enhancd + plugin: + env: + ENHANCD_FILTER: fzf --height 25% --reverse --ansi:fzy + sources: + - init.sh + - name: cantino/mcfly + description: fly through your shell history + owner: cantino + repo: mcfly + release: + name: mcfly + tag: v0.6.1 + command: + link: + - from: "*mcfly*" + to: mcfly + plugin: + sources: + - eval "$(mcfly init zsh)" + - name: bootandy/dust + description: du + rust + owner: bootandy + repo: dust + release: + name: dust + tag: v0.8.3 + asset: + filename: "{{ .Release.Name }}-{{ .Release.Tag }}-x86_64-unknown-linux-gnu.tar.gz" + command: + link: + - from: "dust-v0.8.3-x86_64-unknown-linux-gnu/*dust*" + to: dust + - name: ogham/dog + description: better dig + owner: ogham + repo: dog + release: + name: dog + tag: v0.1.0 + asset: + filename: "{{ .Release.Name }}-{{ .Release.Tag }}-x86_64-unknown-linux-gnu.zip" + command: + link: + - from: "bin/*dog*" + to: digdog + plugin: + sources: + - completions/dog.zsh + - name: denilsonsa/prettyping + description: prettyping is a wrapper around the standard ping tool with the objective of making the output prettier, more colorful, more compact, and easier to read. + owner: denilsonsa + repo: prettyping + command: + link: + - from: prettyping + to: prettyping + - name: tstack/lnav + description: advanced log file viewer for the terminal. It can quickly parse and index log files and display them in a single combined view with syntax highlighting. + owner: tstack + repo: lnav + release: + name: lnav + tag: v0.11.1 + asset: + filename: "lnav-0.11.1-musl-64bit.zip" + command: + link: + - from: "lnav-0.11.1/lnav" + to: lnav + - name: mifi/lossless-cut + description: LosslessCut aims to be the ultimate cross platform FFmpeg GUI for extremely fast and lossless operations on video, audio, subtitle and other related media files. + owner: mifi + repo: lossless-cut + release: + name: lossless-cut + tag: v3.47.1 + asset: + filename: "LosslessCut-linux-x64.tar.bz2" + command: + link: + - from: "*LosslessCut-linux-x64/losslesscut" + to: losslesscut +``` + +Here is my [**Gist**](https://gist.github.com/comdotlinux/bdd4a1a565280a87639dbf740b94f009) (Sometimes not shown properly when embedded) + +![Nicely arranged tools and tool boxes](/assets/20221008/nicely-arranged-tools-and-tool-boxes-high-quality-digital-art.png) + +## Extro + +Now you should have a nice control over your tools and moreover easy to spread the love <3 +So where did I get to know about these tools? A very good Question, most are from the excellent and relatively (to my knowledge) unknown blog post. +[Command Line for the 21. Century: The Low Hanging Fruit](https://ileriseviye.wordpress.com/2018/10/30/command-line-for-the-21-century-the-low-hanging-fruit/) + +## Next Steps? + +- Ability to install `afx` using `asdf` ;) +- Ability to install `asdf` using `afx` ;) +- Also remember to commit the `.tool-versions` and `github.yaml` to source control. + +--- diff --git a/cms/test/fixtures/golden/spike-compat-new-b.md b/cms/test/fixtures/golden/spike-compat-new-b.md new file mode 100644 index 0000000..70fee32 --- /dev/null +++ b/cms/test/fixtures/golden/spike-compat-new-b.md @@ -0,0 +1,36 @@ +--- +title: Spike compat new B +author: comdotlinux +pubDatetime: 2026-11-01 +featured: false +draft: false +tags: + - cms + - tools +description: New entry created in the CMS with the fixture body. +--- + + +## A heading for the fixture + +A paragraph with a [link to asdf](https://asdf-vm.com/) and some `inline code`. + +| Tool | Purpose | +| ---- | ------- | +| asdf | versions | +| afx | packages | + +```ts file="hello.ts" +export const hello = (name: string) => `hello ${name}`; +``` + +```shell bash +asdf install nodejs latest +``` + +> [!NOTE] +> This is a callout in Obsidian syntax. + +![Gradle logo](/assets/20221126/gradle-logo.png) + +The end. diff --git a/cms/test/fixtures/golden/spike-compat.md b/cms/test/fixtures/golden/spike-compat.md new file mode 100644 index 0000000..45a3e54 --- /dev/null +++ b/cms/test/fixtures/golden/spike-compat.md @@ -0,0 +1,35 @@ +--- +title: CMS compat fixture +author: comdotlinux +pubDatetime: 2026-11-01 +featured: false +draft: false +tags: + - cms + - tools +description: A fixture post exercising the blog Markdown dialect. +--- + +## A heading for the fixture + +A paragraph with a [link to asdf](https://asdf-vm.com/) and some `inline code`. + +| Tool | Purpose | +| ---- | ------- | +| asdf | versions | +| afx | packages | + +```ts file="hello.ts" +export const hello = (name: string) => `hello ${name}`; +``` + +```shell bash +asdf install nodejs latest +``` + +> [!NOTE] +> This is a callout in Obsidian syntax. + +![Gradle logo](/assets/20221126/gradle-logo.png) + +The end. diff --git a/cms/test/unit/admin-page.test.ts b/cms/test/unit/admin-page.test.ts new file mode 100644 index 0000000..a7f8e2b --- /dev/null +++ b/cms/test/unit/admin-page.test.ts @@ -0,0 +1,20 @@ +import { readFileSync } from "node:fs"; +import { join } from "node:path"; +import { describe, expect, it } from "vitest"; +import { cmsRoot } from "./helpers"; + +const html = readFileSync(join(cmsRoot, "public/admin/index.html"), "utf8"); + +describe("admin/index.html", () => { + it("loads an exact Sveltia version with subresource integrity", () => { + expect(html).toMatch( + /src="https:\/\/unpkg\.com\/@sveltia\/cms@\d+\.\d+\.\d+\/dist\/sveltia-cms\.js"/ + ); + expect(html).toMatch(/integrity="sha384-[A-Za-z0-9+/=]{64}"/); + expect(html).toContain('crossorigin="anonymous"'); + }); + + it("is not indexed", () => { + expect(html).toContain(''); + }); +}); diff --git a/cms/test/unit/config.test.ts b/cms/test/unit/config.test.ts new file mode 100644 index 0000000..d00f6f7 --- /dev/null +++ b/cms/test/unit/config.test.ts @@ -0,0 +1,84 @@ +import { describe, expect, it } from "vitest"; +import { blogPostKeys, cmsConfig, type Field } from "./helpers"; + +const config = cmsConfig(); +const posts = config.collections.find(c => c.name === "posts"); +const field = (name: string): Field | undefined => + posts?.fields.find(f => f.name === name); + +describe("blog schema key list", () => { + it("parses the posts schema keys from src/content.config.ts", () => { + const keys = blogPostKeys(); + for (const key of ["title", "description", "pubDatetime"]) { + expect(keys).toContain(key); + } + }); +}); + +describe("config.yml", () => { + it("targets this repo on main through the editorial workflow", () => { + expect(config.backend).toEqual({ + name: "github", + repo: "comdotlinux/blog", + branch: "main", + }); + expect(config.publish_mode).toBe("editorial_workflow"); + }); + + it("omits empty optional fields so modDatetime is never written as ''", () => { + expect(config.output?.omit_empty_optional_fields).toBe(true); + }); + + it("writes posts as Markdown with frontmatter into src/content/posts", () => { + expect(posts).toMatchObject({ + folder: "src/content/posts", + extension: "md", + format: "frontmatter", + }); + }); + + it("uses only keys the blog schema knows, plus the body", () => { + const allowed = new Set([...blogPostKeys(), "body"]); + for (const f of posts?.fields ?? []) expect(allowed).toContain(f.name); + }); + + it("leaves out the fields the plan excludes", () => { + const names = posts?.fields.map(f => f.name); + for (const name of [ + "ogImage", + "canonicalURL", + "hideEditPost", + "hideToc", + "timezone", + ]) { + expect(names).not.toContain(name); + } + }); + + it("requires title, description and pubDatetime", () => { + for (const name of ["title", "description", "pubDatetime"]) { + expect(field(name), name).toBeDefined(); + expect(field(name)?.required, name).not.toBe(false); + } + }); + + it("stores pubDatetime and modDatetime as date-only YYYY-MM-DD", () => { + for (const name of ["pubDatetime", "modDatetime"]) { + expect(field(name), name).toMatchObject({ + widget: "datetime", + time_format: false, + date_format: "YYYY-MM-DD", + }); + } + expect(field("modDatetime")?.required).toBe(false); + }); + + it("defaults draft to false", () => { + expect(field("draft")).toMatchObject({ widget: "boolean", default: false }); + }); + + it("edits the body as raw Markdown first", () => { + expect(field("body")).toMatchObject({ widget: "markdown" }); + expect(field("body")?.modes?.[0]).toBe("raw"); + }); +}); diff --git a/cms/test/unit/golden.test.ts b/cms/test/unit/golden.test.ts new file mode 100644 index 0000000..f2f3470 --- /dev/null +++ b/cms/test/unit/golden.test.ts @@ -0,0 +1,33 @@ +import { readdirSync, readFileSync } from "node:fs"; +import { join } from "node:path"; +import { describe, expect, it } from "vitest"; +import { blogPostKeys, cmsRoot, frontmatter } from "./helpers"; + +const goldenDir = join(cmsRoot, "test/fixtures/golden"); +const goldens = readdirSync(goldenDir).filter(name => name.endsWith(".md")); + +describe("golden outputs written by Sveltia in Spike 1", () => { + it("has golden files", () => { + expect(goldens.length).toBeGreaterThan(0); + }); + + it.each(goldens)("%s has blog-valid frontmatter", name => { + const data = frontmatter(readFileSync(join(goldenDir, name), "utf8")); + expect(data.pubDatetime).toBeInstanceOf(Date); + expect(Array.isArray(data.tags)).toBe(true); + for (const tag of data.tags as unknown[]) expect(typeof tag).toBe("string"); + for (const [key, value] of Object.entries(data)) { + expect(value, key).not.toBe(""); + expect(blogPostKeys(), key).toContain(key); + } + }); + + it("writes a new entry's pubDatetime as an unquoted date", () => { + const source = readFileSync( + join(goldenDir, "spike-compat-new-b.md"), + "utf8" + ); + expect(source).toMatch(/^pubDatetime: \d{4}-\d{2}-\d{2}$/m); + expect(source).toMatch(/^draft: false$/m); + }); +}); diff --git a/cms/test/unit/helpers.ts b/cms/test/unit/helpers.ts new file mode 100644 index 0000000..1e4384b --- /dev/null +++ b/cms/test/unit/helpers.ts @@ -0,0 +1,69 @@ +import { readFileSync } from "node:fs"; +import { join } from "node:path"; +import { parseDocument } from "yaml"; + +export const cmsRoot = join(import.meta.dirname, "../.."); +export const repoRoot = join(cmsRoot, ".."); + +// Same options as the blog's parser (@astrojs/internal-helpers/yaml), so dates parse the same way. +export function parseYaml(source: string): unknown { + const doc = parseDocument(source, { + customTags: ["timestamp"], + merge: true, + schema: "core", + }); + if (doc.errors.length > 0) throw doc.errors[0]; + return doc.toJS(); +} + +export function frontmatter(markdown: string): Record { + const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(markdown); + if (!match) throw new Error("no frontmatter"); + return parseYaml(match[1]) as Record; +} + +// Vitest cannot import astro:content, so the posts schema keys are read as text. +export function blogPostKeys(): Set { + const source = readFileSync(join(repoRoot, "src/content.config.ts"), "utf8"); + const start = source.indexOf("const posts = defineCollection("); + const objectStart = source.indexOf("z.object({", start); + const objectEnd = source.indexOf("\n }),", objectStart); + if (start < 0 || objectStart < 0 || objectEnd < 0) { + throw new Error("posts schema not found in src/content.config.ts"); + } + const keys = source + .slice(objectStart, objectEnd) + .split("\n") + .map(line => /^\s+(\w+):/.exec(line)?.[1]) + .filter((key): key is string => Boolean(key)); + return new Set(keys); +} + +export interface Field { + name: string; + widget: string; + required?: boolean; + default?: unknown; + time_format?: string | false; + date_format?: string; + modes?: string[]; +} + +export interface CmsConfig { + backend: { name: string; repo: string; branch: string }; + publish_mode?: string; + output?: { omit_empty_optional_fields?: boolean }; + collections: { + name: string; + folder: string; + extension: string; + format: string; + fields: Field[]; + }[]; +} + +export function cmsConfig(): CmsConfig { + return parseYaml( + readFileSync(join(cmsRoot, "public/admin/config.yml"), "utf8") + ) as CmsConfig; +} diff --git a/cms/tsconfig.json b/cms/tsconfig.json new file mode 100644 index 0000000..a169f0b --- /dev/null +++ b/cms/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "Bundler", + "strict": true, + "skipLibCheck": true, + "noEmit": true + }, + "include": ["**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/cms/vitest.config.ts b/cms/vitest.config.ts new file mode 100644 index 0000000..94aae43 --- /dev/null +++ b/cms/vitest.config.ts @@ -0,0 +1,5 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { include: ["test/unit/**/*.test.ts"] }, +});