inlaycms 0.2.0 → 0.3.0
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 +330 -1
- package/assets/admin/admin.css +1 -1
- package/assets/admin/admin.js +1 -1
- package/assets/admin/editor.js +59 -44
- package/dist/adapters/admin/screens/redirects.js +12 -3
- package/dist/adapters/admin/views/layout.js +27 -7
- package/dist/adapters/cli/remote.js +9 -1
- package/dist/adapters/mcp/tools/redirects.js +16 -2
- package/dist/adapters/site/assets.d.ts +11 -0
- package/dist/adapters/site/assets.js +71 -0
- package/dist/adapters/site/cache.d.ts +2 -1
- package/dist/adapters/site/cache.js +6 -1
- package/dist/adapters/site/context.d.ts +6 -0
- package/dist/adapters/site/context.js +38 -13
- package/dist/adapters/site/head.d.ts +30 -7
- package/dist/adapters/site/head.js +145 -20
- package/dist/adapters/site/headers.d.ts +5 -0
- package/dist/adapters/site/headers.js +31 -0
- package/dist/adapters/site/plugin.d.ts +2 -0
- package/dist/adapters/site/plugin.js +32 -9
- package/dist/adapters/site/public.js +7 -24
- package/dist/adapters/site/render.d.ts +5 -0
- package/dist/adapters/site/render.js +23 -8
- package/dist/adapters/site/routes.d.ts +6 -0
- package/dist/adapters/site/routes.js +8 -3
- package/dist/adapters/site/seo.d.ts +20 -0
- package/dist/adapters/site/seo.js +45 -0
- package/dist/adapters/site/sitemap.d.ts +1 -1
- package/dist/adapters/site/sitemap.js +1 -1
- package/dist/config.js +3 -2
- package/dist/core/agent/format.js +1 -1
- package/dist/core/agent/schema.js +3 -0
- package/dist/core/boot.js +7 -0
- package/dist/core/check.js +6 -1
- package/dist/core/content/dry-run.d.ts +7 -6
- package/dist/core/content/dry-run.js +8 -8
- package/dist/core/content/publish.d.ts +1 -1
- package/dist/core/content/publish.js +5 -3
- package/dist/core/content/read.d.ts +3 -0
- package/dist/core/content/reader.js +3 -2
- package/dist/core/content/refs.js +1 -1
- package/dist/core/content/search.js +2 -2
- package/dist/core/content/shipped-images.d.ts +32 -0
- package/dist/core/content/shipped-images.js +62 -0
- package/dist/core/content/shipped-input.d.ts +9 -3
- package/dist/core/content/shipped-input.js +165 -28
- package/dist/core/content/shipped.js +8 -3
- package/dist/core/content/validate.js +7 -1
- package/dist/core/core.d.ts +5 -1
- package/dist/core/core.js +5 -4
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +13 -1
- package/dist/core/db/migrate.js +2 -0
- package/dist/core/db/migrations/0007_published_at.d.ts +3 -0
- package/dist/core/db/migrations/0007_published_at.js +16 -0
- package/dist/core/db/schema.d.ts +1 -0
- package/dist/core/export/export.js +3 -1
- package/dist/core/export/format.d.ts +8 -1
- package/dist/core/export/format.js +3 -2
- package/dist/core/export/read.js +7 -0
- package/dist/core/export/stage.d.ts +1 -1
- package/dist/core/export/stage.js +24 -1
- package/dist/core/fields/builtins.d.ts +28 -0
- package/dist/core/fields/builtins.js +103 -11
- package/dist/core/fields/define.d.ts +6 -0
- package/dist/core/fields/widgets.d.ts +7 -0
- package/dist/core/fields/widgets.js +76 -28
- package/dist/core/messages/en.d.ts +70 -6
- package/dist/core/messages/en.js +70 -6
- package/dist/core/redirects/collapse.d.ts +17 -1
- package/dist/core/redirects/collapse.js +19 -3
- package/dist/core/redirects/redirects.d.ts +13 -12
- package/dist/core/redirects/redirects.js +141 -53
- package/dist/core/redirects/rule.d.ts +25 -0
- package/dist/core/redirects/rule.js +55 -0
- package/dist/core/registry/define.d.ts +40 -0
- package/dist/core/registry/define.js +3 -0
- package/dist/core/registry/registry.d.ts +21 -0
- package/dist/core/registry/registry.js +114 -6
- package/dist/core/registry/render.d.ts +37 -1
- package/dist/core/registry/route.d.ts +4 -0
- package/dist/core/release/bundle.js +30 -5
- package/dist/core/release/manifest.d.ts +14 -0
- package/dist/core/release/manifest.js +42 -17
- package/dist/core/release/markdown-file.d.ts +21 -0
- package/dist/core/release/markdown-file.js +172 -0
- package/dist/core/release/pack.js +2 -2
- package/dist/core/release/read.js +4 -1
- package/dist/core/release/site-dir.d.ts +4 -0
- package/dist/core/release/site-dir.js +8 -0
- package/dist/core/report.d.ts +8 -2
- package/dist/core/richtext/html.d.ts +3 -1
- package/dist/core/richtext/html.js +16 -4
- package/dist/core/richtext/inline.d.ts +22 -0
- package/dist/core/richtext/inline.js +33 -0
- package/dist/core/richtext/markdown.d.ts +16 -1
- package/dist/core/richtext/markdown.js +137 -14
- package/dist/core/richtext/schema.d.ts +16 -4
- package/dist/core/richtext/schema.js +71 -1
- package/dist/core/site/live.d.ts +1 -0
- package/dist/core/site/live.js +1 -0
- package/dist/core/site/paths.d.ts +6 -0
- package/dist/core/site/paths.js +13 -0
- package/dist/core/site/resolve.d.ts +1 -1
- package/dist/core/site/resolve.js +119 -30
- package/dist/core/site/sitemap.d.ts +1 -1
- package/dist/core/site/sitemap.js +4 -0
- package/dist/core/types.d.ts +28 -3
- package/dist/host/app.d.ts +5 -0
- package/dist/host/app.js +8 -0
- package/dist/host/dev.js +3 -7
- package/dist/host/diff.d.ts +19 -1
- package/dist/host/diff.js +32 -2
- package/dist/index.d.ts +2 -2
- package/dist/markdown-modules.d.ts +8 -0
- package/dist/markdown-modules.js +1 -0
- package/dist/site.d.ts +8 -3
- package/dist/site.js +6 -0
- package/dist/testing.d.ts +22 -0
- package/dist/testing.js +155 -0
- package/package.json +6 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { sql } from 'kysely';
|
|
2
|
-
import {
|
|
2
|
+
import { nextHops, pathTarget, ruleIndex } from '../redirects/collapse.js';
|
|
3
|
+
import { isUrlTarget } from '../redirects/rule.js';
|
|
3
4
|
import { liveDocuments, liveQuery, liveSingleton } from './live.js';
|
|
4
|
-
import { encodePath, normalizePath, routeRegExp, singletonPath, splitLocale } from './paths.js';
|
|
5
|
+
import { encodePath, lowercaseFallback, normalizePath, routeRegExp, singletonPath, splitLocale } from './paths.js';
|
|
5
6
|
const notFound = (locale) => ({ kind: 'not_found', locale });
|
|
6
7
|
const page = (document) => ({ kind: 'page', document });
|
|
7
8
|
const redirect = (path) => ({ kind: 'redirect', location: encodePath(path), status: 301 });
|
|
@@ -48,47 +49,65 @@ async function matchIndex(deps) {
|
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* Where a rule sends a request in `locale`: a document target is its URL in `locale` (`null` when it
|
|
51
|
-
* isn't live there); a
|
|
52
|
-
* matched the unprefixed rest.
|
|
52
|
+
* isn't live there); a URL target is that URL as stored, on another site; a path target gets its params
|
|
53
|
+
* filled in, and the locale prefix when the rule matched the unprefixed rest.
|
|
53
54
|
*/
|
|
54
55
|
async function ruleTarget(deps, candidate, locale, opts) {
|
|
55
56
|
const { rule } = candidate;
|
|
56
57
|
if (rule.to_group_id !== null) {
|
|
57
|
-
|
|
58
|
+
const path = (await liveDocuments(deps, [rule.to_group_id], locale, opts)).get(rule.to_group_id)?.path ?? null;
|
|
59
|
+
return path === null ? null : { target: path, external: false };
|
|
58
60
|
}
|
|
59
61
|
if (rule.to_path === null)
|
|
60
62
|
return null;
|
|
61
|
-
|
|
63
|
+
if (isUrlTarget(rule.to_path))
|
|
64
|
+
return { target: rule.to_path, external: true };
|
|
65
|
+
return { target: pathTarget(deps.registry, locale, rule.to_path, candidate), external: false };
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
64
|
-
* The rules that would answer a request for `path`, in `
|
|
65
|
-
* pattern rules
|
|
68
|
+
* The rules that would answer a request for `path`, in `nextHops` order: admin rules then code
|
|
69
|
+
* rules, each with exact rules before pattern rules, and last the lowercase fallback when `path`
|
|
70
|
+
* has one. Rules whose target isn't live, or is `path` itself, are skipped.
|
|
66
71
|
*/
|
|
67
|
-
async function* firing(deps,
|
|
68
|
-
for (const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
async function* firing(deps, sets, path, locale, opts) {
|
|
73
|
+
for (const hop of nextHops(deps.registry, sets, path)) {
|
|
74
|
+
if ('fallback' in hop) {
|
|
75
|
+
yield hop;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const to = await ruleTarget(deps, hop.candidate, locale, opts);
|
|
79
|
+
if (to !== null && to.target !== path)
|
|
80
|
+
yield { rule: hop.candidate.rule, ...to };
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
/** The most redirects followed when checking that a redirect doesn't lead round in a loop. */
|
|
75
84
|
const MAX_HOPS = 32;
|
|
76
85
|
/**
|
|
77
86
|
* Follows a visitor sent from `start` to `fired.target`, answering each request as `resolvePath`
|
|
78
|
-
* would (pages, normalizing redirects, then the first rule that fires
|
|
79
|
-
* rules passed if a path comes round again, or
|
|
87
|
+
* would (a GET code route, pages, normalizing redirects, then the first rule that fires or else the
|
|
88
|
+
* lowercase fallback), and gives the `from` of the rules passed if a path comes round again, or
|
|
89
|
+
* `null` when the chain ends (at a code route, a page, a not-found or another site) or runs past
|
|
90
|
+
* `MAX_HOPS`.
|
|
80
91
|
*/
|
|
81
|
-
async function loopFrom(deps,
|
|
92
|
+
async function loopFrom(deps, sets, start, fired, opts) {
|
|
93
|
+
if (fired.external)
|
|
94
|
+
return null;
|
|
82
95
|
const seen = new Set([start]);
|
|
83
96
|
const rules = [fired.rule.from];
|
|
84
97
|
let path = fired.target;
|
|
85
98
|
for (let hops = 0; hops < MAX_HOPS; hops++) {
|
|
99
|
+
if (deps.registry.getRoutePaths.has(path))
|
|
100
|
+
return null;
|
|
86
101
|
if (seen.has(path))
|
|
87
102
|
return rules;
|
|
88
103
|
seen.add(path);
|
|
89
104
|
const res = await resolveSite(deps, encodePath(path), opts);
|
|
90
105
|
if (res.kind === 'page' || res.kind === 'not_found')
|
|
91
106
|
return null;
|
|
107
|
+
if (res.kind === 'canonical') {
|
|
108
|
+
path = res.canonical;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
92
111
|
if (res.kind === 'redirect') {
|
|
93
112
|
const next = normalizePath(res.location);
|
|
94
113
|
if (next === null)
|
|
@@ -96,25 +115,37 @@ async function loopFrom(deps, index, start, fired, opts) {
|
|
|
96
115
|
path = next;
|
|
97
116
|
continue;
|
|
98
117
|
}
|
|
99
|
-
const { value: next } = await firing(deps,
|
|
118
|
+
const { value: next } = await firing(deps, sets, res.path, res.locale, opts).next();
|
|
100
119
|
if (!next)
|
|
101
120
|
return null;
|
|
121
|
+
if ('fallback' in next) {
|
|
122
|
+
path = next.fallback;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (next.external)
|
|
126
|
+
return null;
|
|
102
127
|
rules.push(next.rule.from);
|
|
103
128
|
path = next.target;
|
|
104
129
|
}
|
|
105
130
|
return null;
|
|
106
131
|
}
|
|
107
132
|
/**
|
|
108
|
-
* The first redirect rule that applies, as `firing` gives them
|
|
109
|
-
* visitor round in a loop. `not_found` with `loop` when only such rules fire.
|
|
133
|
+
* The first redirect rule that applies, as `firing` gives them up to the lowercase fallback, skipping
|
|
134
|
+
* any that would send the visitor round in a loop. `not_found` with `loop` when only such rules fire.
|
|
110
135
|
*/
|
|
111
136
|
async function matchRedirect(deps, at, opts) {
|
|
112
|
-
const
|
|
137
|
+
const sets = [await matchIndex(deps), deps.registry.redirectIndex];
|
|
113
138
|
const loop = new Set();
|
|
114
|
-
for await (const fired of firing(deps,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
for await (const fired of firing(deps, sets, at.path, at.locale, opts)) {
|
|
140
|
+
if ('fallback' in fired)
|
|
141
|
+
break;
|
|
142
|
+
const rules = await loopFrom(deps, sets, at.path, fired, opts);
|
|
143
|
+
if (rules === null) {
|
|
144
|
+
const { target, rule } = fired;
|
|
145
|
+
return fired.external
|
|
146
|
+
? { kind: 'redirect', location: target, status: rule.status, external: true }
|
|
147
|
+
: { kind: 'redirect', location: encodePath(target), status: rule.status };
|
|
148
|
+
}
|
|
118
149
|
for (const from of rules)
|
|
119
150
|
loop.add(from);
|
|
120
151
|
}
|
|
@@ -126,21 +157,79 @@ function lookupLocales(deps, locale) {
|
|
|
126
157
|
/** Resolves a still-encoded URL path (no query string) to a page, a redirect or not-found. */
|
|
127
158
|
export async function resolvePath(deps, rawPath, opts = {}) {
|
|
128
159
|
const res = await resolveSite(deps, rawPath, opts);
|
|
160
|
+
if (res.kind === 'canonical') {
|
|
161
|
+
// A mixed-case path that would 404 once canonical goes where the lowercase fallback lands, in one 301.
|
|
162
|
+
const { canonical } = res;
|
|
163
|
+
const lower = lowercaseFallback(canonical);
|
|
164
|
+
if (lower !== null &&
|
|
165
|
+
!deps.registry.getRoutePaths.has(canonical) &&
|
|
166
|
+
(await resolveRules(deps, encodePath(canonical), opts)).kind === 'not_found') {
|
|
167
|
+
return (await landing(deps, lower, opts)) ?? redirect(canonical);
|
|
168
|
+
}
|
|
169
|
+
return redirect(canonical);
|
|
170
|
+
}
|
|
129
171
|
if (res.kind !== 'rules')
|
|
130
172
|
return res;
|
|
131
|
-
// 7. Redirect rules.
|
|
173
|
+
// 7. Redirect rules: the admin's (7a), then the site's code rules (7b).
|
|
132
174
|
const rule = await matchRedirect(deps, res, opts);
|
|
133
|
-
if (rule)
|
|
175
|
+
if (rule?.kind === 'redirect')
|
|
134
176
|
return rule;
|
|
135
|
-
// 8.
|
|
136
|
-
|
|
177
|
+
// 8. Lowercase fallback.
|
|
178
|
+
const lower = lowercaseFallback(res.path);
|
|
179
|
+
const landed = lower === null ? null : await landing(deps, lower, opts);
|
|
180
|
+
if (landed)
|
|
181
|
+
return landed;
|
|
182
|
+
// 9. Not found.
|
|
183
|
+
return rule ?? notFound(res.locale);
|
|
184
|
+
}
|
|
185
|
+
/** Steps 1–7b of `resolvePath`: everything but the lowercase fallback. */
|
|
186
|
+
async function resolveRules(deps, rawPath, opts) {
|
|
187
|
+
const res = await resolveSite(deps, rawPath, opts);
|
|
188
|
+
if (res.kind === 'canonical')
|
|
189
|
+
return redirect(res.canonical);
|
|
190
|
+
if (res.kind !== 'rules')
|
|
191
|
+
return res;
|
|
192
|
+
return (await matchRedirect(deps, res, opts)) ?? notFound(res.locale);
|
|
137
193
|
}
|
|
138
194
|
/**
|
|
139
|
-
*
|
|
195
|
+
* Where the lowercase fallback for a request lands, given its lowercase form `lower`: a GET code
|
|
196
|
+
* route or a page there, a redirect that steps 2–6 or a rule would give, or `null` when nothing
|
|
197
|
+
* answers there. A step 2–3 redirect lands only when something answers at its canonical path.
|
|
198
|
+
*/
|
|
199
|
+
async function landing(deps, lower, opts) {
|
|
200
|
+
if (deps.registry.getRoutePaths.has(lower))
|
|
201
|
+
return redirect(lower);
|
|
202
|
+
const res = await resolveSite(deps, encodePath(lower), opts);
|
|
203
|
+
if (res.kind === 'page')
|
|
204
|
+
return redirect(lower);
|
|
205
|
+
if (res.kind === 'canonical')
|
|
206
|
+
return (await answers(deps, res.canonical, opts)) ? redirect(res.canonical) : null;
|
|
207
|
+
if (res.kind === 'redirect')
|
|
208
|
+
return res;
|
|
209
|
+
if (res.kind !== 'rules')
|
|
210
|
+
return null;
|
|
211
|
+
const rule = await matchRedirect(deps, res, opts);
|
|
212
|
+
return rule?.kind === 'redirect' ? rule : null;
|
|
213
|
+
}
|
|
214
|
+
/** Whether a GET code route, a page, a redirect from steps 2–6 or a firing rule answers at a decoded `path`. */
|
|
215
|
+
async function answers(deps, path, opts) {
|
|
216
|
+
if (deps.registry.getRoutePaths.has(path))
|
|
217
|
+
return true;
|
|
218
|
+
const res = await resolveSite(deps, encodePath(path), opts);
|
|
219
|
+
if (res.kind === 'canonical')
|
|
220
|
+
return answers(deps, res.canonical, opts);
|
|
221
|
+
if (res.kind !== 'rules')
|
|
222
|
+
return res.kind !== 'not_found';
|
|
223
|
+
return (await matchRedirect(deps, res, opts))?.kind === 'redirect';
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* What `resolvePath` answers before it looks at redirect rules (steps 1–6, then 9): a redirect rule
|
|
140
227
|
* can only fire where this is `not_found`.
|
|
141
228
|
*/
|
|
142
229
|
export async function resolveWithoutRules(deps, rawPath, opts = {}) {
|
|
143
230
|
const res = await resolveSite(deps, rawPath, opts);
|
|
231
|
+
if (res.kind === 'canonical')
|
|
232
|
+
return redirect(res.canonical);
|
|
144
233
|
return res.kind === 'rules' ? notFound(res.locale) : res;
|
|
145
234
|
}
|
|
146
235
|
/** Steps 1–6 of `resolvePath`, or where redirect rules are tried next. */
|
|
@@ -155,7 +244,7 @@ async function resolveSite(deps, rawPath, opts) {
|
|
|
155
244
|
const [, first = '', ...tail] = path.split('/');
|
|
156
245
|
const canonical = first === registry.defaultLocale ? `/${tail.join('/')}` : path;
|
|
157
246
|
if (canonical !== path || decodeURIComponent(rawPath) !== path)
|
|
158
|
-
return
|
|
247
|
+
return { kind: 'canonical', canonical };
|
|
159
248
|
const { locale, rest } = splitLocale(registry, path);
|
|
160
249
|
const types = [...registry.types.values()];
|
|
161
250
|
// 4. Singleton paths.
|
package/dist/core/types.d.ts
CHANGED
|
@@ -199,9 +199,14 @@ export interface LiveDocument {
|
|
|
199
199
|
revisionId: number;
|
|
200
200
|
/** The shown revision's `created_at`. */
|
|
201
201
|
updatedAt: string;
|
|
202
|
+
/** When Inlay first published the document; `null` if it never has been. */
|
|
203
|
+
publishedAt: string | null;
|
|
202
204
|
data: DocumentData;
|
|
203
205
|
}
|
|
204
|
-
/**
|
|
206
|
+
/**
|
|
207
|
+
* What a request path resolves to. A redirect's `location` is already encoded: a site path, or with
|
|
208
|
+
* `external` the full https URL of a rule's URL target.
|
|
209
|
+
*/
|
|
205
210
|
export type RouteMatch = {
|
|
206
211
|
kind: 'page';
|
|
207
212
|
document: LiveDocument;
|
|
@@ -209,6 +214,7 @@ export type RouteMatch = {
|
|
|
209
214
|
kind: 'redirect';
|
|
210
215
|
location: string;
|
|
211
216
|
status: 301 | 302;
|
|
217
|
+
external?: true;
|
|
212
218
|
}
|
|
213
219
|
/** `loop` lists the `from` of redirect rules that were skipped because they would go round in a loop. */
|
|
214
220
|
| {
|
|
@@ -221,11 +227,16 @@ export type RedirectSource = 'manual' | 'auto' | 'import';
|
|
|
221
227
|
export interface Redirect {
|
|
222
228
|
id: number;
|
|
223
229
|
from: string;
|
|
224
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* A site path (which may use the `:name` params of `from`), a document's translation group, or a
|
|
232
|
+
* full https URL on another site.
|
|
233
|
+
*/
|
|
225
234
|
to: {
|
|
226
235
|
path: string;
|
|
227
236
|
} | {
|
|
228
237
|
document: string;
|
|
238
|
+
} | {
|
|
239
|
+
url: string;
|
|
229
240
|
};
|
|
230
241
|
status: 301 | 302;
|
|
231
242
|
source: RedirectSource;
|
|
@@ -236,13 +247,27 @@ export interface Redirect {
|
|
|
236
247
|
export interface RedirectInput {
|
|
237
248
|
/** A site path, or a full http(s) URL whose origin is dropped. */
|
|
238
249
|
from: string;
|
|
239
|
-
/** A site path, or a document's translation group. */
|
|
250
|
+
/** A site path, a full `https://` URL on another site, or a document's translation group. */
|
|
240
251
|
to: string | {
|
|
241
252
|
document: string;
|
|
242
253
|
};
|
|
243
254
|
status?: 301 | 302;
|
|
244
255
|
note?: string;
|
|
245
256
|
}
|
|
257
|
+
/** A redirect rule from the site's code. Read-only: it changes only with a new release. */
|
|
258
|
+
export interface CodeRedirect {
|
|
259
|
+
from: string;
|
|
260
|
+
to: {
|
|
261
|
+
path: string;
|
|
262
|
+
} | {
|
|
263
|
+
url: string;
|
|
264
|
+
};
|
|
265
|
+
status: 301 | 302;
|
|
266
|
+
/** An admin rule with the same `from` answers first. */
|
|
267
|
+
overridden: boolean;
|
|
268
|
+
/** A published page answers at the exact `from`, so the rule never fires. */
|
|
269
|
+
hidden: boolean;
|
|
270
|
+
}
|
|
246
271
|
export type ThemeColor = 'base-100' | 'base-200' | 'base-300' | 'base-content' | 'primary' | 'primary-content' | 'secondary' | 'secondary-content' | 'accent' | 'accent-content' | 'neutral' | 'neutral-content' | 'info' | 'info-content' | 'success' | 'success-content' | 'warning' | 'warning-content' | 'error' | 'error-content';
|
|
247
272
|
export interface CustomTheme {
|
|
248
273
|
base?: string;
|
package/dist/host/app.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FastifyInstance } from 'fastify';
|
|
2
2
|
import { type HostApi } from '../adapters/site/plugin.js';
|
|
3
|
+
import type { LoadedConfig } from '../config.js';
|
|
3
4
|
import type { Core } from '../core/core.js';
|
|
4
5
|
import { type SiteDefinition } from '../core/registry/define.js';
|
|
5
6
|
import type { HostConfig } from './config.js';
|
|
@@ -13,6 +14,8 @@ export interface SiteSource {
|
|
|
13
14
|
/** Each shipped file's source as the site names it, to the file to read. */
|
|
14
15
|
shippedFiles?: ReadonlyMap<string, string>;
|
|
15
16
|
}
|
|
17
|
+
/** The source of a site run from its code (`inlaycms dev` and `inlaycms/testing`): its `public/` folder, if it has one. */
|
|
18
|
+
export declare function sourceFromConfig(loaded: LoadedConfig): SiteSource;
|
|
16
19
|
/**
|
|
17
20
|
* The Fastify app for one site on the host, ready but not listening. With no `source` it serves the admin and, for
|
|
18
21
|
* every content page, the `noSite` page: "no site yet" (`'empty'`, the default) for a host that has no release, or
|
|
@@ -40,6 +43,8 @@ export declare function createSiteApp(config: HostConfig, source: SiteSource | n
|
|
|
40
43
|
diff?: (core: Core) => Promise<ContentDiff>;
|
|
41
44
|
/** The largest release file a push may send (`PUSH_MAX_BYTES` by default); for tests. */
|
|
42
45
|
pushMaxBytes?: number;
|
|
46
|
+
/** What routes get as `ctx.fetch`; the global `fetch` by default. */
|
|
47
|
+
fetch?: typeof fetch;
|
|
43
48
|
}): Promise<{
|
|
44
49
|
app: FastifyInstance;
|
|
45
50
|
core: Core;
|
package/dist/host/app.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
1
3
|
import Fastify from 'fastify';
|
|
2
4
|
import { AUTH, inlay } from '../adapters/site/plugin.js';
|
|
3
5
|
import { catalogPage } from '../adapters/site/render.js';
|
|
@@ -15,6 +17,11 @@ export const EMPTY_SITE = defineSite({
|
|
|
15
17
|
defaultLocale: 'en',
|
|
16
18
|
admin: { name: t('admin.title') },
|
|
17
19
|
});
|
|
20
|
+
/** The source of a site run from its code (`inlaycms dev` and `inlaycms/testing`): its `public/` folder, if it has one. */
|
|
21
|
+
export function sourceFromConfig(loaded) {
|
|
22
|
+
const publicDir = join(loaded.dir, 'public');
|
|
23
|
+
return { site: loaded.config.site, publicDir: existsSync(publicDir) ? publicDir : null };
|
|
24
|
+
}
|
|
18
25
|
/**
|
|
19
26
|
* The Fastify app for one site on the host, ready but not listening. With no `source` it serves the admin and, for
|
|
20
27
|
* every content page, the `noSite` page: "no site yet" (`'empty'`, the default) for a host that has no release, or
|
|
@@ -87,6 +94,7 @@ export async function createSiteApp(config, source, opts) {
|
|
|
87
94
|
publicMaxAge: config.publicMaxAge,
|
|
88
95
|
...(source?.publicDir != null && { publicDir: source.publicDir }),
|
|
89
96
|
secrets: config.secrets(source?.site.secrets ?? []),
|
|
97
|
+
...(opts.fetch && { fetch: opts.fetch }),
|
|
90
98
|
content: opts.content,
|
|
91
99
|
...(source?.shippedFiles && { shippedFiles: source.shippedFiles }),
|
|
92
100
|
...(opts.now && { now: opts.now }),
|
package/dist/host/dev.js
CHANGED
|
@@ -8,7 +8,7 @@ import { loadConfig } from '../config.js';
|
|
|
8
8
|
import { InlayError } from '../core/errors.js';
|
|
9
9
|
import { t } from '../core/messages/index.js';
|
|
10
10
|
import { INLAY_ENTRIES } from '../core/release/read.js';
|
|
11
|
-
import { createSiteApp } from './app.js';
|
|
11
|
+
import { createSiteApp, sourceFromConfig } from './app.js';
|
|
12
12
|
import { INLAY_BIN } from './bin.js';
|
|
13
13
|
import { ensureDataDir, readHostConfig } from './config.js';
|
|
14
14
|
/** Only for `inlaycms dev` on a developer's computer: the server's own secret when INLAY_SECRET isn't set. */
|
|
@@ -147,14 +147,10 @@ async function runSite(configFile, io) {
|
|
|
147
147
|
process.on('disconnect', () => void close());
|
|
148
148
|
try {
|
|
149
149
|
useRunningInlay();
|
|
150
|
-
const
|
|
150
|
+
const loaded = await loadConfig(configFile);
|
|
151
151
|
const host = readHostConfig(process.env);
|
|
152
152
|
await ensureDataDir(host);
|
|
153
|
-
|
|
154
|
-
app = (await createSiteApp(host, { site: config.site, publicDir: existsSync(publicDir) ? publicDir : null }, {
|
|
155
|
-
content: 'apply',
|
|
156
|
-
logger: true,
|
|
157
|
-
})).app;
|
|
153
|
+
app = (await createSiteApp(host, sourceFromConfig(loaded), { content: 'apply', logger: true })).app;
|
|
158
154
|
if (closing)
|
|
159
155
|
return 0;
|
|
160
156
|
await app.listen({ port: host.port, host: host.host });
|
package/dist/host/diff.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type ReleaseManifest } from '../core/release/manifest.js';
|
|
1
|
+
import { type ManifestRedirect, type ReleaseManifest } from '../core/release/manifest.js';
|
|
2
2
|
import type { ReleaseDiff } from './push.js';
|
|
3
3
|
type Route = {
|
|
4
4
|
method: string;
|
|
5
5
|
path: string;
|
|
6
|
+
sitemap?: true;
|
|
6
7
|
};
|
|
7
8
|
type FieldChange = 'added' | 'removed' | 'type' | 'required' | 'optional';
|
|
8
9
|
type Slot = {
|
|
@@ -44,9 +45,26 @@ export interface StructuralDiff {
|
|
|
44
45
|
path: string;
|
|
45
46
|
change: FieldChange;
|
|
46
47
|
}>;
|
|
48
|
+
/**
|
|
49
|
+
* `sitemap.added`: the staged release's sitemap routes that the current release doesn't list, new routes included.
|
|
50
|
+
* `sitemap.removed`: routes both releases have that the current release lists and the staged one doesn't.
|
|
51
|
+
*/
|
|
47
52
|
routes: {
|
|
48
53
|
added: Route[];
|
|
49
54
|
removed: Route[];
|
|
55
|
+
sitemap: {
|
|
56
|
+
added: Route[];
|
|
57
|
+
removed: Route[];
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/** Code redirects by `from`; `changed` holds those whose target or status differs. Absent from a host before 0.3. */
|
|
61
|
+
redirects?: {
|
|
62
|
+
added: ManifestRedirect[];
|
|
63
|
+
removed: ManifestRedirect[];
|
|
64
|
+
changed: Array<{
|
|
65
|
+
before: ManifestRedirect;
|
|
66
|
+
after: ManifestRedirect;
|
|
67
|
+
}>;
|
|
50
68
|
};
|
|
51
69
|
/** Every secret the staged release needs. */
|
|
52
70
|
secrets: string[];
|
package/dist/host/diff.js
CHANGED
|
@@ -244,6 +244,20 @@ export function structuralDiff(current, staged) {
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
+
const curRedirects = new Map((current?.redirects ?? []).map((r) => [r.from, r]));
|
|
248
|
+
const stagedRedirects = new Map((staged.redirects ?? []).map((r) => [r.from, r]));
|
|
249
|
+
const redirects = { added: [], removed: [], changed: [] };
|
|
250
|
+
for (const [from, after] of stagedRedirects) {
|
|
251
|
+
const before = curRedirects.get(from);
|
|
252
|
+
if (!before)
|
|
253
|
+
redirects.added.push(after);
|
|
254
|
+
else if (before.to !== after.to || before.status !== after.status)
|
|
255
|
+
redirects.changed.push({ before, after });
|
|
256
|
+
}
|
|
257
|
+
for (const [from, before] of curRedirects)
|
|
258
|
+
if (!stagedRedirects.has(from))
|
|
259
|
+
redirects.removed.push(before);
|
|
260
|
+
const listed = new Set((current?.routes ?? []).filter((r) => r.sitemap === true).map(routeKey));
|
|
247
261
|
return {
|
|
248
262
|
types: { added: added(curNames, stagedNames), removed: added(stagedNames, curNames), changed },
|
|
249
263
|
slots,
|
|
@@ -252,7 +266,12 @@ export function structuralDiff(current, staged) {
|
|
|
252
266
|
routes: {
|
|
253
267
|
added: added(current?.routes ?? [], staged.routes, routeKey),
|
|
254
268
|
removed: added(staged.routes, current?.routes ?? [], routeKey),
|
|
269
|
+
sitemap: {
|
|
270
|
+
added: staged.routes.filter((r) => r.sitemap === true && !listed.has(routeKey(r))),
|
|
271
|
+
removed: staged.routes.filter((r) => r.sitemap !== true && listed.has(routeKey(r))),
|
|
272
|
+
},
|
|
255
273
|
},
|
|
274
|
+
redirects,
|
|
256
275
|
secrets: [...staged.secrets],
|
|
257
276
|
migrations: [...staged.migrations],
|
|
258
277
|
shipped: { stale },
|
|
@@ -335,9 +354,20 @@ export function formatDiff(diff) {
|
|
|
335
354
|
for (const name of s.migrations)
|
|
336
355
|
lines.push(t('diff.release.migration', { name }));
|
|
337
356
|
for (const r of s.routes.added)
|
|
338
|
-
lines.push(t('diff.release.routeAdded', r));
|
|
357
|
+
lines.push(t('diff.release.routeAdded', { method: r.method, path: r.path }));
|
|
339
358
|
for (const r of s.routes.removed)
|
|
340
|
-
lines.push(t('diff.release.routeRemoved', r));
|
|
359
|
+
lines.push(t('diff.release.routeRemoved', { method: r.method, path: r.path }));
|
|
360
|
+
for (const r of s.routes.sitemap?.added ?? [])
|
|
361
|
+
lines.push(t('diff.release.routeSitemapAdded', { path: r.path }));
|
|
362
|
+
for (const r of s.routes.sitemap?.removed ?? [])
|
|
363
|
+
lines.push(t('diff.release.routeSitemapRemoved', { path: r.path }));
|
|
364
|
+
for (const r of s.redirects?.added ?? [])
|
|
365
|
+
lines.push(t('diff.release.redirectAdded', { from: r.from, to: r.to, status: r.status }));
|
|
366
|
+
for (const r of s.redirects?.removed ?? [])
|
|
367
|
+
lines.push(t('diff.release.redirectRemoved', { from: r.from, to: r.to }));
|
|
368
|
+
for (const { after } of s.redirects?.changed ?? []) {
|
|
369
|
+
lines.push(t('diff.release.redirectChanged', { from: after.from, to: after.to, status: after.status }));
|
|
370
|
+
}
|
|
341
371
|
if (lines.length === 0)
|
|
342
372
|
lines.push(t('diff.release.nothing'));
|
|
343
373
|
if (s.secrets.length > 0)
|
package/dist/index.d.ts
CHANGED
|
@@ -39,9 +39,9 @@ export { extractRelease, loadRelease, openRelease, readRelease, type LoadedRelea
|
|
|
39
39
|
export { InlayError } from './core/errors.js';
|
|
40
40
|
export { defineField, type AdminWidget, type FieldMeta, type FormValues, type WidgetProps, } from './core/fields/define.js';
|
|
41
41
|
export { defineContent, defineEntries, type ShippedContent, type ShippedDocument, type ShippedDocumentRef, } from './core/registry/content.js';
|
|
42
|
-
export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
|
|
42
|
+
export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type RedirectDef, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
|
|
43
43
|
export { defineRoute, type QueryApi, type RouteContext, type RouteDef, type RouteMethod, type RouteRequest, type RouteResponse, } from './core/registry/route.js';
|
|
44
44
|
export { defineMigration, type MigrationContext, type MigrationDocument, type ReleaseMigration, } from './core/registry/migration.js';
|
|
45
45
|
export type { Gap, GapFilter, GapSummary } from './core/content/gaps.js';
|
|
46
46
|
export type { HiddenContent, HiddenDocuments } from './core/content/hidden.js';
|
|
47
|
-
export type { Activity, Actor, ContentInput, ContentIssue, ContentRef, Ctx, DiffEntry, DocumentData, DocumentKind, DocumentSummary, DocumentView, FileValue, ImageValue, IssueCode, LinkValue, LiveDocument, LiveState, MediaInfo, MediaStatus, PathSegment, Redirect, RedirectInput, RedirectSource, RevisionMeta, RevisionSource, Role, ShippedFile, UploadLimits, Usage, } from './core/types.js';
|
|
47
|
+
export type { Activity, Actor, CodeRedirect, ContentInput, ContentIssue, ContentRef, Ctx, DiffEntry, DocumentData, DocumentKind, DocumentSummary, DocumentView, FileValue, ImageValue, IssueCode, LinkValue, LiveDocument, LiveState, MediaInfo, MediaStatus, PathSegment, Redirect, RedirectInput, RedirectSource, RevisionMeta, RevisionSource, Role, ShippedFile, UploadLimits, Usage, } from './core/types.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The type of a `.md` file a site imports (`import post from './posts/x.md'`): its text, with relative image targets
|
|
3
|
+
* already pointing at their files. A script file, so the declaration is global wherever it is referenced.
|
|
4
|
+
*/
|
|
5
|
+
declare module '*.md' {
|
|
6
|
+
const text: string;
|
|
7
|
+
export default text;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/site.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
+
/// <reference path="markdown-modules.d.ts" preserve="true" />
|
|
1
2
|
/**
|
|
2
3
|
* What a site's code imports (`inlaycms/site`): the definitions and the types
|
|
3
4
|
* templates, routes and migrations use, and nothing that reaches the server.
|
|
4
5
|
* A release may import only this and the JSX runtime.
|
|
5
6
|
*/
|
|
7
|
+
import { type RichTextDoc } from './core/richtext/schema.js';
|
|
6
8
|
export { z } from 'zod';
|
|
7
9
|
export { f } from './core/fields/builtins.js';
|
|
8
10
|
export { defineConfig, type InlayConfig } from './config.js';
|
|
9
11
|
export { escapeHtml, raw, SafeHtml, type Html, type Renderable } from './jsx/html.js';
|
|
10
12
|
export { defineField, type AdminWidget, type FieldMeta, type FormValues, type WidgetProps } from './core/fields/define.js';
|
|
11
13
|
export { defineContent, defineEntries, type ShippedContent, type ShippedDocument, type ShippedDocumentRef, } from './core/registry/content.js';
|
|
12
|
-
export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
|
|
14
|
+
export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, type AdminSettings, type BlockDef, type CollectionDef, type GlobalDef, type SingletonDef, type SingletonPath, type SiteDefinition, type OgType, type RedirectDef, type SeoSettings, type SiteInput, type SlotDef, type TemplateDef, type TemplateRenderProps, type TypeDef, } from './core/registry/define.js';
|
|
13
15
|
export { defineRoute, type QueryApi, type RouteContext, type RouteDef, type RouteMethod, type RouteRequest, type RouteResponse, } from './core/registry/route.js';
|
|
14
16
|
export { defineMigration, type MigrationContext, type MigrationDocument, type ReleaseMigration, } from './core/registry/migration.js';
|
|
15
|
-
export type { Entry, PageInfo, QueryOptions, QueryResult, RenderContext, ResolvedFile, ResolvedImage, ResolvedLink, } from './core/registry/render.js';
|
|
17
|
+
export type { Entry, HeadApi, HeadLink, HeadMeta, PageInfo, QueryOptions, QueryResult, RenderContext, ResolvedFile, ResolvedImage, ResolvedLink, } from './core/registry/render.js';
|
|
16
18
|
export type { AdminTheme, ContentInput, CustomTheme, DocumentData, FileValue, ImageValue, LinkValue, MediaInfo, ShippedFile, ThemeColor, } from './core/types.js';
|
|
17
|
-
|
|
19
|
+
/** The text of a rich-text or inline-text value without its formatting; `''` for `null` or `undefined`. */
|
|
20
|
+
export declare function plainText(doc: RichTextDoc | null | undefined): string;
|
|
21
|
+
export type { RichTextDoc };
|
|
22
|
+
export type { RichTextFeature, RichTextOptions } from './core/richtext/schema.js';
|
package/dist/site.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/// <reference path="./markdown-modules.ts" preserve="true" />
|
|
1
2
|
/**
|
|
2
3
|
* What a site's code imports (`inlaycms/site`): the definitions and the types
|
|
3
4
|
* templates, routes and migrations use, and nothing that reaches the server.
|
|
4
5
|
* A release may import only this and the JSX runtime.
|
|
5
6
|
*/
|
|
7
|
+
import { richTextText } from './core/richtext/schema.js';
|
|
6
8
|
export { z } from 'zod';
|
|
7
9
|
export { f } from './core/fields/builtins.js';
|
|
8
10
|
export { defineConfig } from './config.js';
|
|
@@ -12,3 +14,7 @@ export { defineContent, defineEntries, } from './core/registry/content.js';
|
|
|
12
14
|
export { defineBlock, defineCollection, defineGlobal, defineSingleton, defineSite, defineTemplate, } from './core/registry/define.js';
|
|
13
15
|
export { defineRoute, } from './core/registry/route.js';
|
|
14
16
|
export { defineMigration, } from './core/registry/migration.js';
|
|
17
|
+
/** The text of a rich-text or inline-text value without its formatting; `''` for `null` or `undefined`. */
|
|
18
|
+
export function plainText(doc) {
|
|
19
|
+
return doc ? richTextText(doc) : '';
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface TestSiteOptions {
|
|
2
|
+
/** The site's inlay.config.ts: a path relative to process.cwd(), or a file: URL (a URL, or a string starting with file:). */
|
|
3
|
+
config: string | URL;
|
|
4
|
+
/** Used for canonical, Open Graph and sitemap URLs. Default http://localhost. */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Values for the site's declared secrets. */
|
|
7
|
+
secrets?: Record<string, string>;
|
|
8
|
+
/** What routes get as ctx.fetch. Default: the global fetch. */
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
/** The clock. Default: real time. */
|
|
11
|
+
now?: () => Date;
|
|
12
|
+
}
|
|
13
|
+
export interface TestSite {
|
|
14
|
+
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
15
|
+
paths(): Promise<string[]>;
|
|
16
|
+
close(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Boots the site of an `inlay.config.ts` the way `inlaycms dev` does, in a temporary data folder, and answers its
|
|
20
|
+
* requests in process (Fastify `inject`): no port, no child process. `close()` stops it and removes the folder.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTestSite(opts: TestSiteOptions): Promise<TestSite>;
|