create-spillway 0.1.26 → 0.1.28
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 +3 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/templates/astro/.env.example +6 -0
- package/templates/astro/README.md +29 -6
- package/templates/astro/astro.config.mjs +46 -5
- package/templates/astro/package.json +3 -0
- package/templates/astro/public/spillway-search.js +85 -0
- package/templates/astro/public/spillway-suggest.js +10 -3
- package/templates/astro/src/layouts/Layout.astro +19 -7
- package/templates/astro/src/lib/output.ts +28 -0
- package/templates/astro/src/lib/spillway.ts +10 -4
- package/templates/astro/src/lib/static-paths.ts +26 -0
- package/templates/astro/src/middleware.ts +4 -2
- package/templates/astro/src/pages/[...path].astro +26 -8
- package/templates/next/.env.example +6 -0
- package/templates/next/README.md +30 -7
- package/templates/next/app/[[...slug]]/page.static.tsx +103 -0
- package/templates/next/app/layout.tsx +8 -4
- package/templates/next/app/not-found.tsx +3 -2
- package/templates/next/app/robots.ts +3 -0
- package/templates/next/app/sitemap.ts +3 -0
- package/templates/next/components/MembersOnly.tsx +10 -1
- package/templates/next/components/Nav.tsx +7 -4
- package/templates/next/components/SiteShell.tsx +24 -7
- package/templates/next/components/StaticSearchPage.tsx +35 -0
- package/templates/next/lib/output.ts +36 -0
- package/templates/next/lib/spillway.ts +7 -9
- package/templates/next/next.config.ts +37 -4
- package/templates/next/package.json +3 -0
- package/templates/next/public/spillway-search.js +85 -0
- package/templates/next/public/spillway-suggest.js +10 -3
- package/templates/nuxt/README.md +2 -0
- package/templates/nuxt/package.json +3 -0
- package/templates/nuxt/public/spillway-suggest.js +10 -3
- package/templates/sveltekit/README.md +2 -0
- package/templates/sveltekit/package.json +3 -0
- package/templates/sveltekit/static/spillway-suggest.js +10 -3
- /package/templates/astro/src/{pages → server-routes}/api/preview/exit.ts +0 -0
- /package/templates/astro/src/{pages → server-routes}/api/preview/index.ts +0 -0
- /package/templates/astro/src/{pages → server-routes}/api/revalidate.ts +0 -0
- /package/templates/astro/src/{pages → server-routes}/api/search/suggest.ts +0 -0
- /package/templates/astro/src/{pages → server-routes}/auth/callback.ts +0 -0
- /package/templates/astro/src/{pages → server-routes}/auth/login.ts +0 -0
- /package/templates/astro/src/{pages → server-routes}/auth/logout.ts +0 -0
- /package/templates/next/app/[[...slug]]/{page.tsx → page.server.tsx} +0 -0
- /package/templates/next/app/api/preview/exit/{route.ts → route.server.ts} +0 -0
- /package/templates/next/app/api/preview/{route.ts → route.server.ts} +0 -0
- /package/templates/next/app/api/revalidate/{route.ts → route.server.ts} +0 -0
- /package/templates/next/app/api/search/suggest/{route.ts → route.server.ts} +0 -0
- /package/templates/next/app/auth/callback/{route.ts → route.server.ts} +0 -0
- /package/templates/next/app/auth/login/{route.ts → route.server.ts} +0 -0
- /package/templates/next/app/auth/logout/{route.ts → route.server.ts} +0 -0
- /package/templates/next/app/member/[[...slug]]/{page.tsx → page.server.tsx} +0 -0
- /package/templates/next/app/search/{page.tsx → page.server.tsx} +0 -0
- /package/templates/next/{proxy.ts → proxy.server.ts} +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The search results with static output (README.md, Static output): the page is a file, so the browser reads the results
|
|
3
|
+
* itself from the Spillway site's public search (GET /api/search, published pages only, no cookies sent) for the words in
|
|
4
|
+
* the address (?q=, &page=), and shows them as the server-rendered search page does: the count, each page with the
|
|
5
|
+
* passage that matched (the matched words marked), and a pager. Text is set with textContent, never parsed as HTML.
|
|
6
|
+
*/
|
|
7
|
+
(function () {
|
|
8
|
+
var d = document;
|
|
9
|
+
function run() {
|
|
10
|
+
var box = d.querySelector('[data-sw-search-results]');
|
|
11
|
+
if (!box) return;
|
|
12
|
+
var endpoint = box.getAttribute('data-sw-endpoint') || '';
|
|
13
|
+
var locale = box.getAttribute('data-sw-locale') || '';
|
|
14
|
+
var base = box.getAttribute('data-sw-base') || '';
|
|
15
|
+
var params = new URLSearchParams(location.search);
|
|
16
|
+
var q = (params.get('q') || '').trim().slice(0, 200);
|
|
17
|
+
var page = Math.max(1, Math.min(100, parseInt(params.get('page') || '1', 10) || 1));
|
|
18
|
+
var field = box.parentNode && box.parentNode.querySelector('input[name="q"]');
|
|
19
|
+
if (field && q) field.value = q;
|
|
20
|
+
if (!q || !endpoint) return;
|
|
21
|
+
var url = endpoint + '?q=' + encodeURIComponent(q) + '&page=' + page + '&limit=10' + (locale ? '&locale=' + encodeURIComponent(locale) : '');
|
|
22
|
+
fetch(url, { headers: { accept: 'application/json' }, credentials: 'omit' })
|
|
23
|
+
.then(function (res) {
|
|
24
|
+
if (!res.ok) throw new Error(String(res.status));
|
|
25
|
+
return res.json();
|
|
26
|
+
})
|
|
27
|
+
.then(function (body) {
|
|
28
|
+
show(box, q, page, base, body || {});
|
|
29
|
+
})
|
|
30
|
+
.catch(function () {
|
|
31
|
+
box.textContent = '';
|
|
32
|
+
var p = d.createElement('p');
|
|
33
|
+
p.setAttribute('role', 'alert');
|
|
34
|
+
p.textContent = 'Search is not available right now. Please try again later.';
|
|
35
|
+
box.appendChild(p);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function el(tag, attrs, text) {
|
|
39
|
+
var node = d.createElement(tag);
|
|
40
|
+
for (var k in attrs) node.setAttribute(k, attrs[k]);
|
|
41
|
+
if (text !== undefined) node.textContent = text;
|
|
42
|
+
return node;
|
|
43
|
+
}
|
|
44
|
+
function show(box, q, page, base, body) {
|
|
45
|
+
var items = (body.items || []).filter(function (r) {
|
|
46
|
+
return typeof r.path === 'string' && r.path.charAt(0) === '/';
|
|
47
|
+
});
|
|
48
|
+
var total = body.total || 0;
|
|
49
|
+
var pages = Math.ceil(total / (body.limit || 10));
|
|
50
|
+
box.textContent = '';
|
|
51
|
+
box.appendChild(el('p', { role: 'status' }, (total === 1 ? '1 result' : total + ' results') + ' for “' + q + '”'));
|
|
52
|
+
if (items.length) {
|
|
53
|
+
var list = el('ol', { class: 'search-results' });
|
|
54
|
+
items.forEach(function (r) {
|
|
55
|
+
var li = d.createElement('li');
|
|
56
|
+
var h = d.createElement('h2');
|
|
57
|
+
h.appendChild(el('a', { href: base + r.path }, r.title));
|
|
58
|
+
li.appendChild(h);
|
|
59
|
+
// Spillway marks the matched words in a snippet «like this».
|
|
60
|
+
var parts = String(r.snippet || '').split(/[«»]/);
|
|
61
|
+
if (parts.join('')) {
|
|
62
|
+
var p = d.createElement('p');
|
|
63
|
+
parts.forEach(function (text, i) {
|
|
64
|
+
if (text) p.appendChild(i % 2 === 1 ? el('mark', {}, text) : d.createTextNode(text));
|
|
65
|
+
});
|
|
66
|
+
li.appendChild(p);
|
|
67
|
+
}
|
|
68
|
+
list.appendChild(li);
|
|
69
|
+
});
|
|
70
|
+
box.appendChild(list);
|
|
71
|
+
}
|
|
72
|
+
if (pages > 1) {
|
|
73
|
+
var nav = el('nav', { class: 'search-pager', 'aria-label': 'Result pages' });
|
|
74
|
+
var link = function (n) {
|
|
75
|
+
return location.pathname + '?q=' + encodeURIComponent(q) + (n > 1 ? '&page=' + n : '');
|
|
76
|
+
};
|
|
77
|
+
if (page > 1) nav.appendChild(el('a', { href: link(page - 1), rel: 'prev' }, 'Previous'));
|
|
78
|
+
nav.appendChild(el('span', {}, 'Page ' + page + ' of ' + pages));
|
|
79
|
+
if (page < pages) nav.appendChild(el('a', { href: link(page + 1), rel: 'next' }, 'Next'));
|
|
80
|
+
box.appendChild(nav);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (d.readyState === 'loading') d.addEventListener('DOMContentLoaded', run);
|
|
84
|
+
else run();
|
|
85
|
+
})();
|
|
@@ -4,10 +4,17 @@
|
|
|
4
4
|
* end's /api/search/suggest, which reads Spillway's published pages, and shows them as a list under the field: the arrow
|
|
5
5
|
* keys move through it, Enter opens the highlighted page, Escape closes it. Without this script the field is a plain
|
|
6
6
|
* search form. Text is set with textContent, never parsed as HTML.
|
|
7
|
+
*
|
|
8
|
+
* With static output there is no /api/search/suggest here: the script tag names Spillway's own public endpoint
|
|
9
|
+
* (data-sw-endpoint), which the browser asks directly without cookies, and the base path the pages live under
|
|
10
|
+
* (data-sw-base).
|
|
7
11
|
*/
|
|
8
12
|
(function () {
|
|
9
13
|
var d = document;
|
|
10
14
|
var count = 0;
|
|
15
|
+
var tag = d.currentScript;
|
|
16
|
+
var endpoint = (tag && tag.getAttribute('data-sw-endpoint')) || '/api/search/suggest';
|
|
17
|
+
var base = (tag && tag.getAttribute('data-sw-base')) || '';
|
|
11
18
|
function bind(input) {
|
|
12
19
|
if (input.hasAttribute('data-sw-bound') || !input.form) return;
|
|
13
20
|
input.setAttribute('data-sw-bound', '');
|
|
@@ -65,7 +72,7 @@
|
|
|
65
72
|
li.className = 'sw-suggest__item';
|
|
66
73
|
li.setAttribute('role', 'option');
|
|
67
74
|
li.setAttribute('aria-selected', 'false');
|
|
68
|
-
a.href = item.path;
|
|
75
|
+
a.href = base + item.path;
|
|
69
76
|
a.tabIndex = -1;
|
|
70
77
|
title.className = 'sw-suggest__title';
|
|
71
78
|
title.textContent = item.title;
|
|
@@ -88,8 +95,8 @@
|
|
|
88
95
|
if (q === asked) return;
|
|
89
96
|
asked = q;
|
|
90
97
|
if (q.length < 2) return show([]);
|
|
91
|
-
var url = '
|
|
92
|
-
fetch(url, { headers: { accept: 'application/json' } })
|
|
98
|
+
var url = endpoint + '?q=' + encodeURIComponent(q) + (locale ? '&locale=' + encodeURIComponent(locale) : '');
|
|
99
|
+
fetch(url, { headers: { accept: 'application/json' }, credentials: 'same-origin' })
|
|
93
100
|
.then(function (res) {
|
|
94
101
|
return res.ok ? res.json() : { items: [] };
|
|
95
102
|
})
|
package/templates/nuxt/README.md
CHANGED
|
@@ -78,4 +78,6 @@ npm start # node .output/server/index.mjs with .env loaded; PORT and HO
|
|
|
78
78
|
|
|
79
79
|
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`).
|
|
80
80
|
|
|
81
|
+
This starter needs a server. Static output (`SPILLWAY_OUTPUT=static`, plain files for a host that only serves files) is in the Next.js and Astro starters for now.
|
|
82
|
+
|
|
81
83
|
See [the headless docs](https://github.com/kwall-llc/spillway-cms/blob/main/docs/adapters.md) for the API and the starters.
|
|
@@ -4,10 +4,17 @@
|
|
|
4
4
|
* end's /api/search/suggest, which reads Spillway's published pages, and shows them as a list under the field: the arrow
|
|
5
5
|
* keys move through it, Enter opens the highlighted page, Escape closes it. Without this script the field is a plain
|
|
6
6
|
* search form. Text is set with textContent, never parsed as HTML.
|
|
7
|
+
*
|
|
8
|
+
* With static output there is no /api/search/suggest here: the script tag names Spillway's own public endpoint
|
|
9
|
+
* (data-sw-endpoint), which the browser asks directly without cookies, and the base path the pages live under
|
|
10
|
+
* (data-sw-base).
|
|
7
11
|
*/
|
|
8
12
|
(function () {
|
|
9
13
|
var d = document;
|
|
10
14
|
var count = 0;
|
|
15
|
+
var tag = d.currentScript;
|
|
16
|
+
var endpoint = (tag && tag.getAttribute('data-sw-endpoint')) || '/api/search/suggest';
|
|
17
|
+
var base = (tag && tag.getAttribute('data-sw-base')) || '';
|
|
11
18
|
function bind(input) {
|
|
12
19
|
if (input.hasAttribute('data-sw-bound') || !input.form) return;
|
|
13
20
|
input.setAttribute('data-sw-bound', '');
|
|
@@ -65,7 +72,7 @@
|
|
|
65
72
|
li.className = 'sw-suggest__item';
|
|
66
73
|
li.setAttribute('role', 'option');
|
|
67
74
|
li.setAttribute('aria-selected', 'false');
|
|
68
|
-
a.href = item.path;
|
|
75
|
+
a.href = base + item.path;
|
|
69
76
|
a.tabIndex = -1;
|
|
70
77
|
title.className = 'sw-suggest__title';
|
|
71
78
|
title.textContent = item.title;
|
|
@@ -88,8 +95,8 @@
|
|
|
88
95
|
if (q === asked) return;
|
|
89
96
|
asked = q;
|
|
90
97
|
if (q.length < 2) return show([]);
|
|
91
|
-
var url = '
|
|
92
|
-
fetch(url, { headers: { accept: 'application/json' } })
|
|
98
|
+
var url = endpoint + '?q=' + encodeURIComponent(q) + (locale ? '&locale=' + encodeURIComponent(locale) : '');
|
|
99
|
+
fetch(url, { headers: { accept: 'application/json' }, credentials: 'same-origin' })
|
|
93
100
|
.then(function (res) {
|
|
94
101
|
return res.ok ? res.json() : { items: [] };
|
|
95
102
|
})
|
|
@@ -78,4 +78,6 @@ npm start # node build with .env loaded; PORT and HOST set the address
|
|
|
78
78
|
|
|
79
79
|
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/routes/api/revalidate/+server.ts` too (`affected.tags` are the tags Spillway sends as `Cache-Tag`). For a serverless host, swap `@sveltejs/adapter-node` for that host's adapter.
|
|
80
80
|
|
|
81
|
+
This starter needs a server. Static output (`SPILLWAY_OUTPUT=static`, plain files for a host that only serves files) is in the Next.js and Astro starters for now.
|
|
82
|
+
|
|
81
83
|
See [the headless docs](https://github.com/kwall-llc/spillway-cms/blob/main/docs/adapters.md) for the API and the starters.
|
|
@@ -4,10 +4,17 @@
|
|
|
4
4
|
* end's /api/search/suggest, which reads Spillway's published pages, and shows them as a list under the field: the arrow
|
|
5
5
|
* keys move through it, Enter opens the highlighted page, Escape closes it. Without this script the field is a plain
|
|
6
6
|
* search form. Text is set with textContent, never parsed as HTML.
|
|
7
|
+
*
|
|
8
|
+
* With static output there is no /api/search/suggest here: the script tag names Spillway's own public endpoint
|
|
9
|
+
* (data-sw-endpoint), which the browser asks directly without cookies, and the base path the pages live under
|
|
10
|
+
* (data-sw-base).
|
|
7
11
|
*/
|
|
8
12
|
(function () {
|
|
9
13
|
var d = document;
|
|
10
14
|
var count = 0;
|
|
15
|
+
var tag = d.currentScript;
|
|
16
|
+
var endpoint = (tag && tag.getAttribute('data-sw-endpoint')) || '/api/search/suggest';
|
|
17
|
+
var base = (tag && tag.getAttribute('data-sw-base')) || '';
|
|
11
18
|
function bind(input) {
|
|
12
19
|
if (input.hasAttribute('data-sw-bound') || !input.form) return;
|
|
13
20
|
input.setAttribute('data-sw-bound', '');
|
|
@@ -65,7 +72,7 @@
|
|
|
65
72
|
li.className = 'sw-suggest__item';
|
|
66
73
|
li.setAttribute('role', 'option');
|
|
67
74
|
li.setAttribute('aria-selected', 'false');
|
|
68
|
-
a.href = item.path;
|
|
75
|
+
a.href = base + item.path;
|
|
69
76
|
a.tabIndex = -1;
|
|
70
77
|
title.className = 'sw-suggest__title';
|
|
71
78
|
title.textContent = item.title;
|
|
@@ -88,8 +95,8 @@
|
|
|
88
95
|
if (q === asked) return;
|
|
89
96
|
asked = q;
|
|
90
97
|
if (q.length < 2) return show([]);
|
|
91
|
-
var url = '
|
|
92
|
-
fetch(url, { headers: { accept: 'application/json' } })
|
|
98
|
+
var url = endpoint + '?q=' + encodeURIComponent(q) + (locale ? '&locale=' + encodeURIComponent(locale) : '');
|
|
99
|
+
fetch(url, { headers: { accept: 'application/json' }, credentials: 'same-origin' })
|
|
93
100
|
.then(function (res) {
|
|
94
101
|
return res.ok ? res.json() : { items: [] };
|
|
95
102
|
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|