create-spillway 0.1.22 → 0.1.24
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,204 @@
|
|
|
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
|
+
color: inherit;
|
|
35
|
+
font-weight: 600;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.site-header,
|
|
39
|
+
.site-footer {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-wrap: wrap;
|
|
42
|
+
align-items: center;
|
|
43
|
+
justify-content: space-between;
|
|
44
|
+
gap: 1rem;
|
|
45
|
+
max-width: var(--sw-max-width, 1120px);
|
|
46
|
+
margin: 0 auto;
|
|
47
|
+
padding: 1rem;
|
|
48
|
+
}
|
|
49
|
+
.site-footer {
|
|
50
|
+
border-top: 1px solid var(--sw-color-neutral-200, #e5e7eb);
|
|
51
|
+
color: var(--sw-color-neutral-600, #4b5563);
|
|
52
|
+
font-size: 0.875rem;
|
|
53
|
+
}
|
|
54
|
+
.site-name {
|
|
55
|
+
font-family: var(--sw-font-heading, inherit);
|
|
56
|
+
font-weight: 700;
|
|
57
|
+
color: inherit;
|
|
58
|
+
text-decoration: none;
|
|
59
|
+
}
|
|
60
|
+
.site-nav ul {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-wrap: wrap;
|
|
63
|
+
gap: 1rem;
|
|
64
|
+
margin: 0;
|
|
65
|
+
padding: 0;
|
|
66
|
+
list-style: none;
|
|
67
|
+
}
|
|
68
|
+
.site-nav ul ul {
|
|
69
|
+
display: none;
|
|
70
|
+
}
|
|
71
|
+
.site-nav a {
|
|
72
|
+
color: inherit;
|
|
73
|
+
}
|
|
74
|
+
.site-nav a[aria-current='page'] {
|
|
75
|
+
color: var(--sw-color-primary, #1d4ed8);
|
|
76
|
+
font-weight: 600;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.not-found {
|
|
80
|
+
max-width: var(--sw-max-width, 1120px);
|
|
81
|
+
margin: 4rem auto;
|
|
82
|
+
padding: 0 1rem;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.language-switcher ul {
|
|
86
|
+
display: flex;
|
|
87
|
+
flex-wrap: wrap;
|
|
88
|
+
gap: 0.75rem;
|
|
89
|
+
margin: 0;
|
|
90
|
+
padding: 0;
|
|
91
|
+
list-style: none;
|
|
92
|
+
font-size: 0.875rem;
|
|
93
|
+
}
|
|
94
|
+
.language-switcher a {
|
|
95
|
+
color: inherit;
|
|
96
|
+
}
|
|
97
|
+
.language-switcher a[aria-current='true'] {
|
|
98
|
+
font-weight: 600;
|
|
99
|
+
text-decoration: none;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.search-page {
|
|
103
|
+
max-width: var(--sw-max-width, 1120px);
|
|
104
|
+
margin: 2rem auto 4rem;
|
|
105
|
+
padding: 0 1rem;
|
|
106
|
+
}
|
|
107
|
+
.search-form {
|
|
108
|
+
display: flex;
|
|
109
|
+
gap: 0.5rem;
|
|
110
|
+
max-width: 36rem;
|
|
111
|
+
}
|
|
112
|
+
.search-form input {
|
|
113
|
+
flex: 1 1 auto;
|
|
114
|
+
min-width: 0;
|
|
115
|
+
min-height: 2.75rem;
|
|
116
|
+
padding: 0.6rem 0.85rem;
|
|
117
|
+
font: inherit;
|
|
118
|
+
color: inherit;
|
|
119
|
+
background: var(--sw-color-bg, #ffffff);
|
|
120
|
+
border: 1px solid color-mix(in srgb, currentColor 28%, transparent);
|
|
121
|
+
border-radius: var(--sw-radius, 8px);
|
|
122
|
+
}
|
|
123
|
+
.search-form button {
|
|
124
|
+
min-height: 2.75rem;
|
|
125
|
+
padding: 0.6rem 1.1rem;
|
|
126
|
+
font: inherit;
|
|
127
|
+
font-weight: 600;
|
|
128
|
+
color: var(--sw-color-bg, #ffffff);
|
|
129
|
+
background: var(--sw-color-primary, #1d4ed8);
|
|
130
|
+
border: 0;
|
|
131
|
+
border-radius: var(--sw-radius, 8px);
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
}
|
|
134
|
+
.search-results {
|
|
135
|
+
margin: 1.5rem 0 0;
|
|
136
|
+
padding: 0;
|
|
137
|
+
list-style: none;
|
|
138
|
+
}
|
|
139
|
+
.search-results li {
|
|
140
|
+
padding: 1rem 0;
|
|
141
|
+
border-bottom: 1px solid var(--sw-color-neutral-200, #e5e7eb);
|
|
142
|
+
}
|
|
143
|
+
.search-results h2 {
|
|
144
|
+
margin: 0 0 0.25rem;
|
|
145
|
+
font-size: 1.125rem;
|
|
146
|
+
}
|
|
147
|
+
.search-results p {
|
|
148
|
+
margin: 0;
|
|
149
|
+
color: var(--sw-color-neutral-600, #4b5563);
|
|
150
|
+
}
|
|
151
|
+
.search-pager {
|
|
152
|
+
display: flex;
|
|
153
|
+
gap: 1rem;
|
|
154
|
+
margin-top: 1.5rem;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* Suggestions under a search field (public/spillway-suggest.js). */
|
|
158
|
+
.sw-suggest-host {
|
|
159
|
+
position: relative;
|
|
160
|
+
}
|
|
161
|
+
.sw-suggest {
|
|
162
|
+
position: absolute;
|
|
163
|
+
top: calc(100% + 0.25rem);
|
|
164
|
+
left: 0;
|
|
165
|
+
right: 0;
|
|
166
|
+
z-index: 40;
|
|
167
|
+
margin: 0;
|
|
168
|
+
padding: 0.3rem;
|
|
169
|
+
list-style: none;
|
|
170
|
+
max-height: 22rem;
|
|
171
|
+
overflow: auto;
|
|
172
|
+
background: var(--sw-color-bg, #ffffff);
|
|
173
|
+
color: var(--sw-color-text, inherit);
|
|
174
|
+
border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
|
|
175
|
+
border-radius: var(--sw-radius, 8px);
|
|
176
|
+
box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
|
|
177
|
+
}
|
|
178
|
+
.sw-suggest__item a {
|
|
179
|
+
display: flex;
|
|
180
|
+
justify-content: space-between;
|
|
181
|
+
align-items: baseline;
|
|
182
|
+
gap: 1rem;
|
|
183
|
+
padding: 0.5rem 0.65rem;
|
|
184
|
+
color: inherit;
|
|
185
|
+
text-decoration: none;
|
|
186
|
+
}
|
|
187
|
+
.sw-suggest__item[aria-selected='true'] a {
|
|
188
|
+
background: color-mix(in srgb, var(--sw-color-primary, #1d4ed8) 12%, transparent);
|
|
189
|
+
}
|
|
190
|
+
.sw-suggest__type {
|
|
191
|
+
flex: none;
|
|
192
|
+
font-size: 0.8125rem;
|
|
193
|
+
opacity: 0.7;
|
|
194
|
+
}
|
|
195
|
+
.sw-visually-hidden {
|
|
196
|
+
position: absolute;
|
|
197
|
+
width: 1px;
|
|
198
|
+
height: 1px;
|
|
199
|
+
margin: -1px;
|
|
200
|
+
overflow: hidden;
|
|
201
|
+
clip: rect(0, 0, 0, 0);
|
|
202
|
+
white-space: nowrap;
|
|
203
|
+
border: 0;
|
|
204
|
+
}
|
|
@@ -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,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the server answers for a request (src/lib/server/spillway.ts, `resolveView`) and the Svelte pages lay out. Types
|
|
3
|
+
* only, so the components can import them.
|
|
4
|
+
*/
|
|
5
|
+
import type { LanguageLink, PublicMenuItem } from '@spillway-cms/client';
|
|
6
|
+
|
|
7
|
+
export interface HeadData {
|
|
8
|
+
title: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
canonical?: string;
|
|
11
|
+
alternates: { hreflang: string; href: string }[];
|
|
12
|
+
ogImage?: string;
|
|
13
|
+
noindex: boolean;
|
|
14
|
+
/** JSON-LD, already escaped for a <script> element. */
|
|
15
|
+
jsonLd: string[];
|
|
16
|
+
/** Spillway's CSS for the page, in order: the theme variables, the block styles and the page's block-style rules. */
|
|
17
|
+
css: string[];
|
|
18
|
+
/** The site's motion level when the page animates, for data-sw-motion on <html>. */
|
|
19
|
+
motion: 'subtle' | 'expressive' | null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Shell {
|
|
23
|
+
siteName: string;
|
|
24
|
+
footerNote: string[];
|
|
25
|
+
lang: string;
|
|
26
|
+
main: PublicMenuItem[];
|
|
27
|
+
footer: PublicMenuItem[];
|
|
28
|
+
/** One link per site locale; empty for a site with one locale. */
|
|
29
|
+
languages: LanguageLink[];
|
|
30
|
+
/** The published brand's stylesheet when it is newer than the one the last build wrote (use that one), else null. */
|
|
31
|
+
brandCss: string | null;
|
|
32
|
+
/** Whether search fields suggest pages while visitors type (Site settings → Search). */
|
|
33
|
+
suggestions: boolean;
|
|
34
|
+
/** The search page in the current locale (/search, /es/search). */
|
|
35
|
+
searchPath: string;
|
|
36
|
+
preview: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** One search result: the page and the passage that matched, with the matched words marked. */
|
|
40
|
+
export interface SearchHit {
|
|
41
|
+
id: string;
|
|
42
|
+
title: string;
|
|
43
|
+
href: string;
|
|
44
|
+
snippet: { text: string; hit: boolean }[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SearchView {
|
|
48
|
+
q: string;
|
|
49
|
+
page: number;
|
|
50
|
+
pages: number;
|
|
51
|
+
total: number;
|
|
52
|
+
results: SearchHit[];
|
|
53
|
+
/** Set when Spillway could not answer the search. */
|
|
54
|
+
error?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type View =
|
|
58
|
+
| { kind: 'page'; shell: Shell; head: HeadData; body: string; scripts: string[] }
|
|
59
|
+
| { kind: 'search'; shell: Shell; head: HeadData; search: SearchView }
|
|
60
|
+
| { kind: 'not-found'; shell: Shell; head: HeadData };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Pages are rendered on the server and sent without SvelteKit's client scripts: Spillway's HTML brings the few scripts its
|
|
2
|
+
// blocks need, and links load the next page as a whole. Turn this on for a route when you add components that need to run
|
|
3
|
+
// in the browser; see README.md.
|
|
4
|
+
export const csr = false;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every path: a Spillway page with its block area as Spillway renders it, the search page (/search, /es/search), or a
|
|
3
|
+
* 404. src/lib/server/spillway.ts works out which and reads everything from Spillway; +page.svelte lays it out.
|
|
4
|
+
*/
|
|
5
|
+
import { resolveView } from '../../lib/server/spillway';
|
|
6
|
+
import type { PageServerLoad } from './$types';
|
|
7
|
+
|
|
8
|
+
export const load: PageServerLoad = async ({ url, request, locals, setHeaders }) => {
|
|
9
|
+
const view = await resolveView(url.pathname, Object.fromEntries(url.searchParams), request);
|
|
10
|
+
locals.lang = view.shell.lang;
|
|
11
|
+
locals.motion = view.head.motion;
|
|
12
|
+
locals.notFound = view.kind === 'not-found';
|
|
13
|
+
if (view.shell.preview) setHeaders({ 'cache-control': 'private, no-store' });
|
|
14
|
+
return { view };
|
|
15
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// The brand as the last build wrote it (scripts/brand.mjs, before every build): the --sw-* variables and fonts.
|
|
3
|
+
import builtBrandCss from '../../lib/spillway-brand.css?raw';
|
|
4
|
+
import SearchPage from '../../lib/components/SearchPage.svelte';
|
|
5
|
+
import SiteShell from '../../lib/components/SiteShell.svelte';
|
|
6
|
+
import type { PageProps } from './$types';
|
|
7
|
+
|
|
8
|
+
let { data }: PageProps = $props();
|
|
9
|
+
const view = $derived(data.view);
|
|
10
|
+
const head = $derived(view.head);
|
|
11
|
+
// The brand (one published since the last build arrives with the brand.published webhook and wins until the next build
|
|
12
|
+
// writes it), then Spillway's CSS for the page and the JSON-LD, as they are.
|
|
13
|
+
const styles = $derived([view.shell.brandCss ?? builtBrandCss, ...head.css].filter(Boolean).map((css) => `<style>${css}</style>`).join(''));
|
|
14
|
+
const jsonLd = $derived(head.jsonLd.map((ld: string) => `<script type="application/ld+json">${ld}</` + 'script>').join(''));
|
|
15
|
+
const scripts = $derived(view.kind === 'page' ? view.scripts.map((js: string) => `<script>${js}</` + 'script>').join('') : '');
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<svelte:head>
|
|
19
|
+
<title>{head.title}</title>
|
|
20
|
+
{#if head.description}
|
|
21
|
+
<meta name="description" content={head.description} />
|
|
22
|
+
<meta property="og:description" content={head.description} />
|
|
23
|
+
{/if}
|
|
24
|
+
<meta property="og:title" content={head.title} />
|
|
25
|
+
<meta property="og:type" content="website" />
|
|
26
|
+
<meta property="og:site_name" content={view.shell.siteName} />
|
|
27
|
+
{#if head.canonical}
|
|
28
|
+
<link rel="canonical" href={head.canonical} />
|
|
29
|
+
<meta property="og:url" content={head.canonical} />
|
|
30
|
+
{/if}
|
|
31
|
+
{#each head.alternates as a (a.hreflang)}
|
|
32
|
+
<link rel="alternate" hreflang={a.hreflang} href={a.href} />
|
|
33
|
+
{/each}
|
|
34
|
+
{#if head.ogImage}<meta property="og:image" content={head.ogImage} />{/if}
|
|
35
|
+
{#if head.noindex}<meta name="robots" content="noindex, nofollow" />{/if}
|
|
36
|
+
{@html styles}
|
|
37
|
+
{@html jsonLd}
|
|
38
|
+
{#if view.shell.suggestions}<script src="/spillway-suggest.js" defer></script>{/if}
|
|
39
|
+
</svelte:head>
|
|
40
|
+
|
|
41
|
+
<SiteShell shell={view.shell}>
|
|
42
|
+
{#if view.kind === 'page'}
|
|
43
|
+
<div class="spillway-page">{@html view.body}</div>
|
|
44
|
+
{:else if view.kind === 'search'}
|
|
45
|
+
<SearchPage search={view.search} shell={view.shell} />
|
|
46
|
+
{:else}
|
|
47
|
+
<section class="not-found">
|
|
48
|
+
<h1>Page not found</h1>
|
|
49
|
+
<p>There is no published page at this address. <a href="/">Go to the home page</a>.</p>
|
|
50
|
+
</section>
|
|
51
|
+
{/if}
|
|
52
|
+
</SiteShell>
|
|
53
|
+
<!-- The scripts the page's blocks need (the motion and media players), after the body. -->
|
|
54
|
+
{@html scripts}
|
|
@@ -0,0 +1,30 @@
|
|
|
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, so a cookie
|
|
10
|
+
* written by hand opens nothing) and opens the page on this site, never another one; /api/preview/exit removes it.
|
|
11
|
+
*/
|
|
12
|
+
import { PREVIEW_MAX_AGE, SpillwayError, checkPreviewRequest, previewCookieValue, safeRedirectUrl } from '@spillway-cms/client';
|
|
13
|
+
import { previewCookie } from '../../../lib/server/preview';
|
|
14
|
+
import { spillway } from '../../../lib/server/spillway';
|
|
15
|
+
import type { RequestHandler } from './$types';
|
|
16
|
+
|
|
17
|
+
export const GET: RequestHandler = async ({ request, url }) => {
|
|
18
|
+
const secret = spillway.options.previewSecret;
|
|
19
|
+
const check = checkPreviewRequest(request, { secret });
|
|
20
|
+
if (!check.ok) return Response.json({ error: check.error }, { status: check.status });
|
|
21
|
+
try {
|
|
22
|
+
await spillway.withPreview(check.state).render(check.path);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if (err instanceof SpillwayError && (err.status === 401 || err.status === 403)) return Response.json({ error: 'Preview credential refused' }, { status: 401 });
|
|
25
|
+
if (!(err instanceof SpillwayError && err.status === 404)) throw err; // a missing page still opens the preview
|
|
26
|
+
}
|
|
27
|
+
const headers = new Headers({ location: safeRedirectUrl(check.path, url.origin).href, 'cache-control': 'no-store' });
|
|
28
|
+
headers.append('set-cookie', previewCookie(previewCookieValue(check.state, { secret }), url.protocol === 'https:', secret ? PREVIEW_MAX_AGE : undefined));
|
|
29
|
+
return new Response(null, { status: 307, headers });
|
|
30
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { safeRedirectUrl } from '@spillway-cms/client';
|
|
2
|
+
import { previewCookie } from '../../../../lib/server/preview';
|
|
3
|
+
import type { RequestHandler } from './$types';
|
|
4
|
+
|
|
5
|
+
/** GET /api/preview/exit: ends the preview and goes back to the live home page. */
|
|
6
|
+
export const GET: RequestHandler = ({ url }) => {
|
|
7
|
+
const headers = new Headers({ location: safeRedirectUrl('/', url.origin).href, 'cache-control': 'no-store' });
|
|
8
|
+
headers.append('set-cookie', previewCookie('', url.protocol === 'https:', 0));
|
|
9
|
+
return new Response(null, { status: 307, headers });
|
|
10
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
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; create-spillway adds them when you give it a token.
|
|
5
|
+
*
|
|
6
|
+
* readWebhook checks the X-Spillway-Signature HMAC over the raw body (401 when it does not match); a test send is
|
|
7
|
+
* acknowledged and changes nothing. affectedByWebhook finds what the event touched (the page's path and Spillway's cache
|
|
8
|
+
* tags), and those pages leave the cache, with the site settings, brand, menus and redirects.
|
|
9
|
+
*/
|
|
10
|
+
import { WebhookError, affectedByWebhook, readWebhook, type WebhookPayload } from '@spillway-cms/client/webhook';
|
|
11
|
+
import { DEPLOY_HOOK_URL, SPILLWAY_WEBHOOK_SECRET } from '$app/env/private';
|
|
12
|
+
import { purge } from '../../../lib/server/cache';
|
|
13
|
+
import { SHELL_TAG } from '../../../lib/server/spillway';
|
|
14
|
+
import type { RequestHandler } from './$types';
|
|
15
|
+
|
|
16
|
+
export const POST: RequestHandler = async ({ request }) => {
|
|
17
|
+
if (!SPILLWAY_WEBHOOK_SECRET) return Response.json({ error: 'SPILLWAY_WEBHOOK_SECRET is not set' }, { status: 503 });
|
|
18
|
+
let payload: WebhookPayload;
|
|
19
|
+
try {
|
|
20
|
+
payload = await readWebhook(request, SPILLWAY_WEBHOOK_SECRET);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
if (err instanceof WebhookError) return Response.json({ error: err.message }, { status: err.status });
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
const affected = affectedByWebhook(payload);
|
|
26
|
+
if (affected.test) return Response.json({ ok: true, test: true });
|
|
27
|
+
const dropped = purge([...affected.tags, SHELL_TAG], affected.paths);
|
|
28
|
+
console.log(`[spillway] ${payload.event}: purged ${dropped} cached entries (paths ${affected.paths.join(', ') || '-'})`);
|
|
29
|
+
if (payload.event === 'brand.published') await rebuildForBrand(payload);
|
|
30
|
+
return Response.json({ ok: true, event: payload.event, paths: affected.paths, tags: affected.tags });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pages show a newly published brand at once (the view inlines it); a deploy hook makes the next build write it into
|
|
35
|
+
* src/lib/spillway-brand.css as well. Optional: set DEPLOY_HOOK_URL to your host's deploy hook.
|
|
36
|
+
*/
|
|
37
|
+
async function rebuildForBrand(payload: WebhookPayload): Promise<void> {
|
|
38
|
+
if (!DEPLOY_HOOK_URL) return;
|
|
39
|
+
try {
|
|
40
|
+
const res = await fetch(DEPLOY_HOOK_URL, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ source: 'spillway', event: payload.event, at: payload.at }) });
|
|
41
|
+
if (!res.ok) console.warn(`[spillway] the deploy hook answered ${res.status}`);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.warn(`[spillway] the deploy hook failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GET /api/search/suggest?q=&locale=: up to six published pages for what a visitor has typed, for the suggestions under
|
|
3
|
+
* search fields (static/spillway-suggest.js). Read as a visitor, so drafts never show.
|
|
4
|
+
*/
|
|
5
|
+
import { visitor } from '../../../../lib/server/spillway';
|
|
6
|
+
import type { RequestHandler } from './$types';
|
|
7
|
+
|
|
8
|
+
export const GET: RequestHandler = async ({ url }) => {
|
|
9
|
+
const q = (url.searchParams.get('q') ?? '').slice(0, 100);
|
|
10
|
+
const locale = url.searchParams.get('locale');
|
|
11
|
+
try {
|
|
12
|
+
return Response.json(await visitor.suggest(q, locale ? { locale } : {}), { headers: { 'cache-control': 'public, max-age=60' } });
|
|
13
|
+
} catch {
|
|
14
|
+
return Response.json({ q, items: [] });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SITE_URL } from '../../lib/server/spillway';
|
|
2
|
+
import type { RequestHandler } from './$types';
|
|
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: RequestHandler = () =>
|
|
6
|
+
new Response(`User-agent: *\nAllow: /\nDisallow: /api/\n\nSitemap: ${SITE_URL}/sitemap.xml\n`, { headers: { 'content-type': 'text/plain; charset=utf-8' } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PublicPath } from '@spillway-cms/client';
|
|
2
|
+
import { cached } from '../../lib/server/cache';
|
|
3
|
+
import { SHELL_TAG, SITE_URL, spillway } from '../../lib/server/spillway';
|
|
4
|
+
import type { RequestHandler } from './$types';
|
|
5
|
+
|
|
6
|
+
const esc = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
7
|
+
|
|
8
|
+
/** /sitemap.xml from every published path in Spillway, on this front end's address. */
|
|
9
|
+
export const GET: RequestHandler = async () => {
|
|
10
|
+
let paths: PublicPath[] = [];
|
|
11
|
+
try {
|
|
12
|
+
paths = await cached('paths', async () => ({ value: await spillway.paths(), tags: [SHELL_TAG] }));
|
|
13
|
+
} catch {
|
|
14
|
+
// Spillway is not reachable: an empty sitemap rather than an error
|
|
15
|
+
}
|
|
16
|
+
const urls = paths.map((p) => ` <url><loc>${esc(`${SITE_URL}${p.path === '/' ? '' : p.path}`)}</loc><lastmod>${esc(p.updatedAt)}</lastmod></url>`);
|
|
17
|
+
const body = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.join('\n')}\n</urlset>\n`;
|
|
18
|
+
return new Response(body, { headers: { 'content-type': 'application/xml; charset=utf-8' } });
|
|
19
|
+
};
|
|
@@ -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
|
+
})();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import adapter from '@sveltejs/adapter-node';
|
|
2
|
+
import { sveltekit } from '@sveltejs/kit/vite';
|
|
3
|
+
import { defineConfig } from 'vite';
|
|
4
|
+
|
|
5
|
+
// Server output on the Node adapter: every page is rendered on request from Spillway's content and cached in memory
|
|
6
|
+
// (src/lib/server/cache.ts) until a webhook says it changed. `npm start` runs the build with .env loaded.
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [
|
|
9
|
+
sveltekit({
|
|
10
|
+
compilerOptions: {
|
|
11
|
+
// Force runes mode for the project, except for libraries. Can be removed in svelte 6.
|
|
12
|
+
runes: ({ filename }) => (filename.split(/[/\\]/).includes('node_modules') ? undefined : true),
|
|
13
|
+
},
|
|
14
|
+
adapter: adapter(),
|
|
15
|
+
}),
|
|
16
|
+
],
|
|
17
|
+
});
|