create-spillway 0.0.0-stage → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/dist/cli.d.ts +23 -0
  4. package/dist/cli.js +133 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/index.d.ts +116 -0
  7. package/dist/index.js +291 -0
  8. package/dist/index.js.map +1 -0
  9. package/package.json +69 -3
  10. package/templates/astro/.env.example +27 -0
  11. package/templates/astro/README.md +57 -0
  12. package/templates/astro/_gitignore +11 -0
  13. package/templates/astro/astro.config.mjs +21 -0
  14. package/templates/astro/package.json +34 -0
  15. package/templates/astro/scripts/brand.mjs +40 -0
  16. package/templates/astro/src/env.d.ts +2 -0
  17. package/templates/astro/src/layouts/Layout.astro +57 -0
  18. package/templates/astro/src/lib/cache.ts +52 -0
  19. package/templates/astro/src/lib/spillway.ts +106 -0
  20. package/templates/astro/src/middleware.ts +18 -0
  21. package/templates/astro/src/pages/[...path].astro +26 -0
  22. package/templates/astro/src/pages/api/preview/exit.ts +4 -0
  23. package/templates/astro/src/pages/api/preview/index.ts +15 -0
  24. package/templates/astro/src/pages/api/revalidate.ts +34 -0
  25. package/templates/astro/src/pages/robots.txt.ts +6 -0
  26. package/templates/astro/src/pages/sitemap.xml.ts +19 -0
  27. package/templates/astro/src/styles/site.css +83 -0
  28. package/templates/astro/src/styles/spillway-brand.css +1 -0
  29. package/templates/astro/src/styles/spillway-brand.json +3 -0
  30. package/templates/astro/tsconfig.json +6 -0
  31. package/templates/next/.env.example +24 -0
  32. package/templates/next/README.md +48 -0
  33. package/templates/next/_gitignore +12 -0
  34. package/templates/next/app/[[...slug]]/page.tsx +56 -0
  35. package/templates/next/app/api/preview/exit/route.ts +6 -0
  36. package/templates/next/app/api/preview/route.ts +16 -0
  37. package/templates/next/app/api/revalidate/route.ts +41 -0
  38. package/templates/next/app/globals.css +83 -0
  39. package/templates/next/app/layout.tsx +71 -0
  40. package/templates/next/app/not-found.tsx +10 -0
  41. package/templates/next/app/robots.ts +10 -0
  42. package/templates/next/app/sitemap.ts +12 -0
  43. package/templates/next/app/spillway-brand.css +1 -0
  44. package/templates/next/app/spillway-brand.json +3 -0
  45. package/templates/next/components/Nav.tsx +30 -0
  46. package/templates/next/lib/spillway.ts +71 -0
  47. package/templates/next/next.config.ts +14 -0
  48. package/templates/next/package.json +34 -0
  49. package/templates/next/scripts/brand.mjs +40 -0
  50. package/templates/next/tsconfig.json +21 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAiBlE,MAAM,CAAC,MAAM,SAAS,GAAuC;IAC3D,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,uFAAuF;QACpG,OAAO,EAAE,YAAY;QACrB,QAAQ,EAAE,wBAAwB;QAClC,SAAS,EAAE,yBAAyB;QACpC,MAAM,EAAE,uBAAuB;KAChC;IACD,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,8FAA8F;QAC3G,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,+BAA+B;QACzC,SAAS,EAAE,gCAAgC;QAC3C,MAAM,EAAE,uBAAuB;KAChC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,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AC;IACrC,OAAO,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AAC7E,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,SAAS,CAAC,MAAsB,EAAE,QAAsB,EAAE,EAAqC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IAClI,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;IAClD,MAAM,GAAG,GAAG,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjC,OAAO;QACL,MAAM,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE;QACrD,GAAG,EAAE,UAAU;QACf,GAAG,GAAG,qBAAqB,IAAI,CAAC,MAAM,EAAE;QACxC,EAAE;QACF,+GAA+G;QAC/G,yHAAyH;QACzH,gDAAgD,MAAM,CAAC,OAAO,4DAA4D;KAC3H,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "create-spillway",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.11",
4
+ "description": "Scaffold a front end of your own on Spillway CMS: `npm create spillway@latest` writes a Next.js or Astro starter with routing, SEO, menus, redirects, the brand, previews and webhook revalidation wired up.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/kwall-llc/spillway-cms.git",
9
+ "directory": "packages/create-spillway"
10
+ },
11
+ "homepage": "https://github.com/kwall-llc/spillway-cms/tree/main/packages/create-spillway#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/kwall-llc/spillway-cms/issues"
14
+ },
15
+ "keywords": [
16
+ "spillway",
17
+ "cms",
18
+ "headless",
19
+ "nextjs",
20
+ "astro",
21
+ "starter",
22
+ "create"
23
+ ],
24
+ "type": "module",
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "bin": {
28
+ "create-spillway": "./dist/cli.js"
29
+ },
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "default": "./dist/index.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "templates",
40
+ "README.md",
41
+ "LICENSE"
42
+ ],
43
+ "dependencies": {
44
+ "@spillway-cms/brand": "0.1.11"
45
+ },
46
+ "devDependencies": {
47
+ "@astrojs/compiler-rs": "^0.5.2",
48
+ "@astrojs/node": "^11.1.10",
49
+ "@puckeditor/core": "^0.24.0",
50
+ "@types/node": "^22.0.0",
51
+ "@types/react": "^19.0.0",
52
+ "@types/react-dom": "^19.0.0",
53
+ "astro": "^7.4.6",
54
+ "next": "^16.4.5",
55
+ "react": "^19.0.0",
56
+ "react-dom": "^19.0.0",
57
+ "typescript": "^5.9.0",
58
+ "vitest": "^3.0.0",
59
+ "@spillway-cms/astro": "0.1.11",
60
+ "@spillway-cms/blocks": "0.1.11",
61
+ "@spillway-cms/client": "0.1.11",
62
+ "@spillway-cms/next": "0.1.11"
63
+ },
64
+ "engines": {
65
+ "node": ">=20.16"
66
+ },
67
+ "scripts": {
68
+ "build": "rm -rf dist && tsc -p tsconfig.json && chmod +x dist/cli.js",
69
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit && node scripts/typecheck-templates.mjs",
70
+ "test": "vitest run"
71
+ }
6
72
  }
@@ -0,0 +1,27 @@
1
+ # Copy to .env (create-spillway wrote one for you) and fill in. Never commit .env.
2
+
3
+ # The Spillway site this front end reads, its public address.
4
+ SPILLWAY_URL=https://cms.example.org
5
+
6
+ # Optional. An API token (spw_..., made under the account menu → API tokens) with content.view_drafts, for draft
7
+ # previews through /api/preview?preview=1, and to read one site of a multisite instance with SPILLWAY_SITE. Server only.
8
+ SPILLWAY_TOKEN=
9
+ # Optional. The site's key on a multisite instance, when SPILLWAY_URL is not the site's own domain (needs SPILLWAY_TOKEN).
10
+ SPILLWAY_SITE=
11
+
12
+ # The secret of the webhook rule in Spillway (Site settings → Notifications) that posts to /api/revalidate.
13
+ SPILLWAY_WEBHOOK_SECRET=
14
+
15
+ # Guards /api/preview?preview=1 (latest drafts through SPILLWAY_TOKEN) and signs its cookie. Without it, only release
16
+ # share links open a preview.
17
+ SPILLWAY_PREVIEW_SECRET=
18
+
19
+ # Optional. A deploy hook (Vercel, Netlify, ...) the revalidation route calls on brand.published, so the next build
20
+ # refreshes the brand stylesheet. Pages already pick up a new brand without it.
21
+ DEPLOY_HOOK_URL=
22
+
23
+ # This front end's own address: canonical links, the sitemap and robots.txt use it.
24
+ SITE_URL=http://localhost:4321
25
+
26
+ # How long a page read from Spillway stays in the in-memory cache when no webhook purges it, in seconds; 0 turns it off.
27
+ SPILLWAY_CACHE_SECONDS=300
@@ -0,0 +1,57 @@
1
+ # __PROJECT_NAME__
2
+
3
+ An Astro front end on a [Spillway CMS](https://spillwaycms.com) site, made with `create-spillway`. Editors keep working in Spillway's admin; this site renders the published pages with Spillway's own block library on the server, keeps them in memory and drops them the moment a webhook says they changed.
4
+
5
+ ## Set up
6
+
7
+ 1. Install and start it:
8
+
9
+ ```bash
10
+ npm install
11
+ npm run dev # http://localhost:4321
12
+ ```
13
+
14
+ 2. Check `.env` (written for you; `.env.example` explains every value). `SPILLWAY_URL` is your Spillway site's address. The webhook and preview secrets were generated for you; keep the file out of version control.
15
+ 3. In Spillway, under **Site settings → Notifications**, add a rule with the channel **Webhook** for each of the events published, unpublished, deleted, menu changed, redirects changed, site settings changed and brand published (`entity.published`, `entity.unpublished`, `entity.deleted`, `menu.updated`, `redirects.updated`, `site.updated`, `brand.published`), all pointing at `https://<this front end>/api/revalidate` with the secret `SPILLWAY_WEBHOOK_SECRET`. **Test send** on a rule should show as delivered in the **Outbox** below the rules.
16
+ 4. For draft previews, create an API token under the account menu → **API tokens** with `content.view_drafts` and set it as `SPILLWAY_TOKEN`. Release share links work without it. Previews need `SPILLWAY_PREVIEW_SECRET`.
17
+
18
+ ## What is in it
19
+
20
+ | File | What it does |
21
+ | --- | --- |
22
+ | `astro.config.mjs` | Server output on the Node adapter, and the `spillway()` integration (the `spillway:client` module) |
23
+ | `src/lib/spillway.ts` | Pages, the site settings, the brand, menus and redirects read through the cache; canonical links on `SITE_URL`; the signed preview cookie |
24
+ | `src/lib/cache.ts` | The in-memory cache, tagged with Spillway's cache tags and the path; `SPILLWAY_CACHE_SECONDS` bounds it |
25
+ | `src/pages/[...path].astro` | Every path: the page's blocks, or a 404 |
26
+ | `src/layouts/Layout.astro` | The head from the page's SEO data (title, description, canonical, hreflang, Open Graph, JSON-LD), the brand, the block stylesheet, the `main` and `footer` menus, the preview bar |
27
+ | `src/middleware.ts` | Spillway's redirects (301 and 302), before any page |
28
+ | `src/pages/api/revalidate.ts` | The webhook target: verifies `X-Spillway-Signature` and purges the paths and tags the event touched (`affectedByWebhook`) |
29
+ | `src/pages/api/preview/index.ts`, `exit.ts` | Starts a preview from a release share link or `?preview=1&secret=`, and ends it |
30
+ | `src/pages/sitemap.xml.ts`, `robots.txt.ts` | `/sitemap.xml` from the published paths, `/robots.txt` |
31
+ | `scripts/brand.mjs` | Writes the brand stylesheet (`src/styles/spillway-brand.css`) with `@spillway-cms/brand`; runs before every build |
32
+
33
+ Forms post straight to Spillway (the public form endpoint accepts posts from other origins) and media load from it.
34
+
35
+ ## Previews
36
+
37
+ - **A release share link**: `/api/preview?path=/about&release=<release id>&token=<share token>`. Spillway checks the token.
38
+ - **The latest drafts**: `/api/preview?path=/about&preview=1&secret=<SPILLWAY_PREVIEW_SECRET>`, read through `SPILLWAY_TOKEN`.
39
+
40
+ Both set the preview cookie (a draft preview's is signed with `SPILLWAY_PREVIEW_SECRET` and lasts an hour, so a cookie written by hand opens nothing; Spillway checks a share link on every request), and show the preview bar; **Exit preview** (`/api/preview/exit`) ends it. Preview pages are never cached.
41
+
42
+ ## The brand
43
+
44
+ `src/styles/spillway-brand.css` holds the brand as Spillway publishes it (colors, fonts, type scale, spacing as `--sw-*` variables). `npm run brand` refreshes it, and every build does. When someone publishes a brand change, the `brand.published` webhook purges the cache and the layout uses the new brand until the next build writes it; set `DEPLOY_HOOK_URL` to have that webhook start the build.
45
+
46
+ With Tailwind v4, add `@tailwindcss/vite`, write `brandStylesheet(brand, { tailwind: 'v4' })` in `scripts/brand.mjs` and import `spillway-brand.css` after `@import "tailwindcss";`: `bg-primary`, `text-primary-700`, `font-heading` and `rounded-brand` then follow the brand.
47
+
48
+ ## Deploy
49
+
50
+ ```bash
51
+ npm run build
52
+ npm start # node dist/server/entry.mjs with .env loaded; PORT and HOST set the address
53
+ ```
54
+
55
+ Run it on any host with Node 22 (a container, Fly.io, Render, a VM) with the variables from `.env.example` and `SITE_URL` the public address, then point the webhook rules at it. The cache lives in the server process: with several instances or a CDN in front, purge those in `src/pages/api/revalidate.ts` too (`affected.tags` are the tags Spillway sends as `Cache-Tag`). For a serverless host, swap `@astrojs/node` for that host's adapter.
56
+
57
+ See [the headless docs](https://github.com/kwall-llc/spillway-cms/blob/main/docs/adapters.md) for the API and the adapters.
@@ -0,0 +1,11 @@
1
+ node_modules/
2
+ .astro/
3
+ dist/
4
+ *.tsbuildinfo
5
+ .DS_Store
6
+ *.log
7
+
8
+ # Secrets: the Spillway token and the webhook and preview secrets.
9
+ .env
10
+ .env.*
11
+ !.env.example
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from 'astro/config';
2
+ import node from '@astrojs/node';
3
+ import { spillway } from '@spillway-cms/astro';
4
+
5
+ // .env holds SPILLWAY_URL, SPILLWAY_TOKEN and the secrets (create-spillway wrote it; .env.example explains each). They are
6
+ // read from process.env at run time and never written into the build: `npm start` loads .env, a host sets them itself.
7
+ try {
8
+ process.loadEnvFile('.env');
9
+ } catch {
10
+ // no .env: the environment provides the values
11
+ }
12
+
13
+ // Server output on the Node adapter: every page is rendered on request from Spillway's content and cached in memory
14
+ // (src/lib/cache.ts) until a webhook says it changed. `spillway()` registers the `spillway:client` module.
15
+ export default defineConfig({
16
+ output: 'server',
17
+ adapter: node({ mode: 'standalone' }),
18
+ site: process.env.SITE_URL || undefined,
19
+ // SPILLWAY_SITE picks one site of a multisite instance (with SPILLWAY_TOKEN); the site key is not a secret.
20
+ integrations: [spillway(process.env.SPILLWAY_SITE ? { site: process.env.SPILLWAY_SITE } : {})],
21
+ });
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "spillway-astro-starter",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "description": "An Astro front end on Spillway CMS, made with create-spillway",
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "astro dev",
9
+ "brand": "node scripts/brand.mjs",
10
+ "prebuild": "node scripts/brand.mjs",
11
+ "build": "astro build",
12
+ "start": "node --env-file-if-exists=.env ./dist/server/entry.mjs",
13
+ "preview": "astro preview",
14
+ "check": "astro sync && tsc --noEmit"
15
+ },
16
+ "dependencies": {
17
+ "@astrojs/node": "^11.1.10",
18
+ "@puckeditor/core": "^0.24.0",
19
+ "@spillway-cms/astro": "latest",
20
+ "@spillway-cms/blocks": "latest",
21
+ "@spillway-cms/brand": "latest",
22
+ "@spillway-cms/client": "latest",
23
+ "astro": "^7.4.6",
24
+ "react": "^19.0.0",
25
+ "react-dom": "^19.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^22.0.0",
29
+ "typescript": "^5.9.0"
30
+ },
31
+ "engines": {
32
+ "node": ">=22.23"
33
+ }
34
+ }
@@ -0,0 +1,40 @@
1
+ // Writes the Spillway site's published brand (GET /api/public/brand) into the project with @spillway-cms/brand: the
2
+ // stylesheet with the --sw-* variables and fonts, and its version (the layout compares it with the live brand).
3
+ // Runs before every build (prebuild) and by hand with `npm run brand`. When Spillway cannot be reached it keeps the files
4
+ // it has, so a build never fails for it.
5
+ //
6
+ // Using Tailwind v4? Write brandStylesheet(brand, { tailwind: 'v4' }) below and import this file after
7
+ // @import "tailwindcss"; then bg-primary, text-primary-700, font-heading and rounded-brand follow the brand.
8
+ import fs from 'node:fs';
9
+ import { brandStylesheet, fetchBrand } from '@spillway-cms/brand';
10
+
11
+ const CSS = 'src/styles/spillway-brand.css';
12
+ const JSON_FILE = 'src/styles/spillway-brand.json';
13
+
14
+ for (const file of ['.env']) {
15
+ try {
16
+ process.loadEnvFile(file); // never overrides a variable that is already set
17
+ } catch {
18
+ // no such file
19
+ }
20
+ }
21
+
22
+ const url = process.env.SPILLWAY_URL;
23
+ if (!url) {
24
+ console.warn(`[brand] SPILLWAY_URL is not set; keeping ${CSS}`);
25
+ } else {
26
+ try {
27
+ const site = process.env.SPILLWAY_SITE ? { site: process.env.SPILLWAY_SITE, token: process.env.SPILLWAY_TOKEN } : {};
28
+ const brand = await fetchBrand(url, { ...site, requestInit: { signal: AbortSignal.timeout(15_000) } });
29
+ const css = brandStylesheet(brand);
30
+ if (fs.existsSync(CSS) && fs.readFileSync(CSS, 'utf8') === css) {
31
+ console.log(`[brand] version ${brand.version} unchanged`);
32
+ } else {
33
+ fs.writeFileSync(CSS, css);
34
+ fs.writeFileSync(JSON_FILE, JSON.stringify({ version: brand.version }, null, 2) + '\n');
35
+ console.log(`[brand] version ${brand.version} written to ${CSS}`);
36
+ }
37
+ } catch (err) {
38
+ console.warn(`[brand] could not fetch the brand from ${url} (${err instanceof Error ? err.message : err}); keeping ${CSS}`);
39
+ }
40
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="astro/client" />
2
+ /// <reference types="@spillway-cms/astro/client" />
@@ -0,0 +1,57 @@
1
+ ---
2
+ /**
3
+ * The shell around every page: the head from the page's SEO data (canonical links on this front end's address), the
4
+ * brand, the block stylesheet, the main and footer menus and, in a preview, the preview bar.
5
+ */
6
+ import SpillwayStyles from '@spillway-cms/astro/components/SpillwayStyles.astro';
7
+ import { renderHead, renderMenu } from '@spillway-cms/astro/render';
8
+ import type { PreviewState, PublicRender } from '@spillway-cms/client';
9
+ import { loadShell, withSiteUrls } from '../lib/spillway';
10
+ // The brand as it was at build time (scripts/brand.mjs, run before every build): the --sw-* variables and fonts.
11
+ import builtCss from '../styles/spillway-brand.css?raw';
12
+ import builtBrand from '../styles/spillway-brand.json';
13
+ import '../styles/site.css';
14
+
15
+ interface Props {
16
+ page: PublicRender | null;
17
+ preview?: PreviewState | null;
18
+ title?: string;
19
+ }
20
+
21
+ const { page, preview = null, title } = Astro.props;
22
+ const { site, brand, main, footer } = await loadShell(preview);
23
+ // A brand published since the last build arrives with the brand.published webhook; use it until the next build writes it.
24
+ const brandCss = brand && brand.version !== builtBrand.version ? brand.css : builtCss;
25
+ const siteName = site?.name ?? page?.site.name ?? 'Spillway site';
26
+ // The page's own menus mark the current item; pages without one (a 404) use the menus read for the shell.
27
+ const mainItems = page?.menus.main ?? main?.items;
28
+ const footerItems = page?.menus.footer ?? footer?.items;
29
+ ---
30
+ <!doctype html>
31
+ <html lang={page?.locale ?? site?.defaultLocale ?? 'en'}>
32
+ <head>
33
+ <meta charset="utf-8" />
34
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
35
+ {page ? <Fragment set:html={renderHead(withSiteUrls(page))} /> : <title>{title ?? `Page not found | ${siteName}`}</title>}
36
+ <Fragment set:html={`<style id="spillway-brand">${brandCss}</style>`} />
37
+ <SpillwayStyles />
38
+ </head>
39
+ <body>
40
+ <a class="skip-link" href="#main">Skip to content</a>
41
+ {preview && (
42
+ <div class="preview-bar" role="status">
43
+ <span>Preview: you are seeing unpublished content.</span>
44
+ <a href="/api/preview/exit">Exit preview</a>
45
+ </div>
46
+ )}
47
+ <header class="site-header">
48
+ <a class="site-name" href="/">{siteName}</a>
49
+ <nav class="site-nav" aria-label="Main"><Fragment set:html={renderMenu(mainItems)} /></nav>
50
+ </header>
51
+ <main id="main"><slot /></main>
52
+ <footer class="site-footer">
53
+ <nav class="site-nav" aria-label="Footer"><Fragment set:html={renderMenu(footerItems)} /></nav>
54
+ {site?.footerNote?.split('\n').map((line) => <p>{line}</p>)}
55
+ </footer>
56
+ </body>
57
+ </html>
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A small in-memory cache for what the site reads from Spillway, keyed by name and tagged with Spillway's cache tags
3
+ * (`entity:<id>`, `type:page`, `site:<id>`, `menu:main`, ...) and the page's path. src/pages/api/revalidate.ts purges it
4
+ * when a webhook says something changed; entries also expire after SPILLWAY_CACHE_SECONDS (300 by default, 0 turns the
5
+ * cache off) so a missed webhook heals itself.
6
+ *
7
+ * It lives in this server process. With more than one instance, or a CDN in front, purge those from the webhook too
8
+ * (`affected.tags` carries the tags Spillway sends in its Cache-Tag header).
9
+ */
10
+ interface Entry {
11
+ value: unknown;
12
+ tags: Set<string>;
13
+ expires: number;
14
+ }
15
+
16
+ const store = new Map<string, Entry>();
17
+
18
+ function ttlMs(): number {
19
+ const raw = Number(process.env.SPILLWAY_CACHE_SECONDS ?? 300);
20
+ return Number.isFinite(raw) && raw > 0 ? raw * 1000 : 0;
21
+ }
22
+
23
+ /**
24
+ * The cached value under `key`, or what `load` answers, stored with its tags unless `keep` is false. Errors are never
25
+ * cached.
26
+ */
27
+ export async function cached<T>(key: string, load: () => Promise<{ value: T; tags: string[]; keep?: boolean }>): Promise<T> {
28
+ const ttl = ttlMs();
29
+ const hit = store.get(key);
30
+ if (hit && hit.expires > Date.now()) return hit.value as T;
31
+ const { value, tags, keep = true } = await load();
32
+ if (ttl > 0 && keep) store.set(key, { value, tags: new Set(tags), expires: Date.now() + ttl });
33
+ return value;
34
+ }
35
+
36
+ /** Drops every entry carrying one of `tags` or tagged with one of `paths` (as `path:<path>`). Returns how many went. */
37
+ export function purge(tags: string[], paths: string[] = []): number {
38
+ const wanted = new Set([...tags, ...paths.map((p) => `path:${p}`)]);
39
+ let dropped = 0;
40
+ for (const [key, entry] of store) {
41
+ if ([...entry.tags].some((t) => wanted.has(t))) {
42
+ store.delete(key);
43
+ dropped += 1;
44
+ }
45
+ }
46
+ return dropped;
47
+ }
48
+
49
+ /** Empties the cache. */
50
+ export function purgeAll(): void {
51
+ store.clear();
52
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Everything the pages read from Spillway, through the cache in ./cache.ts. `spillway:client` is the client the
3
+ * integration in astro.config.mjs configures from SPILLWAY_URL and SPILLWAY_TOKEN; it is server code, so never import
4
+ * this file from a client-side script.
5
+ */
6
+ import type { AstroCookies } from 'astro';
7
+ import { client } from 'spillway:client';
8
+ import { SpillwayError, previewFromRequest, type PreviewState } from '@spillway-cms/astro';
9
+ import type { PublicBrand, PublicMenu, PublicRedirect, PublicRender, PublicSite } from '@spillway-cms/client';
10
+ import { cached } from './cache';
11
+
12
+ export { client };
13
+
14
+ /** This front end's own address, for canonical links, the sitemap and robots.txt. */
15
+ export const SITE_URL = (process.env.SITE_URL || 'http://localhost:4321').replace(/\/+$/, '');
16
+
17
+ /** Tag of the entries every webhook purges: the site settings, the brand, the menus, the redirects and the path list. */
18
+ export const SHELL_TAG = 'shell';
19
+
20
+ /** The page at `path`, or null when Spillway has none. A preview skips the cache. */
21
+ export async function loadPage(path: string, preview: PreviewState | null = null): Promise<PublicRender | null> {
22
+ const fetchPage = async () => {
23
+ try {
24
+ return await client.render(path, { previewState: preview });
25
+ } catch (err) {
26
+ if (err instanceof SpillwayError && err.status === 404) return null;
27
+ throw err;
28
+ }
29
+ };
30
+ if (preview) return fetchPage();
31
+ return cached(`render:${path}`, async () => {
32
+ const page = await fetchPage();
33
+ // A 404 is not kept: the page may be published any moment.
34
+ return { value: page, tags: page ? [...page.cacheTags, `path:${path}`] : [], keep: page !== null };
35
+ });
36
+ }
37
+
38
+ /** The site settings, the brand and the main and footer menus, each null when Spillway does not answer it. */
39
+ export async function loadShell(preview: PreviewState | null = null): Promise<{ site: PublicSite | null; brand: PublicBrand | null; main: PublicMenu | null; footer: PublicMenu | null }> {
40
+ const c = preview ? client.withPreview(preview) : client;
41
+ const read = <T>(key: string, load: () => Promise<T>): Promise<T | null> =>
42
+ (preview ? load() : cached(key, async () => ({ value: await load(), tags: [SHELL_TAG] }))).catch(() => null);
43
+ const [site, brand, main, footer] = await Promise.all([
44
+ read('site', () => c.site()),
45
+ read('brand', () => c.brand()),
46
+ read('menu:main', () => c.menu('main')),
47
+ read('menu:footer', () => c.menu('footer')),
48
+ ]);
49
+ return { site, brand, main, footer };
50
+ }
51
+
52
+ /** Redirect matching as Spillway does it: case-insensitive, without a trailing slash or a query. */
53
+ export function normalizePath(raw: string): string {
54
+ let p = raw;
55
+ try {
56
+ p = decodeURIComponent(p);
57
+ } catch {
58
+ // keep it as it is; a malformed escape never matches a stored path
59
+ }
60
+ const q = p.indexOf('?');
61
+ if (q >= 0) p = p.slice(0, q);
62
+ p = p.replace(/\/{2,}/g, '/').toLowerCase();
63
+ if (!p.startsWith('/')) p = `/${p}`;
64
+ if (p.length > 1) p = p.replace(/\/+$/, '');
65
+ return p;
66
+ }
67
+
68
+ /** The redirect from `path` in Spillway's list (Marketing → Redirects), if there is one. */
69
+ export async function redirectFor(path: string): Promise<PublicRedirect | undefined> {
70
+ try {
71
+ const list = await cached('redirects', async () => ({ value: await client.redirects(), tags: [SHELL_TAG, 'redirects'] }));
72
+ const want = normalizePath(path);
73
+ return list.find((r) => normalizePath(r.from) === want);
74
+ } catch {
75
+ return undefined; // an older Spillway without the list, or Spillway is down: serve the page
76
+ }
77
+ }
78
+
79
+ /** A URL on the Spillway site rewritten onto this front end (canonical links and alternates name the site's pages). */
80
+ export function onSite(href: string | undefined, origin: string): string | undefined {
81
+ if (!href || !origin) return href;
82
+ return href === origin || href.startsWith(`${origin}/`) ? SITE_URL + href.slice(origin.length) : href;
83
+ }
84
+
85
+ /** The page with its canonical link and hreflang alternates pointing at this front end instead of Spillway. */
86
+ export function withSiteUrls(page: PublicRender): PublicRender {
87
+ const origin = page.site.origin;
88
+ return {
89
+ ...page,
90
+ seo: {
91
+ ...page.seo,
92
+ ...(page.seo.canonical ? { canonical: onSite(page.seo.canonical, origin) } : {}),
93
+ alternates: page.seo.alternates.map((a) => ({ ...a, href: onSite(a.href, origin) ?? a.href })),
94
+ },
95
+ };
96
+ }
97
+
98
+ // ---------- Previews ----------
99
+ // Only /api/preview starts a preview. A draft preview's cookie is signed with SPILLWAY_PREVIEW_SECRET (the client's
100
+ // previewSecret) and expires after an hour, so a cookie someone writes by hand, say `preview=1` for the latest drafts
101
+ // through this site's token, is ignored. A release share link is checked by Spillway on every request.
102
+
103
+ /** The preview this request is in, from the cookie /api/preview set; null for a visitor. */
104
+ export function readPreview(cookies: AstroCookies): PreviewState | null {
105
+ return previewFromRequest({ cookies }, { secret: client.options.previewSecret });
106
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Spillway's redirects (Marketing → Redirects) answered before any page, as on a Spillway-rendered site: 301 or 302 to
3
+ * the target, with the query string kept. The list is cached and purged by the redirects.updated webhook.
4
+ */
5
+ import type { MiddlewareHandler } from 'astro';
6
+ import { redirectFor } from './lib/spillway';
7
+
8
+ const SKIP = ['/api/', '/_astro/', '/_image', '/_server-islands/'];
9
+
10
+ export const onRequest: MiddlewareHandler = async (context, next) => {
11
+ const { pathname, search } = context.url;
12
+ const method = context.request.method;
13
+ if ((method !== 'GET' && method !== 'HEAD') || SKIP.some((p) => pathname.startsWith(p))) return next();
14
+ const hit = await redirectFor(pathname);
15
+ if (!hit) return next();
16
+ const target = search && !hit.to.includes('?') ? `${hit.to}${search}` : hit.to;
17
+ return new Response(null, { status: hit.status, headers: { location: target, 'cache-control': 'no-store' } });
18
+ };
@@ -0,0 +1,26 @@
1
+ ---
2
+ /**
3
+ * Every path: the published page Spillway has there, rendered with the core block library, or a 404. The fetch
4
+ * happens here in the frontmatter, before the layout starts streaming, so the 404 status still reaches the browser.
5
+ */
6
+ import { pathFromParams } from '@spillway-cms/astro';
7
+ import { renderPage } from '@spillway-cms/astro/render';
8
+ import Layout from '../layouts/Layout.astro';
9
+ import { loadPage, readPreview } from '../lib/spillway';
10
+
11
+ const path = pathFromParams(Astro.params);
12
+ const preview = readPreview(Astro.cookies);
13
+ const page = await loadPage(path, preview);
14
+ if (!page) Astro.response.status = 404;
15
+ if (preview) Astro.response.headers.set('cache-control', 'private, no-store');
16
+ ---
17
+ <Layout page={page} preview={preview}>
18
+ {page ? (
19
+ <Fragment set:html={renderPage(page)} />
20
+ ) : (
21
+ <section class="not-found">
22
+ <h1>Page not found</h1>
23
+ <p>There is no published page at this address. <a href="/">Go to the home page</a>.</p>
24
+ </section>
25
+ )}
26
+ </Layout>
@@ -0,0 +1,4 @@
1
+ import { createPreviewExitEndpoint } from '@spillway-cms/astro/server';
2
+
3
+ /** GET /api/preview/exit: ends the preview and goes back to the live home page. */
4
+ export const GET = createPreviewExitEndpoint('/');
@@ -0,0 +1,15 @@
1
+ /**
2
+ * GET /api/preview: starts a preview and shows a page as it will be.
3
+ *
4
+ * - A release share link: /api/preview?path=/about&release=<release id>&token=<share token>. Spillway checks the token;
5
+ * the editor shares the link from the release in the admin.
6
+ * - The latest drafts through this front end's token: /api/preview?path=/about&preview=1&secret=<SPILLWAY_PREVIEW_SECRET>.
7
+ * Needs SPILLWAY_TOKEN with content.view_drafts.
8
+ *
9
+ * It sets the preview cookie (a draft preview's is signed with SPILLWAY_PREVIEW_SECRET and lasts an hour) and opens the
10
+ * page on this site, never another one; /api/preview/exit removes it.
11
+ */
12
+ import { createPreviewEndpoint } from '@spillway-cms/astro/server';
13
+ import { client } from '../../../lib/spillway';
14
+
15
+ export const GET = createPreviewEndpoint({ client });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * POST /api/revalidate: the target of the webhook rules in Spillway (Site settings → Notifications). Point one rule per
3
+ * event at it (entity.published, entity.unpublished, entity.deleted, menu.updated, redirects.updated, site.updated,
4
+ * brand.published) with the secret SPILLWAY_WEBHOOK_SECRET.
5
+ *
6
+ * createRevalidateEndpoint checks the X-Spillway-Signature HMAC over the raw body (401 when it does not match) and
7
+ * acknowledges test sends; onEvent gets what affectedByWebhook found the event touched (the page's path and Spillway's
8
+ * cache tags) and purges exactly those pages from the cache, plus the site settings, brand, menus and redirects.
9
+ */
10
+ import type { APIRoute } from 'astro';
11
+ import { createRevalidateEndpoint, deployHook } from '@spillway-cms/astro/server';
12
+ import { purge } from '../../lib/cache';
13
+ import { SHELL_TAG } from '../../lib/spillway';
14
+
15
+ export const POST: APIRoute = async (context) => {
16
+ const secret = process.env.SPILLWAY_WEBHOOK_SECRET;
17
+ if (!secret) return Response.json({ error: 'SPILLWAY_WEBHOOK_SECRET is not set' }, { status: 503 });
18
+ const endpoint = createRevalidateEndpoint({
19
+ secret,
20
+ onEvent: async (payload, affected) => {
21
+ const dropped = purge([...affected.tags, SHELL_TAG], affected.paths);
22
+ console.log(`[spillway] ${payload.event}: purged ${dropped} cached entries (paths ${affected.paths.join(', ') || '-'})`);
23
+ // Optional: a deploy hook rebuilds the site so the next build writes a newly published brand into the stylesheet.
24
+ if (payload.event === 'brand.published' && process.env.DEPLOY_HOOK_URL) {
25
+ try {
26
+ await deployHook(process.env.DEPLOY_HOOK_URL)(payload, affected);
27
+ } catch (err) {
28
+ console.warn(`[spillway] the deploy hook failed: ${err instanceof Error ? err.message : String(err)}`);
29
+ }
30
+ }
31
+ },
32
+ });
33
+ return endpoint(context);
34
+ };
@@ -0,0 +1,6 @@
1
+ import type { APIRoute } from 'astro';
2
+ import { SITE_URL } from '../lib/spillway';
3
+
4
+ /** /robots.txt: everything may be crawled except the API routes; the sitemap is on this front end's address. */
5
+ export const GET: APIRoute = () =>
6
+ new Response(`User-agent: *\nAllow: /\nDisallow: /api/\n\nSitemap: ${SITE_URL}/sitemap.xml\n`, { headers: { 'content-type': 'text/plain; charset=utf-8' } });