create-spillway 0.1.21 → 0.1.23
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.
- package/README.md +11 -7
- package/dist/cli.d.ts +5 -1
- package/dist/cli.js +47 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +44 -5
- package/dist/index.js +109 -11
- package/dist/index.js.map +1 -1
- package/package.json +11 -7
- package/templates/astro/README.md +16 -3
- package/templates/astro/public/spillway-suggest.js +133 -0
- package/templates/astro/src/layouts/Layout.astro +21 -6
- package/templates/astro/src/lib/spillway.ts +88 -15
- package/templates/astro/src/pages/[...path].astro +58 -6
- package/templates/astro/src/pages/api/search/suggest.ts +16 -0
- package/templates/astro/src/styles/site.css +121 -0
- package/templates/next/README.md +19 -3
- package/templates/next/app/[[...slug]]/page.tsx +7 -4
- package/templates/next/app/api/search/suggest/route.ts +18 -0
- package/templates/next/app/globals.css +121 -0
- package/templates/next/app/layout.tsx +11 -21
- package/templates/next/app/not-found.tsx +11 -6
- package/templates/next/app/search/page.tsx +29 -0
- package/templates/next/components/LanguageSwitcher.tsx +19 -0
- package/templates/next/components/SearchPage.tsx +67 -0
- package/templates/next/components/SiteShell.tsx +38 -0
- package/templates/next/lib/spillway.ts +49 -1
- package/templates/next/next.config.ts +2 -1
- package/templates/next/public/spillway-suggest.js +133 -0
- package/templates/nuxt/.env.example +27 -0
- package/templates/nuxt/README.md +75 -0
- package/templates/nuxt/_gitignore +15 -0
- package/templates/nuxt/app/app.vue +3 -0
- package/templates/nuxt/app/assets/site.css +217 -0
- package/templates/nuxt/app/assets/spillway-brand.css +1 -0
- package/templates/nuxt/app/assets/spillway-brand.json +3 -0
- package/templates/nuxt/app/components/SearchPage.vue +36 -0
- package/templates/nuxt/app/components/SiteShell.vue +30 -0
- package/templates/nuxt/app/components/SpillwayMenu.vue +15 -0
- package/templates/nuxt/app/pages/[...slug].vue +54 -0
- package/templates/nuxt/nuxt.config.ts +18 -0
- package/templates/nuxt/package.json +32 -0
- package/templates/nuxt/public/spillway-suggest.js +133 -0
- package/templates/nuxt/scripts/brand.mjs +40 -0
- package/templates/nuxt/server/api/_spillway/view.get.ts +14 -0
- package/templates/nuxt/server/api/preview/exit.ts +13 -0
- package/templates/nuxt/server/api/preview/index.get.ts +31 -0
- package/templates/nuxt/server/api/revalidate.post.ts +45 -0
- package/templates/nuxt/server/api/search/suggest.get.ts +17 -0
- package/templates/nuxt/server/middleware/redirects.ts +17 -0
- package/templates/nuxt/server/routes/robots.txt.ts +7 -0
- package/templates/nuxt/server/routes/sitemap.xml.ts +18 -0
- package/templates/nuxt/server/utils/cache.ts +52 -0
- package/templates/nuxt/server/utils/preview.ts +6 -0
- package/templates/nuxt/server/utils/spillway.ts +211 -0
- package/templates/nuxt/shared/spillway.ts +60 -0
- package/templates/nuxt/tsconfig.json +9 -0
- package/templates/sveltekit/.env.example +27 -0
- package/templates/sveltekit/README.md +75 -0
- package/templates/sveltekit/_gitignore +11 -0
- package/templates/sveltekit/package.json +34 -0
- package/templates/sveltekit/scripts/brand.mjs +40 -0
- package/templates/sveltekit/src/app.d.ts +14 -0
- package/templates/sveltekit/src/app.html +11 -0
- package/templates/sveltekit/src/env.ts +20 -0
- package/templates/sveltekit/src/hooks.server.ts +26 -0
- package/templates/sveltekit/src/lib/components/SearchPage.svelte +41 -0
- package/templates/sveltekit/src/lib/components/SiteShell.svelte +36 -0
- package/templates/sveltekit/src/lib/components/SpillwayMenu.svelte +18 -0
- package/templates/sveltekit/src/lib/server/cache.ts +54 -0
- package/templates/sveltekit/src/lib/server/preview.ts +6 -0
- package/templates/sveltekit/src/lib/server/spillway.ts +203 -0
- package/templates/sveltekit/src/lib/site.css +204 -0
- package/templates/sveltekit/src/lib/spillway-brand.css +1 -0
- package/templates/sveltekit/src/lib/spillway-brand.json +3 -0
- package/templates/sveltekit/src/lib/view.ts +60 -0
- package/templates/sveltekit/src/routes/+layout.server.ts +4 -0
- package/templates/sveltekit/src/routes/+layout.svelte +8 -0
- package/templates/sveltekit/src/routes/[...path]/+page.server.ts +15 -0
- package/templates/sveltekit/src/routes/[...path]/+page.svelte +54 -0
- package/templates/sveltekit/src/routes/api/preview/+server.ts +30 -0
- package/templates/sveltekit/src/routes/api/preview/exit/+server.ts +10 -0
- package/templates/sveltekit/src/routes/api/revalidate/+server.ts +45 -0
- package/templates/sveltekit/src/routes/api/search/suggest/+server.ts +16 -0
- package/templates/sveltekit/src/routes/robots.txt/+server.ts +6 -0
- package/templates/sveltekit/src/routes/sitemap.xml/+server.ts +19 -0
- package/templates/sveltekit/static/spillway-suggest.js +133 -0
- package/templates/sveltekit/tsconfig.json +8 -0
- package/templates/sveltekit/vite.config.ts +17 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# __PROJECT_NAME__
|
|
2
|
+
|
|
3
|
+
A Nuxt front end on a [Spillway CMS](https://spillwaycms.com) site, made with `create-spillway`. Editors keep working in Spillway's admin; this site places the block area Spillway renders as HTML inside Vue pages of its own, keeps pages 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:3002
|
|
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. If you gave `create-spillway` the address this front end will have (`--deploy-url`) and a token with `site.settings`, it added these rules for you; check them there.
|
|
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
|
+
| `nuxt.config.ts` | The site's CSS, and the route rule that sends pages without Nuxt's client scripts (below) |
|
|
23
|
+
| `server/utils/spillway.ts` | The server-side client and `resolveView`: what a request shows (a Spillway page, the search page or a 404) with its head and the shell around it. Canonical links on `SITE_URL`; redirects; the signed preview cookie |
|
|
24
|
+
| `server/utils/cache.ts` | The in-memory cache, tagged with Spillway's cache tags and the path; `SPILLWAY_CACHE_SECONDS` bounds it |
|
|
25
|
+
| `app/pages/[...slug].vue` | Every path: the head (title, description, canonical, hreflang, Open Graph, JSON-LD, Spillway's CSS) and the page, the search page or the 404 |
|
|
26
|
+
| `app/components/` | `SiteShell.vue` (the site name, the `main` and `footer` menus, the language switcher, the preview bar), `SpillwayMenu.vue`, `SearchPage.vue` |
|
|
27
|
+
| `shared/spillway.ts` | The types the server answers and the pages lay out |
|
|
28
|
+
| `server/middleware/redirects.ts` | Spillway's redirects (301 and 302), before any page |
|
|
29
|
+
| `server/api/revalidate.post.ts` | The webhook target: verifies `X-Spillway-Signature` and purges the paths and tags the event touched (`affectedByWebhook`) |
|
|
30
|
+
| `server/api/preview/index.get.ts`, `exit.ts` | Starts a preview from a release share link or `?preview=1&secret=`, and ends it |
|
|
31
|
+
| `server/api/search/suggest.get.ts`, `public/spillway-suggest.js` | Search suggestions while visitors type |
|
|
32
|
+
| `server/routes/sitemap.xml.ts`, `robots.txt.ts` | `/sitemap.xml` from the published paths, `/robots.txt` |
|
|
33
|
+
| `scripts/brand.mjs` | Writes the brand stylesheet (`app/assets/spillway-brand.css`) with `@spillway-cms/brand`; runs before every build |
|
|
34
|
+
|
|
35
|
+
## How the page is put together
|
|
36
|
+
|
|
37
|
+
Spillway renders the block area: `client.renderHtml(path)` (`GET /api/public/render/<path>?format=html`) answers the page's blocks and regions as HTML, the CSS they need (the theme variables, the block styles and the page's block-style rules) and the few scripts some blocks run (the motion and media players), with the SEO data, the menus and the cache tags. This starter puts that HTML in the page as it is and owns everything around it: the routing, the head, the header and footer, the search page and the cache. The blocks look and behave as on Spillway, Form blocks post to Spillway itself (the form endpoint accepts posts from other origins) and media load from it. Write your own components around the block area; to change a block, change it in Spillway.
|
|
38
|
+
|
|
39
|
+
Pages are sent without Nuxt's client scripts (`routeRules: { '/**': { noScripts: true } }`): Spillway's HTML brings the scripts its blocks need, every link loads the next page as a whole (Nuxt adds speculation rules, so browsers that support them load it ahead), and a page carries no second copy of itself as a payload. When you add Vue components that need to run in the browser, narrow or remove that rule, and keep the block area's links as plain `<a>` elements: scripts inside Spillway's HTML run only when the page loads as a whole.
|
|
40
|
+
|
|
41
|
+
## Search
|
|
42
|
+
|
|
43
|
+
`/search` (and `/es/search` and so on, on a site with several languages) is the search page: the published pages that match, ten a page, read from Spillway's search without `SPILLWAY_TOKEN`, so drafts never show. Spillway's Search block sends visitors there. While visitors type, `public/spillway-suggest.js` suggests pages from this site's `/api/search/suggest`, unless suggestions are off under **Site settings → Search**.
|
|
44
|
+
|
|
45
|
+
## Languages
|
|
46
|
+
|
|
47
|
+
On a site with more than one language (**Site settings → Languages**), every language but the default lives under its prefix (`/es/about`), as on Spillway, and the header has a language switcher: each language links to the translation of the page, or to that language's home page when the page has none. The `<html lang>`, the menus and the search page follow the page's language. The links come from `languageLinks` in `@spillway-cms/client` (`server/utils/spillway.ts`).
|
|
48
|
+
|
|
49
|
+
## Members
|
|
50
|
+
|
|
51
|
+
Signing members in on this front end (sign up, log in, the account page and the pages only members see) is coming: Spillway will be an OpenID Connect provider, so the starter signs members in with the library its framework already uses. Until then, members-only pages answer 404 here; members read them on Spillway's own pages.
|
|
52
|
+
|
|
53
|
+
## Previews
|
|
54
|
+
|
|
55
|
+
- **A release share link**: `/api/preview?path=/about&release=<release id>&token=<share token>`. Spillway checks the token.
|
|
56
|
+
- **The latest drafts**: `/api/preview?path=/about&preview=1&secret=<SPILLWAY_PREVIEW_SECRET>`, read through `SPILLWAY_TOKEN`.
|
|
57
|
+
|
|
58
|
+
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. The preview bar posts to it rather than linking, so a browser that loads links ahead never ends the preview on its own. Preview pages are never cached.
|
|
59
|
+
|
|
60
|
+
## The brand
|
|
61
|
+
|
|
62
|
+
`app/assets/spillway-brand.css` holds the brand as Spillway publishes it (colors, fonts, type scale, spacing as `--sw-*` variables), and every page carries it inline ahead of Spillway's CSS. `npm run brand` refreshes it, and every build does. When someone publishes a brand change, the `brand.published` webhook purges the cache and pages use the new brand until the next build writes it; set `DEPLOY_HOOK_URL` to have that webhook start the build.
|
|
63
|
+
|
|
64
|
+
With Tailwind v4, add `@tailwindcss/vite` to `vite.plugins` in `nuxt.config.ts`, write `brandStylesheet(brand, { tailwind: 'v4' })` in `scripts/brand.mjs` and import `spillway-brand.css` after `@import "tailwindcss";` in a stylesheet of your own: `bg-primary`, `text-primary-700`, `font-heading` and `rounded-brand` then follow the brand.
|
|
65
|
+
|
|
66
|
+
## Deploy
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm run build
|
|
70
|
+
npm start # node .output/server/index.mjs with .env loaded; PORT and HOST set the address
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
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 `server/api/revalidate.post.ts` too (`affected.tags` are the tags Spillway sends as `Cache-Tag`). For another host, set Nitro's preset (`nitro: { preset }` in `nuxt.config.ts`).
|
|
74
|
+
|
|
75
|
+
See [the headless docs](https://github.com/kwall-llc/spillway-cms/blob/main/docs/adapters.md) for the API and the starters.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The shell around Spillway's blocks. Everything reads the brand's variables (spillway-brand.css), so a brand change in
|
|
3
|
+
* Spillway reaches the header and footer too. The fallbacks apply before the first brand fetch.
|
|
4
|
+
*/
|
|
5
|
+
body {
|
|
6
|
+
margin: 0;
|
|
7
|
+
font-family: var(--sw-font-body, system-ui, sans-serif);
|
|
8
|
+
color: var(--sw-color-text, #111827);
|
|
9
|
+
background: var(--sw-color-bg, #ffffff);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.skip-link {
|
|
13
|
+
position: absolute;
|
|
14
|
+
left: -999px;
|
|
15
|
+
}
|
|
16
|
+
.skip-link:focus {
|
|
17
|
+
left: 1rem;
|
|
18
|
+
top: 1rem;
|
|
19
|
+
z-index: 10;
|
|
20
|
+
padding: 0.5rem 1rem;
|
|
21
|
+
background: var(--sw-color-bg, #ffffff);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.preview-bar {
|
|
25
|
+
display: flex;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
gap: 1rem;
|
|
28
|
+
padding: 0.5rem 1rem;
|
|
29
|
+
background: var(--sw-color-warning, #fbbf24);
|
|
30
|
+
color: #111827;
|
|
31
|
+
font-size: 0.875rem;
|
|
32
|
+
}
|
|
33
|
+
.preview-bar a,
|
|
34
|
+
.preview-bar button {
|
|
35
|
+
color: inherit;
|
|
36
|
+
font-weight: 600;
|
|
37
|
+
}
|
|
38
|
+
.preview-bar form {
|
|
39
|
+
display: contents;
|
|
40
|
+
}
|
|
41
|
+
.preview-bar button {
|
|
42
|
+
padding: 0;
|
|
43
|
+
font: inherit;
|
|
44
|
+
font-weight: 600;
|
|
45
|
+
text-decoration: underline;
|
|
46
|
+
background: none;
|
|
47
|
+
border: 0;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.site-header,
|
|
52
|
+
.site-footer {
|
|
53
|
+
display: flex;
|
|
54
|
+
flex-wrap: wrap;
|
|
55
|
+
align-items: center;
|
|
56
|
+
justify-content: space-between;
|
|
57
|
+
gap: 1rem;
|
|
58
|
+
max-width: var(--sw-max-width, 1120px);
|
|
59
|
+
margin: 0 auto;
|
|
60
|
+
padding: 1rem;
|
|
61
|
+
}
|
|
62
|
+
.site-footer {
|
|
63
|
+
border-top: 1px solid var(--sw-color-neutral-200, #e5e7eb);
|
|
64
|
+
color: var(--sw-color-neutral-600, #4b5563);
|
|
65
|
+
font-size: 0.875rem;
|
|
66
|
+
}
|
|
67
|
+
.site-name {
|
|
68
|
+
font-family: var(--sw-font-heading, inherit);
|
|
69
|
+
font-weight: 700;
|
|
70
|
+
color: inherit;
|
|
71
|
+
text-decoration: none;
|
|
72
|
+
}
|
|
73
|
+
.site-nav ul {
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-wrap: wrap;
|
|
76
|
+
gap: 1rem;
|
|
77
|
+
margin: 0;
|
|
78
|
+
padding: 0;
|
|
79
|
+
list-style: none;
|
|
80
|
+
}
|
|
81
|
+
.site-nav ul ul {
|
|
82
|
+
display: none;
|
|
83
|
+
}
|
|
84
|
+
.site-nav a {
|
|
85
|
+
color: inherit;
|
|
86
|
+
}
|
|
87
|
+
.site-nav a[aria-current='page'] {
|
|
88
|
+
color: var(--sw-color-primary, #1d4ed8);
|
|
89
|
+
font-weight: 600;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.not-found {
|
|
93
|
+
max-width: var(--sw-max-width, 1120px);
|
|
94
|
+
margin: 4rem auto;
|
|
95
|
+
padding: 0 1rem;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.language-switcher ul {
|
|
99
|
+
display: flex;
|
|
100
|
+
flex-wrap: wrap;
|
|
101
|
+
gap: 0.75rem;
|
|
102
|
+
margin: 0;
|
|
103
|
+
padding: 0;
|
|
104
|
+
list-style: none;
|
|
105
|
+
font-size: 0.875rem;
|
|
106
|
+
}
|
|
107
|
+
.language-switcher a {
|
|
108
|
+
color: inherit;
|
|
109
|
+
}
|
|
110
|
+
.language-switcher a[aria-current='true'] {
|
|
111
|
+
font-weight: 600;
|
|
112
|
+
text-decoration: none;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.search-page {
|
|
116
|
+
max-width: var(--sw-max-width, 1120px);
|
|
117
|
+
margin: 2rem auto 4rem;
|
|
118
|
+
padding: 0 1rem;
|
|
119
|
+
}
|
|
120
|
+
.search-form {
|
|
121
|
+
display: flex;
|
|
122
|
+
gap: 0.5rem;
|
|
123
|
+
max-width: 36rem;
|
|
124
|
+
}
|
|
125
|
+
.search-form input {
|
|
126
|
+
flex: 1 1 auto;
|
|
127
|
+
min-width: 0;
|
|
128
|
+
min-height: 2.75rem;
|
|
129
|
+
padding: 0.6rem 0.85rem;
|
|
130
|
+
font: inherit;
|
|
131
|
+
color: inherit;
|
|
132
|
+
background: var(--sw-color-bg, #ffffff);
|
|
133
|
+
border: 1px solid color-mix(in srgb, currentColor 28%, transparent);
|
|
134
|
+
border-radius: var(--sw-radius, 8px);
|
|
135
|
+
}
|
|
136
|
+
.search-form button {
|
|
137
|
+
min-height: 2.75rem;
|
|
138
|
+
padding: 0.6rem 1.1rem;
|
|
139
|
+
font: inherit;
|
|
140
|
+
font-weight: 600;
|
|
141
|
+
color: var(--sw-color-bg, #ffffff);
|
|
142
|
+
background: var(--sw-color-primary, #1d4ed8);
|
|
143
|
+
border: 0;
|
|
144
|
+
border-radius: var(--sw-radius, 8px);
|
|
145
|
+
cursor: pointer;
|
|
146
|
+
}
|
|
147
|
+
.search-results {
|
|
148
|
+
margin: 1.5rem 0 0;
|
|
149
|
+
padding: 0;
|
|
150
|
+
list-style: none;
|
|
151
|
+
}
|
|
152
|
+
.search-results li {
|
|
153
|
+
padding: 1rem 0;
|
|
154
|
+
border-bottom: 1px solid var(--sw-color-neutral-200, #e5e7eb);
|
|
155
|
+
}
|
|
156
|
+
.search-results h2 {
|
|
157
|
+
margin: 0 0 0.25rem;
|
|
158
|
+
font-size: 1.125rem;
|
|
159
|
+
}
|
|
160
|
+
.search-results p {
|
|
161
|
+
margin: 0;
|
|
162
|
+
color: var(--sw-color-neutral-600, #4b5563);
|
|
163
|
+
}
|
|
164
|
+
.search-pager {
|
|
165
|
+
display: flex;
|
|
166
|
+
gap: 1rem;
|
|
167
|
+
margin-top: 1.5rem;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* Suggestions under a search field (public/spillway-suggest.js). */
|
|
171
|
+
.sw-suggest-host {
|
|
172
|
+
position: relative;
|
|
173
|
+
}
|
|
174
|
+
.sw-suggest {
|
|
175
|
+
position: absolute;
|
|
176
|
+
top: calc(100% + 0.25rem);
|
|
177
|
+
left: 0;
|
|
178
|
+
right: 0;
|
|
179
|
+
z-index: 40;
|
|
180
|
+
margin: 0;
|
|
181
|
+
padding: 0.3rem;
|
|
182
|
+
list-style: none;
|
|
183
|
+
max-height: 22rem;
|
|
184
|
+
overflow: auto;
|
|
185
|
+
background: var(--sw-color-bg, #ffffff);
|
|
186
|
+
color: var(--sw-color-text, inherit);
|
|
187
|
+
border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
|
|
188
|
+
border-radius: var(--sw-radius, 8px);
|
|
189
|
+
box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
|
|
190
|
+
}
|
|
191
|
+
.sw-suggest__item a {
|
|
192
|
+
display: flex;
|
|
193
|
+
justify-content: space-between;
|
|
194
|
+
align-items: baseline;
|
|
195
|
+
gap: 1rem;
|
|
196
|
+
padding: 0.5rem 0.65rem;
|
|
197
|
+
color: inherit;
|
|
198
|
+
text-decoration: none;
|
|
199
|
+
}
|
|
200
|
+
.sw-suggest__item[aria-selected='true'] a {
|
|
201
|
+
background: color-mix(in srgb, var(--sw-color-primary, #1d4ed8) 12%, transparent);
|
|
202
|
+
}
|
|
203
|
+
.sw-suggest__type {
|
|
204
|
+
flex: none;
|
|
205
|
+
font-size: 0.8125rem;
|
|
206
|
+
opacity: 0.7;
|
|
207
|
+
}
|
|
208
|
+
.sw-visually-hidden {
|
|
209
|
+
position: absolute;
|
|
210
|
+
width: 1px;
|
|
211
|
+
height: 1px;
|
|
212
|
+
margin: -1px;
|
|
213
|
+
overflow: hidden;
|
|
214
|
+
clip: rect(0, 0, 0, 0);
|
|
215
|
+
white-space: nowrap;
|
|
216
|
+
border: 0;
|
|
217
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* The brand of your Spillway site. A placeholder until scripts/brand.mjs fetches it (npm run brand, and before every build). */
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The search page: a GET form, the published pages that match (read as a visitor, so drafts never show) and a pager.
|
|
4
|
+
* With suggestions on in Spillway (Site settings → Search), public/spillway-suggest.js suggests pages while visitors type.
|
|
5
|
+
*/
|
|
6
|
+
import type { SearchView, Shell } from '#shared/spillway';
|
|
7
|
+
|
|
8
|
+
const props = defineProps<{ search: SearchView; shell: Shell }>();
|
|
9
|
+
const pageHref = (n: number) => `${props.shell.searchPath}?q=${encodeURIComponent(props.search.q)}${n > 1 ? `&page=${n}` : ''}`;
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<section class="search-page">
|
|
14
|
+
<h1>Search</h1>
|
|
15
|
+
<form class="search-form" role="search" method="get" :action="shell.searchPath">
|
|
16
|
+
<label class="sw-visually-hidden" for="search-q">Search this site</label>
|
|
17
|
+
<input id="search-q" type="search" name="q" :value="search.q" placeholder="Search" enterkeyhint="search" :data-sw-suggest="shell.suggestions ? '' : undefined" :data-sw-locale="shell.suggestions ? shell.lang : undefined" />
|
|
18
|
+
<button type="submit">Search</button>
|
|
19
|
+
</form>
|
|
20
|
+
<p v-if="search.error" role="alert">Search is not available right now. Please try again later.</p>
|
|
21
|
+
<template v-else-if="search.q">
|
|
22
|
+
<p role="status">{{ search.total === 1 ? '1 result' : `${search.total} results` }} for “{{ search.q }}”</p>
|
|
23
|
+
<ol v-if="search.results.length" class="search-results">
|
|
24
|
+
<li v-for="r in search.results" :key="r.id">
|
|
25
|
+
<h2><a :href="r.href">{{ r.title }}</a></h2>
|
|
26
|
+
<p v-if="r.snippet.length"><template v-for="(part, i) in r.snippet" :key="i"><mark v-if="part.hit">{{ part.text }}</mark><template v-else>{{ part.text }}</template></template></p>
|
|
27
|
+
</li>
|
|
28
|
+
</ol>
|
|
29
|
+
<nav v-if="search.pages > 1" class="search-pager" aria-label="Result pages">
|
|
30
|
+
<a v-if="search.page > 1" :href="pageHref(search.page - 1)" rel="prev">Previous</a>
|
|
31
|
+
<span>Page {{ search.page }} of {{ search.pages }}</span>
|
|
32
|
+
<a v-if="search.page < search.pages" :href="pageHref(search.page + 1)" rel="next">Next</a>
|
|
33
|
+
</nav>
|
|
34
|
+
</template>
|
|
35
|
+
</section>
|
|
36
|
+
</template>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/** The shell around every page: the site name, the main and footer menus, the language switcher and the preview bar. */
|
|
3
|
+
import type { Shell } from '#shared/spillway';
|
|
4
|
+
|
|
5
|
+
defineProps<{ shell: Shell }>();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<template>
|
|
9
|
+
<a class="skip-link" href="#main">Skip to content</a>
|
|
10
|
+
<div v-if="shell.preview" class="preview-bar" role="status">
|
|
11
|
+
<span>Preview: you are seeing unpublished content.</span>
|
|
12
|
+
<form method="post" action="/api/preview/exit"><button type="submit">Exit preview</button></form>
|
|
13
|
+
</div>
|
|
14
|
+
<header class="site-header">
|
|
15
|
+
<a class="site-name" href="/">{{ shell.siteName }}</a>
|
|
16
|
+
<nav class="site-nav" aria-label="Main"><SpillwayMenu :items="shell.main" /></nav>
|
|
17
|
+
<nav v-if="shell.languages.length" class="language-switcher" aria-label="Language">
|
|
18
|
+
<ul>
|
|
19
|
+
<li v-for="l in shell.languages" :key="l.locale">
|
|
20
|
+
<a :href="l.href" :hreflang="l.locale" :lang="l.locale" :aria-current="l.current ? 'true' : undefined">{{ l.label }}</a>
|
|
21
|
+
</li>
|
|
22
|
+
</ul>
|
|
23
|
+
</nav>
|
|
24
|
+
</header>
|
|
25
|
+
<main id="main"><slot /></main>
|
|
26
|
+
<footer class="site-footer">
|
|
27
|
+
<nav class="site-nav" aria-label="Footer"><SpillwayMenu :items="shell.footer" /></nav>
|
|
28
|
+
<p v-for="(line, i) in shell.footerNote" :key="i">{{ line }}</p>
|
|
29
|
+
</footer>
|
|
30
|
+
</template>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/** A Spillway menu (Structure → Menus) as a nested list; the item for the current page is marked. */
|
|
3
|
+
import type { PublicMenuItem } from '@spillway-cms/client';
|
|
4
|
+
|
|
5
|
+
defineProps<{ items: PublicMenuItem[] }>();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<template>
|
|
9
|
+
<ul v-if="items.length">
|
|
10
|
+
<li v-for="item in items" :key="`${item.href}:${item.label}`" :class="item.current ? 'is-current' : undefined">
|
|
11
|
+
<a :href="item.href" :aria-current="item.current ? 'page' : undefined" :target="item.newTab ? '_blank' : undefined" :rel="item.newTab ? 'noopener' : undefined">{{ item.label }}</a>
|
|
12
|
+
<SpillwayMenu v-if="item.children?.length" :items="item.children" />
|
|
13
|
+
</li>
|
|
14
|
+
</ul>
|
|
15
|
+
</template>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Every path: a Spillway page with its block area as Spillway renders it, the search page (/search, /es/search), or a
|
|
4
|
+
* 404. server/utils/spillway.ts works out which and reads everything from Spillway; this page sets the head and lays it out.
|
|
5
|
+
*/
|
|
6
|
+
import type { View } from '#shared/spillway';
|
|
7
|
+
// The brand as the last build wrote it (scripts/brand.mjs, before every build): the --sw-* variables and fonts.
|
|
8
|
+
import builtBrandCss from '~/assets/spillway-brand.css?raw';
|
|
9
|
+
|
|
10
|
+
const route = useRoute();
|
|
11
|
+
const { data, error } = await useFetch<View>('/api/_spillway/view', { query: { ...route.query, _path: route.path } });
|
|
12
|
+
if (!data.value) throw createError({ statusCode: 502, statusMessage: `Spillway did not answer: ${error.value?.message ?? 'no response'}`, fatal: true });
|
|
13
|
+
const view = data.value;
|
|
14
|
+
|
|
15
|
+
const event = useRequestEvent();
|
|
16
|
+
if (event && view.kind === 'not-found') setResponseStatus(event, 404, 'Page not found');
|
|
17
|
+
if (view.shell.preview) useResponseHeader('cache-control').value = 'private, no-store';
|
|
18
|
+
|
|
19
|
+
const { head, shell } = view;
|
|
20
|
+
useHead({
|
|
21
|
+
htmlAttrs: { lang: shell.lang, ...(head.motion ? { 'data-sw-motion': head.motion } : {}) },
|
|
22
|
+
title: head.title,
|
|
23
|
+
meta: [
|
|
24
|
+
...(head.description ? [{ name: 'description', content: head.description }, { property: 'og:description', content: head.description }] : []),
|
|
25
|
+
{ property: 'og:title', content: head.title },
|
|
26
|
+
{ property: 'og:type', content: 'website' },
|
|
27
|
+
{ property: 'og:site_name', content: shell.siteName },
|
|
28
|
+
...(head.canonical ? [{ property: 'og:url', content: head.canonical }] : []),
|
|
29
|
+
...(head.ogImage ? [{ property: 'og:image', content: head.ogImage }] : []),
|
|
30
|
+
...(head.noindex ? [{ name: 'robots', content: 'noindex, nofollow' }] : []),
|
|
31
|
+
],
|
|
32
|
+
link: [...(head.canonical ? [{ rel: 'canonical' as const, href: head.canonical }] : []), ...head.alternates.map((a) => ({ rel: 'alternate' as const, hreflang: a.hreflang, href: a.href }))],
|
|
33
|
+
// The brand (one published since the last build arrives with the brand.published webhook and wins until the next
|
|
34
|
+
// build writes it), then Spillway's CSS for the page.
|
|
35
|
+
style: [shell.brandCss ?? builtBrandCss, ...head.css].filter(Boolean).map((innerHTML) => ({ innerHTML })),
|
|
36
|
+
script: [
|
|
37
|
+
...head.jsonLd.map((innerHTML) => ({ type: 'application/ld+json' as const, innerHTML })),
|
|
38
|
+
...(shell.suggestions ? [{ src: '/spillway-suggest.js', defer: true }] : []),
|
|
39
|
+
// The scripts the page's blocks need (the motion and media players), after the body.
|
|
40
|
+
...(view.kind === 'page' ? view.scripts.map((innerHTML) => ({ innerHTML, tagPosition: 'bodyClose' as const })) : []),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<SiteShell :shell="shell">
|
|
47
|
+
<div v-if="view.kind === 'page'" class="spillway-page" v-html="view.body" />
|
|
48
|
+
<SearchPage v-else-if="view.kind === 'search'" :search="view.search" :shell="shell" />
|
|
49
|
+
<section v-else class="not-found">
|
|
50
|
+
<h1>Page not found</h1>
|
|
51
|
+
<p>There is no published page at this address. <a href="/">Go to the home page</a>.</p>
|
|
52
|
+
</section>
|
|
53
|
+
</SiteShell>
|
|
54
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
2
|
+
//
|
|
3
|
+
// .env holds SPILLWAY_URL, SPILLWAY_TOKEN and the secrets (create-spillway wrote it; .env.example explains each). The
|
|
4
|
+
// server code reads them from process.env when it runs, so they are never written into the build: `nuxt dev` loads .env,
|
|
5
|
+
// `npm start` does too, and a host sets them itself.
|
|
6
|
+
export default defineNuxtConfig({
|
|
7
|
+
compatibilityDate: '2025-07-15',
|
|
8
|
+
devtools: { enabled: false },
|
|
9
|
+
devServer: { port: 3002 },
|
|
10
|
+
// The shell around Spillway's blocks. The brand goes inline in every page, ahead of Spillway's CSS (app/pages/[...slug].vue).
|
|
11
|
+
css: ['~/assets/site.css'],
|
|
12
|
+
routeRules: {
|
|
13
|
+
// Pages are rendered on the server without Nuxt's client scripts: Spillway's HTML brings the few scripts its blocks
|
|
14
|
+
// need, links load the next page as a whole, and a page carries no second copy of itself as a payload. Remove this
|
|
15
|
+
// rule when you add Vue components that need to run in the browser; see README.md.
|
|
16
|
+
'/**': { noScripts: true },
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "spillway-nuxt-starter",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "A Nuxt front end on Spillway CMS, made with create-spillway",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "nuxt dev",
|
|
9
|
+
"brand": "node scripts/brand.mjs",
|
|
10
|
+
"prebuild": "node scripts/brand.mjs",
|
|
11
|
+
"build": "nuxt build",
|
|
12
|
+
"start": "node --env-file-if-exists=.env .output/server/index.mjs",
|
|
13
|
+
"preview": "nuxt preview",
|
|
14
|
+
"postinstall": "nuxt prepare",
|
|
15
|
+
"typecheck": "nuxt typecheck"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@spillway-cms/brand": "latest",
|
|
19
|
+
"@spillway-cms/client": "latest",
|
|
20
|
+
"nuxt": "^4.6.4",
|
|
21
|
+
"vue": "^3.5.45",
|
|
22
|
+
"vue-router": "^5.5.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^22.0.0",
|
|
26
|
+
"typescript": "^5.9.0",
|
|
27
|
+
"vue-tsc": "^3.3.14"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": "^22.22.3 || ^24.15.0 || >=26.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Search suggestions while visitors type, for every search field marked data-sw-suggest: the field on the search page
|
|
3
|
+
* and Spillway's Search blocks (Spillway marks them when Site settings → Search has suggestions on). It asks this front
|
|
4
|
+
* end's /api/search/suggest, which reads Spillway's published pages, and shows them as a list under the field: the arrow
|
|
5
|
+
* keys move through it, Enter opens the highlighted page, Escape closes it. Without this script the field is a plain
|
|
6
|
+
* search form. Text is set with textContent, never parsed as HTML.
|
|
7
|
+
*/
|
|
8
|
+
(function () {
|
|
9
|
+
var d = document;
|
|
10
|
+
var count = 0;
|
|
11
|
+
function bind(input) {
|
|
12
|
+
if (input.hasAttribute('data-sw-bound') || !input.form) return;
|
|
13
|
+
input.setAttribute('data-sw-bound', '');
|
|
14
|
+
var form = input.form;
|
|
15
|
+
var id = 'sw-suggest-' + ++count;
|
|
16
|
+
var locale = input.getAttribute('data-sw-locale') || '';
|
|
17
|
+
var list = d.createElement('ul');
|
|
18
|
+
var live = d.createElement('div');
|
|
19
|
+
var timer = 0;
|
|
20
|
+
var active = -1;
|
|
21
|
+
var asked = '';
|
|
22
|
+
list.id = id;
|
|
23
|
+
list.className = 'sw-suggest';
|
|
24
|
+
list.setAttribute('role', 'listbox');
|
|
25
|
+
list.setAttribute('aria-label', 'Suggestions');
|
|
26
|
+
list.hidden = true;
|
|
27
|
+
live.className = 'sw-visually-hidden';
|
|
28
|
+
live.setAttribute('aria-live', 'polite');
|
|
29
|
+
form.classList.add('sw-suggest-host');
|
|
30
|
+
form.appendChild(list);
|
|
31
|
+
form.appendChild(live);
|
|
32
|
+
input.setAttribute('role', 'combobox');
|
|
33
|
+
input.setAttribute('aria-autocomplete', 'list');
|
|
34
|
+
input.setAttribute('aria-expanded', 'false');
|
|
35
|
+
input.setAttribute('aria-controls', id);
|
|
36
|
+
input.setAttribute('autocomplete', 'off');
|
|
37
|
+
|
|
38
|
+
function close() {
|
|
39
|
+
list.hidden = true;
|
|
40
|
+
active = -1;
|
|
41
|
+
input.setAttribute('aria-expanded', 'false');
|
|
42
|
+
input.removeAttribute('aria-activedescendant');
|
|
43
|
+
}
|
|
44
|
+
function mark(i) {
|
|
45
|
+
var options = list.children;
|
|
46
|
+
for (var k = 0; k < options.length; k++) options[k].setAttribute('aria-selected', k === i ? 'true' : 'false');
|
|
47
|
+
active = i;
|
|
48
|
+
if (i < 0) input.removeAttribute('aria-activedescendant');
|
|
49
|
+
else input.setAttribute('aria-activedescendant', options[i].id);
|
|
50
|
+
}
|
|
51
|
+
function show(items) {
|
|
52
|
+
list.textContent = '';
|
|
53
|
+
active = -1;
|
|
54
|
+
if (!items.length) {
|
|
55
|
+
close();
|
|
56
|
+
live.textContent = '';
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
items.forEach(function (item, i) {
|
|
60
|
+
var li = d.createElement('li');
|
|
61
|
+
var a = d.createElement('a');
|
|
62
|
+
var title = d.createElement('span');
|
|
63
|
+
var type = d.createElement('span');
|
|
64
|
+
li.id = id + '-' + i;
|
|
65
|
+
li.className = 'sw-suggest__item';
|
|
66
|
+
li.setAttribute('role', 'option');
|
|
67
|
+
li.setAttribute('aria-selected', 'false');
|
|
68
|
+
a.href = item.path;
|
|
69
|
+
a.tabIndex = -1;
|
|
70
|
+
title.className = 'sw-suggest__title';
|
|
71
|
+
title.textContent = item.title;
|
|
72
|
+
type.className = 'sw-suggest__type';
|
|
73
|
+
type.textContent = item.typeLabel;
|
|
74
|
+
a.appendChild(title);
|
|
75
|
+
a.appendChild(type);
|
|
76
|
+
li.appendChild(a);
|
|
77
|
+
li.addEventListener('mousedown', function (e) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
});
|
|
80
|
+
list.appendChild(li);
|
|
81
|
+
});
|
|
82
|
+
list.hidden = false;
|
|
83
|
+
input.setAttribute('aria-expanded', 'true');
|
|
84
|
+
live.textContent = items.length + (items.length === 1 ? ' suggestion' : ' suggestions') + ', use the up and down arrows to choose';
|
|
85
|
+
}
|
|
86
|
+
function ask() {
|
|
87
|
+
var q = input.value.trim();
|
|
88
|
+
if (q === asked) return;
|
|
89
|
+
asked = q;
|
|
90
|
+
if (q.length < 2) return show([]);
|
|
91
|
+
var url = '/api/search/suggest?q=' + encodeURIComponent(q) + (locale ? '&locale=' + encodeURIComponent(locale) : '');
|
|
92
|
+
fetch(url, { headers: { accept: 'application/json' } })
|
|
93
|
+
.then(function (res) {
|
|
94
|
+
return res.ok ? res.json() : { items: [] };
|
|
95
|
+
})
|
|
96
|
+
.then(function (body) {
|
|
97
|
+
if (input.value.trim() === q) show((body && body.items) || []);
|
|
98
|
+
})
|
|
99
|
+
.catch(function () {
|
|
100
|
+
show([]);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
input.addEventListener('input', function () {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
timer = setTimeout(ask, 150);
|
|
106
|
+
});
|
|
107
|
+
input.addEventListener('keydown', function (e) {
|
|
108
|
+
var n = list.children.length;
|
|
109
|
+
if (e.key === 'ArrowDown' && n) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
list.hidden = false;
|
|
112
|
+
input.setAttribute('aria-expanded', 'true');
|
|
113
|
+
mark((active + 1) % n);
|
|
114
|
+
} else if (e.key === 'ArrowUp' && n) {
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
mark(active <= 0 ? n - 1 : active - 1);
|
|
117
|
+
} else if (e.key === 'Enter' && active >= 0 && !list.hidden) {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
location.href = list.children[active].querySelector('a').href;
|
|
120
|
+
} else if (e.key === 'Escape' && !list.hidden) {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
close();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
input.addEventListener('blur', close);
|
|
126
|
+
}
|
|
127
|
+
function scan() {
|
|
128
|
+
var fields = d.querySelectorAll('form [data-sw-suggest]');
|
|
129
|
+
for (var i = 0; i < fields.length; i++) bind(fields[i]);
|
|
130
|
+
}
|
|
131
|
+
if (d.readyState === 'loading') d.addEventListener('DOMContentLoaded', scan);
|
|
132
|
+
else scan();
|
|
133
|
+
})();
|