inlaycms 0.1.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 +344 -8
- 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
|
@@ -6,6 +6,7 @@ import { DataTable, readTableQuery } from '../views/data-table.js';
|
|
|
6
6
|
import { Icon } from '../views/icons.js';
|
|
7
7
|
import { Alert, adminPage, Time } from '../views/layout.js';
|
|
8
8
|
import { Sheet } from '../views/sheet.js';
|
|
9
|
+
import { Badge } from '../views/status.js';
|
|
9
10
|
const sourceName = (s) => t(`admin.redirects.source.${s}`);
|
|
10
11
|
/** The redirects: a searchable table, an add form, and a CSV import. */
|
|
11
12
|
export function registerRedirects(scope, ctx) {
|
|
@@ -15,9 +16,14 @@ export function registerRedirects(scope, ctx) {
|
|
|
15
16
|
function Target({ redirect, docs }) {
|
|
16
17
|
if ('path' in redirect.to)
|
|
17
18
|
return _jsx("code", { children: redirect.to.path });
|
|
19
|
+
if ('url' in redirect.to)
|
|
20
|
+
return _jsx("code", { children: redirect.to.url });
|
|
18
21
|
const doc = docs.get(redirect.to.document);
|
|
19
22
|
return doc === undefined ? (_jsx("span", { children: t('admin.redirects.missingPage') })) : (_jsx("a", { href: `/admin/documents/${encodeURIComponent(doc.documentId)}`, class: "link", children: doc.title }));
|
|
20
23
|
}
|
|
24
|
+
function CodeRules({ rules }) {
|
|
25
|
+
return (_jsxs("section", { id: "code-redirects", "aria-labelledby": "code-redirects-heading", class: "flex flex-col gap-3", children: [_jsx("h2", { id: "code-redirects-heading", class: "text-lg font-semibold", children: t('admin.redirects.code.heading') }), _jsx("p", { class: "text-sm text-base-content/70", children: t('admin.redirects.code.intro') }), _jsx("div", { class: "overflow-x-auto", children: _jsxs("table", { class: "table", children: [_jsx("caption", { class: "sr-only", children: t('admin.redirects.code.table') }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: t('admin.redirects.from') }), _jsx("th", { scope: "col", children: t('admin.redirects.to') }), _jsx("th", { scope: "col", children: t('admin.redirects.type') })] }) }), _jsx("tbody", { children: rules.map((r) => (_jsxs("tr", { children: [_jsx("td", { children: _jsx("code", { children: r.from }) }), _jsx("td", { children: _jsx("code", { children: 'path' in r.to ? r.to.path : r.to.url }) }), _jsxs("td", { children: [t(r.status === 301 ? 'admin.redirects.permanent' : 'admin.redirects.temporary'), r.overridden && (_jsxs(_Fragment, { children: [' ', _jsx(Badge, { tone: "outline", children: t('admin.redirects.code.overridden') })] })), r.hidden && (_jsxs(_Fragment, { children: [' ', _jsx(Badge, { tone: "outline", children: t('admin.redirects.code.hidden') })] }))] })] }))) })] }) })] }));
|
|
26
|
+
}
|
|
21
27
|
async function list(request, reply, status, sheets = {}) {
|
|
22
28
|
const form = sheets.add ?? {};
|
|
23
29
|
const imp = sheets.import ?? { csv: '', problems: [] };
|
|
@@ -29,6 +35,7 @@ export function registerRedirects(scope, ctx) {
|
|
|
29
35
|
const table = readTableQuery(query, { sorts: [], defaultSort: 'from', defaultDir: 'asc' });
|
|
30
36
|
const q = table.q;
|
|
31
37
|
const all = await core.listRedirects();
|
|
38
|
+
const codeRules = core.registry.redirects.length === 0 ? [] : await core.listCodeRedirects();
|
|
32
39
|
const wanted = new Set(all.flatMap((r) => ('document' in r.to ? [r.to.document] : [])));
|
|
33
40
|
if (form.values?.to_document)
|
|
34
41
|
wanted.add(form.values.to_document);
|
|
@@ -37,7 +44,7 @@ export function registerRedirects(scope, ctx) {
|
|
|
37
44
|
const shown = needle === ''
|
|
38
45
|
? all
|
|
39
46
|
: all.filter((r) => {
|
|
40
|
-
const to = 'path' in r.to ? r.to.path : (docs.get(r.to.document)?.title ?? '');
|
|
47
|
+
const to = 'path' in r.to ? r.to.path : 'url' in r.to ? r.to.url : (docs.get(r.to.document)?.title ?? '');
|
|
41
48
|
return [r.from, to, r.note ?? ''].some((s) => s.toLowerCase().includes(needle));
|
|
42
49
|
});
|
|
43
50
|
const values = form.values ?? {};
|
|
@@ -45,7 +52,7 @@ export function registerRedirects(scope, ctx) {
|
|
|
45
52
|
const chosen = values.to_document ? docs.get(values.to_document)?.title : undefined;
|
|
46
53
|
const picker = `/admin/pick/documents?${new URLSearchParams({ locale: core.registry.defaultLocale }).toString()}`;
|
|
47
54
|
const error = form.error;
|
|
48
|
-
const body = (_jsxs("div", { class: "flex flex-col gap-8", children: [_jsx(DataTable, { id: "redirects", caption: t('admin.redirects.table'), base: "/admin/redirects", query: table, rows: shown, rowKey: (r) => String(r.id), rowLabel: (r) => r.from, search: { label: t('admin.redirects.search') }, empty: t('admin.redirects.empty'), columns: [
|
|
55
|
+
const body = (_jsxs("div", { class: "flex flex-col gap-8", children: [sheets.deleteError !== undefined && (_jsx(Alert, { kind: "error", id: "delete-error", children: sheets.deleteError })), _jsx(DataTable, { id: "redirects", caption: t('admin.redirects.table'), base: "/admin/redirects", query: table, rows: shown, rowKey: (r) => String(r.id), rowLabel: (r) => r.from, search: { label: t('admin.redirects.search') }, empty: t('admin.redirects.empty'), columns: [
|
|
49
56
|
{ key: 'from', label: t('admin.redirects.from'), cell: (r) => _jsx("code", { children: r.from }) },
|
|
50
57
|
{ key: 'to', label: t('admin.redirects.to'), cell: (r) => _jsx(Target, { redirect: r, docs: docs }) },
|
|
51
58
|
{ key: 'type', label: t('admin.redirects.type'), cell: (r) => t(r.status === 301 ? 'admin.redirects.permanent' : 'admin.redirects.temporary') },
|
|
@@ -55,7 +62,7 @@ export function registerRedirects(scope, ctx) {
|
|
|
55
62
|
cell: (r) => (_jsxs(_Fragment, { children: [sourceName(r.source), ", ", r.createdBy, ", ", _jsx(Time, { iso: r.createdAt, relative: true })] })),
|
|
56
63
|
},
|
|
57
64
|
{ key: 'note', label: t('admin.redirects.note'), cell: (r) => r.note ?? '' },
|
|
58
|
-
], rowActions: (r) => [{ label: t('admin.redirects.delete'), icon: 'trash', href: `/admin/redirects/${r.id}/delete`, danger: true, method: 'post' }] }), _jsxs(Sheet, { id: "add-redirect", title: t('admin.redirects.addHeading'), description: t('admin.redirects.addDescription'), open: addOpen, action: "/admin/redirects", submit: t('admin.redirects.add'), children: [error && (_jsx(Alert, { kind: "error", id: "redirect-error", children: _jsxs("div", { children: [_jsx("p", { children: error.message }), (error.details.issues ?? []).length > 0 && (_jsx("ul", { class: "list-disc pl-5", children: (error.details.issues ?? []).map((issue) => (_jsx("li", { children: issue.message }))) }))] }) })), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "from", class: "text-sm font-medium", children: t('admin.redirects.from') }), _jsx("input", { id: "from", name: "from", type: "text", value: values.from ?? '', class: "input w-full font-mono", placeholder: t('admin.redirects.fromPlaceholder'), "aria-describedby": "from-hint" }), _jsx("p", { id: "from-hint", class: "text-xs text-base-content/70", children: t('admin.redirects.fromHint') })] }), _jsxs("fieldset", { class: "flex flex-col gap-3", children: [_jsx("legend", { class: "mb-1.5 text-sm font-medium", children: t('admin.redirects.toMode') }), _jsxs("div", { class: "join w-full", children: [_jsx("input", { class: "join-item btn btn-sm flex-1", type: "radio", id: "to-mode-path", name: "to_mode", value: "path", "aria-label": t('admin.redirects.toPath'), checked: mode === 'path' }), _jsx("input", { class: "join-item btn btn-sm flex-1", type: "radio", id: "to-mode-document", name: "to_mode", value: "document", "aria-label": t('admin.redirects.toDocument'), checked: mode === 'document' })] }), _jsxs("div", { class: "flex flex-col gap-1.5", "data-shown-when": "to_mode=path", hidden: mode !== 'path', children: [_jsx("label", { for: "to_path", class: "text-sm font-medium", children: t('admin.redirects.toPathLabel') }), _jsx("input", { id: "to_path", name: "to_path", type: "text", value: values.to_path ?? '', class: "input w-full font-mono", placeholder: t('admin.redirects.toPathPlaceholder'), "aria-describedby": "to-path-hint" }), _jsx("p", { id: "to-path-hint", class: "text-xs text-base-content/70", children: t('admin.redirects.toPathHint') })] }), _jsxs("div", { "data-shown-when": "to_mode=document", hidden: mode !== 'document', "data-picker": picker, "data-name": "to_document", class: "flex items-center gap-3 rounded-field border border-base-300 px-3 py-2.5", children: [_jsx("input", { type: "hidden", name: "to_document", value: values.to_document ?? '', "data-picker-value": true }), _jsx("span", { id: "to-document-chosen", "data-picker-label": true, "data-empty": t('admin.form.nothingChosen'), class: "min-w-0 flex-1 truncate text-sm text-base-content/60", children: chosen ?? t('admin.form.nothingChosen') }), _jsx("button", { type: "button", id: "to-document", "data-picker-open": true, class: "btn btn-sm", "aria-describedby": "to-document-chosen", children: t('admin.redirects.choose') }), _jsx("button", { type: "button", "data-picker-clear": true, class: "btn btn-ghost btn-sm", children: t('admin.form.clear') })] })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "status", class: "text-sm font-medium", children: t('admin.redirects.type') }), _jsxs("select", { id: "status", name: "status", class: "select w-full", children: [_jsx("option", { value: "301", selected: values.status !== '302', children: t('admin.redirects.permanent') }), _jsx("option", { value: "302", selected: values.status === '302', children: t('admin.redirects.temporary') })] })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "note", class: "text-sm font-medium", children: t('admin.redirects.noteLabel') }), _jsx("input", { id: "note", name: "note", type: "text", value: values.note ?? '', class: "input w-full" })] })] }), _jsxs(Sheet, { id: "import-redirects", size: "lg", title: t('admin.redirects.importTitle'), description: t('admin.redirects.importDescription'), open: importOpen, action: "/admin/redirects/import", enctype: "multipart/form-data", submit: t('admin.redirects.importSubmit'), children: [imp.problems.length > 0 && (_jsx(Alert, { kind: "error", id: "import-problems", children: _jsxs("div", { children: [imp.summary !== undefined && _jsx("p", { class: "font-semibold", children: imp.summary }), _jsx("ul", { class: "list-disc pl-5", children: imp.problems.map((p) => (_jsx("li", { children: p }))) })] }) })), _jsxs("div", { id: "csv-hint", class: "rounded-field bg-base-200 px-4 py-3 text-sm", children: [_jsx("p", { children: t('admin.redirects.importHint') }), _jsx("pre", { class: "mt-2 overflow-x-auto font-mono text-xs text-base-content/80", children: t('admin.redirects.importExample') })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "file", class: "text-sm font-medium", children: t('admin.redirects.csvFile') }), _jsx("input", { id: "file", name: "file", type: "file", accept: ".csv,text/csv", class: "file-input w-full", "aria-describedby": "csv-hint" })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "csv", class: "text-sm font-medium", children: t('admin.redirects.csvText') }), _jsx("textarea", { id: "csv", name: "csv", rows: "10", class: "textarea w-full font-mono text-sm", "aria-describedby": "csv-hint", children: imp.csv })] })] })] }));
|
|
65
|
+
], rowActions: (r) => [{ label: t('admin.redirects.delete'), icon: 'trash', href: `/admin/redirects/${r.id}/delete`, danger: true, method: 'post' }] }), codeRules.length > 0 && _jsx(CodeRules, { rules: codeRules }), _jsxs(Sheet, { id: "add-redirect", title: t('admin.redirects.addHeading'), description: t('admin.redirects.addDescription'), open: addOpen, action: "/admin/redirects", submit: t('admin.redirects.add'), children: [error && (_jsx(Alert, { kind: "error", id: "redirect-error", children: _jsxs("div", { children: [_jsx("p", { children: error.message }), (error.details.issues ?? []).length > 0 && (_jsx("ul", { class: "list-disc pl-5", children: (error.details.issues ?? []).map((issue) => (_jsx("li", { children: issue.message }))) }))] }) })), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "from", class: "text-sm font-medium", children: t('admin.redirects.from') }), _jsx("input", { id: "from", name: "from", type: "text", value: values.from ?? '', class: "input w-full font-mono", placeholder: t('admin.redirects.fromPlaceholder'), "aria-describedby": "from-hint" }), _jsx("p", { id: "from-hint", class: "text-xs text-base-content/70", children: t('admin.redirects.fromHint') })] }), _jsxs("fieldset", { class: "flex flex-col gap-3", children: [_jsx("legend", { class: "mb-1.5 text-sm font-medium", children: t('admin.redirects.toMode') }), _jsxs("div", { class: "join w-full", children: [_jsx("input", { class: "join-item btn btn-sm flex-1", type: "radio", id: "to-mode-path", name: "to_mode", value: "path", "aria-label": t('admin.redirects.toPath'), checked: mode === 'path' }), _jsx("input", { class: "join-item btn btn-sm flex-1", type: "radio", id: "to-mode-document", name: "to_mode", value: "document", "aria-label": t('admin.redirects.toDocument'), checked: mode === 'document' })] }), _jsxs("div", { class: "flex flex-col gap-1.5", "data-shown-when": "to_mode=path", hidden: mode !== 'path', children: [_jsx("label", { for: "to_path", class: "text-sm font-medium", children: t('admin.redirects.toPathLabel') }), _jsx("input", { id: "to_path", name: "to_path", type: "text", value: values.to_path ?? '', class: "input w-full font-mono", placeholder: t('admin.redirects.toPathPlaceholder'), "aria-describedby": "to-path-hint" }), _jsx("p", { id: "to-path-hint", class: "text-xs text-base-content/70", children: t('admin.redirects.toPathHint') })] }), _jsxs("div", { "data-shown-when": "to_mode=document", hidden: mode !== 'document', "data-picker": picker, "data-name": "to_document", class: "flex items-center gap-3 rounded-field border border-base-300 px-3 py-2.5", children: [_jsx("input", { type: "hidden", name: "to_document", value: values.to_document ?? '', "data-picker-value": true }), _jsx("span", { id: "to-document-chosen", "data-picker-label": true, "data-empty": t('admin.form.nothingChosen'), class: "min-w-0 flex-1 truncate text-sm text-base-content/60", children: chosen ?? t('admin.form.nothingChosen') }), _jsx("button", { type: "button", id: "to-document", "data-picker-open": true, class: "btn btn-sm", "aria-describedby": "to-document-chosen", children: t('admin.redirects.choose') }), _jsx("button", { type: "button", "data-picker-clear": true, class: "btn btn-ghost btn-sm", children: t('admin.form.clear') })] })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "status", class: "text-sm font-medium", children: t('admin.redirects.type') }), _jsxs("select", { id: "status", name: "status", class: "select w-full", children: [_jsx("option", { value: "301", selected: values.status !== '302', children: t('admin.redirects.permanent') }), _jsx("option", { value: "302", selected: values.status === '302', children: t('admin.redirects.temporary') })] })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "note", class: "text-sm font-medium", children: t('admin.redirects.noteLabel') }), _jsx("input", { id: "note", name: "note", type: "text", value: values.note ?? '', class: "input w-full" })] })] }), _jsxs(Sheet, { id: "import-redirects", size: "lg", title: t('admin.redirects.importTitle'), description: t('admin.redirects.importDescription'), open: importOpen, action: "/admin/redirects/import", enctype: "multipart/form-data", submit: t('admin.redirects.importSubmit'), children: [imp.problems.length > 0 && (_jsx(Alert, { kind: "error", id: "import-problems", children: _jsxs("div", { children: [imp.summary !== undefined && _jsx("p", { class: "font-semibold", children: imp.summary }), _jsx("ul", { class: "list-disc pl-5", children: imp.problems.map((p) => (_jsx("li", { children: p }))) })] }) })), _jsxs("div", { id: "csv-hint", class: "rounded-field bg-base-200 px-4 py-3 text-sm", children: [_jsx("p", { children: t('admin.redirects.importHint') }), _jsx("pre", { class: "mt-2 overflow-x-auto font-mono text-xs text-base-content/80", children: t('admin.redirects.importExample') })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "file", class: "text-sm font-medium", children: t('admin.redirects.csvFile') }), _jsx("input", { id: "file", name: "file", type: "file", accept: ".csv,text/csv", class: "file-input w-full", "aria-describedby": "csv-hint" })] }), _jsxs("div", { class: "flex flex-col gap-1.5", children: [_jsx("label", { for: "csv", class: "text-sm font-medium", children: t('admin.redirects.csvText') }), _jsx("textarea", { id: "csv", name: "csv", rows: "10", class: "textarea w-full font-mono text-sm", "aria-describedby": "csv-hint", children: imp.csv })] })] })] }));
|
|
59
66
|
const notice = noticeOf(query);
|
|
60
67
|
const actions = (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", class: "btn btn-sm", "data-sheet-open": "import-redirects", children: [_jsx(Icon, { name: "upload" }), t('admin.redirects.import')] }), _jsxs("button", { type: "button", class: "btn btn-primary btn-sm", "data-sheet-open": "add-redirect", children: [_jsx(Icon, { name: "plus" }), t('admin.redirects.addHeading')] })] }));
|
|
61
68
|
return send(reply, status, { title: t('admin.redirects.title'), description: t('admin.redirects.intro'), actions, actor, section: 'redirects', ...(notice !== undefined && { notice }) }, body);
|
|
@@ -130,6 +137,8 @@ export function registerRedirects(scope, ctx) {
|
|
|
130
137
|
catch (e) {
|
|
131
138
|
if (e instanceof InlayError && e.code === 'not_found')
|
|
132
139
|
return notFound(reply, ctx, actor);
|
|
140
|
+
if (e instanceof InlayError && e.code === 'conflict')
|
|
141
|
+
return list(request, reply, 409, { deleteError: e.message });
|
|
133
142
|
throw e;
|
|
134
143
|
}
|
|
135
144
|
return reply.redirect('/admin/redirects?notice=redirectRemoved', 303);
|
|
@@ -20,27 +20,39 @@ function SkipLink() {
|
|
|
20
20
|
return (_jsx("a", { href: "#main", class: "sr-only focus:not-sr-only focus:absolute focus:left-4 focus:top-4 focus:z-50 btn btn-primary", children: t('admin.skipLink') }));
|
|
21
21
|
}
|
|
22
22
|
/** The logo with the brand name as its text, or the name itself. */
|
|
23
|
-
function Brand({ ctx }) {
|
|
23
|
+
function Brand({ ctx, size = 'h-10 max-w-full' }) {
|
|
24
24
|
const { name, logo } = ctx.branding;
|
|
25
|
-
return logo !== undefined ? (_jsx("img", { src: logo, alt: name, class:
|
|
25
|
+
return logo !== undefined ? (_jsx("img", { src: logo, alt: name, class: `${size} w-auto` })) : (_jsx("span", { class: "text-lg font-semibold", children: name }));
|
|
26
26
|
}
|
|
27
27
|
/** The sections `actor` may visit, grouped as in the menu; collections carry their entry counts. */
|
|
28
28
|
function navItems(ctx, actor, counts) {
|
|
29
29
|
const { site } = ctx.core.registry;
|
|
30
30
|
const top = [{ section: 'dashboard', href: '/admin', label: t('admin.nav.dashboard'), icon: 'dashboard' }];
|
|
31
31
|
const content = [];
|
|
32
|
+
const blocks = [];
|
|
33
|
+
const custom = new Map();
|
|
32
34
|
if (site.singletons.length > 0)
|
|
33
35
|
content.push({ section: 'pages', href: '/admin/pages', label: t('admin.nav.pages'), icon: 'file' });
|
|
34
36
|
if (site.globals.length > 0)
|
|
35
37
|
content.push({ section: 'globals', href: '/admin/globals', label: t('admin.nav.globals'), icon: 'globe' });
|
|
38
|
+
const contentTitle = t('admin.nav.content');
|
|
39
|
+
const blocksTitle = t('admin.nav.blocks');
|
|
36
40
|
for (const collection of site.collections) {
|
|
37
|
-
|
|
41
|
+
const item = {
|
|
38
42
|
section: `collection:${collection.name}`,
|
|
39
43
|
href: `/admin/collections/${encodeURIComponent(collection.name)}`,
|
|
40
44
|
label: collection.label,
|
|
41
45
|
icon: 'collection',
|
|
42
46
|
count: counts[collection.name]?.total ?? 0,
|
|
43
|
-
}
|
|
47
|
+
};
|
|
48
|
+
const group = collection.group?.trim() ?? '';
|
|
49
|
+
const hasPages = collection.route !== null || collection.customPaths;
|
|
50
|
+
if (group === contentTitle || (group === '' && hasPages))
|
|
51
|
+
content.push(item);
|
|
52
|
+
else if (group === blocksTitle || group === '')
|
|
53
|
+
blocks.push(item);
|
|
54
|
+
else
|
|
55
|
+
custom.set(group, [...(custom.get(group) ?? []), item]);
|
|
44
56
|
}
|
|
45
57
|
content.push({ section: 'media', href: '/admin/media', label: t('admin.nav.media'), icon: 'image' });
|
|
46
58
|
const siteItems = [{ section: 'redirects', href: '/admin/redirects', label: t('admin.nav.redirects'), icon: 'redirect' }];
|
|
@@ -52,7 +64,13 @@ function navItems(ctx, actor, counts) {
|
|
|
52
64
|
}
|
|
53
65
|
siteItems.push({ section: 'security', href: '/admin/security', label: t('admin.nav.security'), icon: 'lock' });
|
|
54
66
|
}
|
|
55
|
-
|
|
67
|
+
const sections = [
|
|
68
|
+
{ title: contentTitle, items: content },
|
|
69
|
+
...[...custom].map(([title, items]) => ({ title, items })),
|
|
70
|
+
{ title: blocksTitle, items: blocks },
|
|
71
|
+
{ title: t('admin.nav.site'), items: siteItems },
|
|
72
|
+
];
|
|
73
|
+
return { top, sections };
|
|
56
74
|
}
|
|
57
75
|
function NavLink({ item, section }) {
|
|
58
76
|
const current = item.section === section;
|
|
@@ -75,7 +93,9 @@ function PersonMenu({ actor, section }) {
|
|
|
75
93
|
}
|
|
76
94
|
function Nav({ ctx, actor, section, counts, }) {
|
|
77
95
|
const groups = navItems(ctx, actor, counts);
|
|
78
|
-
return (_jsxs("nav", { "aria-label": t('admin.nav.label'), class: "flex flex-1 flex-col", children: [_jsxs("ul", { class: "menu menu-sm w-full flex-1 gap-0.5 px-2 py-3", children: [groups.top.map((item) => (_jsx(NavLink, { item: item, section: section }))),
|
|
96
|
+
return (_jsxs("nav", { "aria-label": t('admin.nav.label'), class: "flex flex-1 flex-col", children: [_jsxs("ul", { class: "menu menu-sm w-full flex-1 gap-0.5 px-2 py-3", children: [groups.top.map((item) => (_jsx(NavLink, { item: item, section: section }))), groups.sections
|
|
97
|
+
.filter((group) => group.items.length > 0)
|
|
98
|
+
.map((group, i) => (_jsxs("li", { children: [_jsx("span", { id: `admin-nav-group-${i}`, class: "menu-title mt-3 text-xs", children: group.title }), _jsx("ul", { "aria-labelledby": `admin-nav-group-${i}`, class: "ms-0 flex flex-col gap-0.5 ps-0 before:hidden", children: group.items.map((item) => (_jsx(NavLink, { item: item, section: section }))) })] })))] }), _jsx("div", { class: "border-t border-base-300 p-2", children: _jsx(PersonMenu, { actor: actor, section: section }) })] }));
|
|
79
99
|
}
|
|
80
100
|
/** A small badge saying the site needs a password; a link to the Security page for owners. */
|
|
81
101
|
function PrivateBadge({ owner }) {
|
|
@@ -122,7 +142,7 @@ export async function adminPage(ctx, opts, body) {
|
|
|
122
142
|
const workspace = opts.layout === 'workspace';
|
|
123
143
|
const page = (_jsxs("html", { lang: "en", "data-theme": ctx.branding.theme.name, children: [_jsx(Head, { ctx: ctx, title: opts.title, scripts: scripts }), _jsxs("body", { class: "min-h-screen bg-base-200 text-base-content", children: [_jsx(SkipLink, {}), _jsxs("div", { class: "drawer lg:drawer-open", children: [_jsx("input", { id: "admin-nav-toggle", type: "checkbox", class: "drawer-toggle lg:hidden", "aria-label": t('admin.nav.open') }), _jsxs("div", { class: workspace ? 'drawer-content flex h-screen flex-col' : 'drawer-content flex min-h-screen flex-col', children: [_jsx(TopBar, { pending: pending.length, locked: lock.enabled, owner: opts.actor.role === 'owner' }), _jsxs("main", { id: "main", tabindex: "-1", class: workspace ? 'flex min-h-0 w-full flex-1 flex-col focus:outline-none' : 'w-full flex-1 px-4 py-4 focus:outline-none lg:px-6 lg:py-5', children: [_jsxs("div", { class: workspace
|
|
124
144
|
? 'flex shrink-0 flex-wrap items-center gap-x-4 gap-y-2 border-b border-base-300 bg-base-100 px-4 py-2.5'
|
|
125
|
-
: 'mb-5 flex flex-wrap items-end justify-between gap-4', children: [_jsxs("div", { class: "min-w-0", children: [_jsx(Breadcrumbs, { items: opts.breadcrumbs ?? [], compact: workspace }), _jsx("h1", { class: workspace ? 'truncate text-lg font-semibold tracking-tight' : 'text-2xl font-semibold tracking-tight', children: opts.title }), opts.description !== undefined && _jsx("p", { class: "text-sm text-base-content/70", children: opts.description })] }), opts.actions !== undefined && (_jsx("div", { class: workspace ? 'flex min-w-0 flex-1 flex-wrap items-center gap-2' : 'flex flex-wrap items-center gap-2', children: opts.actions }))] }), ctx.readOnly && (_jsx("div", { role: "status", class: workspace ? `alert alert-info ${BAR}` : 'alert alert-info mb-4', children: ctx.release ? t('admin.readOnly', { name: ctx.release.name }) : t('admin.readOnly.unnamed') })), _jsx("noscript", { children: _jsx("p", { class: workspace ? `alert alert-warning ${BAR}` : 'alert alert-warning mb-4', children: t('admin.noscript') }) }), notice !== undefined && (_jsx("div", { role: "status", class: workspace ? `alert alert-success ${BAR}` : 'alert alert-success mb-4', children: notice })), workspace ? _jsx("div", { class: "flex min-h-0 flex-1 flex-col", children: body }) : body] })] }), _jsxs("div", { class: "drawer-side z-40", children: [_jsx("label", { for: "admin-nav-toggle", "aria-label": t('admin.nav.close'), class: "drawer-overlay", children: _jsx("span", { class: "sr-only", children: t('admin.nav.close') }) }), _jsxs("aside", { class: "flex min-h-full w-64 flex-col border-r border-base-300 bg-base-100", children: [_jsx("header", { class: "flex h-14 shrink-0 items-center border-b border-base-300 px-4", children: _jsx("a", { href: "/admin", class: "inline-flex min-w-0 items-center", children: _jsx(Brand, { ctx: ctx }) }) }), _jsx(Nav, { ctx: ctx, actor: opts.actor, section: opts.section, counts: counts })] })] })] }), _jsx(PickerDialog, {}), _jsx(PublishDialog, {})] })] }));
|
|
145
|
+
: 'mb-5 flex flex-wrap items-end justify-between gap-4', children: [_jsxs("div", { class: "min-w-0", children: [_jsx(Breadcrumbs, { items: opts.breadcrumbs ?? [], compact: workspace }), _jsx("h1", { class: workspace ? 'truncate text-lg font-semibold tracking-tight' : 'text-2xl font-semibold tracking-tight', children: opts.title }), opts.description !== undefined && _jsx("p", { class: "text-sm text-base-content/70", children: opts.description })] }), opts.actions !== undefined && (_jsx("div", { class: workspace ? 'flex min-w-0 flex-1 flex-wrap items-center gap-2' : 'flex flex-wrap items-center gap-2', children: opts.actions }))] }), ctx.readOnly && (_jsx("div", { role: "status", class: workspace ? `alert alert-info ${BAR}` : 'alert alert-info mb-4', children: ctx.release ? t('admin.readOnly', { name: ctx.release.name }) : t('admin.readOnly.unnamed') })), _jsx("noscript", { children: _jsx("p", { class: workspace ? `alert alert-warning ${BAR}` : 'alert alert-warning mb-4', children: t('admin.noscript') }) }), notice !== undefined && (_jsx("div", { role: "status", class: workspace ? `alert alert-success ${BAR}` : 'alert alert-success mb-4', children: notice })), workspace ? _jsx("div", { class: "flex min-h-0 flex-1 flex-col", children: body }) : body] })] }), _jsxs("div", { class: "drawer-side z-40", children: [_jsx("label", { for: "admin-nav-toggle", "aria-label": t('admin.nav.close'), class: "drawer-overlay", children: _jsx("span", { class: "sr-only", children: t('admin.nav.close') }) }), _jsxs("aside", { class: "flex min-h-full w-64 flex-col border-r border-base-300 bg-base-100", children: [_jsx("header", { class: "flex h-14 shrink-0 items-center border-b border-base-300 px-4", children: _jsx("a", { href: "/admin", class: "inline-flex min-w-0 items-center", children: _jsx(Brand, { ctx: ctx, size: "h-7 max-w-40" }) }) }), _jsx(Nav, { ctx: ctx, actor: opts.actor, section: opts.section, counts: counts })] })] })] }), _jsx(PickerDialog, {}), _jsx(PublishDialog, {})] })] }));
|
|
126
146
|
return `<!doctype html>${await renderToString(page)}`;
|
|
127
147
|
}
|
|
128
148
|
/** A page for someone who isn't signed in (setup, login, consent, uploads): a centered card with the brand, no navigation. */
|
|
@@ -36,7 +36,7 @@ function errorOf(body) {
|
|
|
36
36
|
/**
|
|
37
37
|
* Sends one request with node's own client (no redirects followed, no proxy) on a connection of its own, never one
|
|
38
38
|
* kept from an earlier request (whose worker may be shutting down), and reads the whole answer. `sent` turns true
|
|
39
|
-
* once the request, body and all, has gone out.
|
|
39
|
+
* once the request, body and all, has gone out (for a file, once its last byte is handed over).
|
|
40
40
|
*/
|
|
41
41
|
function send(url, method, headers, file, timeoutMs, sent) {
|
|
42
42
|
return new Promise((resolve, reject) => {
|
|
@@ -53,7 +53,15 @@ function send(url, method, headers, file, timeoutMs, sent) {
|
|
|
53
53
|
request.on('finish', () => (sent.done = true));
|
|
54
54
|
if (file === undefined)
|
|
55
55
|
return void request.end();
|
|
56
|
+
// Sent once every byte is handed over: the stream's own end waits on one more read to find the end of the file,
|
|
57
|
+
// and by then the server, which has all it needs, may already have answered or cut the connection.
|
|
58
|
+
let left = Number(headers['content-length']);
|
|
56
59
|
const body = createReadStream(file);
|
|
60
|
+
body.on('data', (chunk) => {
|
|
61
|
+
left -= chunk.length;
|
|
62
|
+
if (left <= 0)
|
|
63
|
+
sent.done = true;
|
|
64
|
+
});
|
|
57
65
|
body.on('error', (e) => request.destroy(e));
|
|
58
66
|
body.pipe(request);
|
|
59
67
|
});
|
|
@@ -20,7 +20,7 @@ async function redirectsJson(deps, redirects) {
|
|
|
20
20
|
return redirects.map(({ id, from, to, status, source, note }) => ({
|
|
21
21
|
id,
|
|
22
22
|
from,
|
|
23
|
-
to: 'document' in to ? { document: to.document, title: live.get(to.document)?.title ?? null } : to.path,
|
|
23
|
+
to: 'document' in to ? { document: to.document, title: live.get(to.document)?.title ?? null } : 'url' in to ? to.url : to.path,
|
|
24
24
|
status,
|
|
25
25
|
source,
|
|
26
26
|
note,
|
|
@@ -42,7 +42,21 @@ export function register(server, deps, ctx) {
|
|
|
42
42
|
description: t('mcp.tool.list_redirects.description'),
|
|
43
43
|
inputSchema: z.object({}),
|
|
44
44
|
annotations: READ_ONLY,
|
|
45
|
-
}, run(async () =>
|
|
45
|
+
}, run(async () => {
|
|
46
|
+
const admin = await redirectsJson(deps, await deps.core.listRedirects());
|
|
47
|
+
const code = (await deps.core.listCodeRedirects()).map(({ from, to, status, overridden, hidden }) => ({
|
|
48
|
+
id: null,
|
|
49
|
+
from,
|
|
50
|
+
to: 'url' in to ? to.url : to.path,
|
|
51
|
+
status,
|
|
52
|
+
source: 'code',
|
|
53
|
+
note: null,
|
|
54
|
+
readOnly: true,
|
|
55
|
+
overridden,
|
|
56
|
+
hidden,
|
|
57
|
+
}));
|
|
58
|
+
return { redirects: [...admin, ...code] };
|
|
59
|
+
}));
|
|
46
60
|
server.registerTool('create_redirect', {
|
|
47
61
|
title: t('mcp.tool.create_redirect.title'),
|
|
48
62
|
description: t('mcp.tool.create_redirect.description'),
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const ASSET_VERSION_LENGTH = 12;
|
|
2
|
+
/** The first 12 hex characters of the sha256 of `bytes`. */
|
|
3
|
+
export declare function assetVersion(bytes: Uint8Array): string;
|
|
4
|
+
/** The absolute path under `dir` that the raw wildcard names, or null when it is empty, tricky or outside `dir`. */
|
|
5
|
+
export declare function locate(dir: string, rawPath: string): string | null;
|
|
6
|
+
export interface PublicAssets {
|
|
7
|
+
/** The `/public/...` URL for `path`, with `?v=<hash>` when the file is there and servable. Never throws. */
|
|
8
|
+
url(path: string): string;
|
|
9
|
+
}
|
|
10
|
+
/** Versions the files under `dir`, re-hashing a file only when its mtime or size changed. */
|
|
11
|
+
export declare function publicAssets(dir: string | null): PublicAssets;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { resolve, sep } from 'node:path';
|
|
4
|
+
export const ASSET_VERSION_LENGTH = 12;
|
|
5
|
+
const ENCODED = /%2e|%2f|%5c/i;
|
|
6
|
+
/** The first 12 hex characters of the sha256 of `bytes`. */
|
|
7
|
+
export function assetVersion(bytes) {
|
|
8
|
+
return createHash('sha256').update(bytes).digest('hex').slice(0, ASSET_VERSION_LENGTH);
|
|
9
|
+
}
|
|
10
|
+
/** The absolute path under `dir` that the raw wildcard names, or null when it is empty, tricky or outside `dir`. */
|
|
11
|
+
export function locate(dir, rawPath) {
|
|
12
|
+
if (rawPath === '' || ENCODED.test(rawPath) || rawPath.includes('\\'))
|
|
13
|
+
return null;
|
|
14
|
+
let decoded;
|
|
15
|
+
try {
|
|
16
|
+
decoded = decodeURIComponent(rawPath);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (decoded.includes('\\') || decoded.includes('\0'))
|
|
22
|
+
return null;
|
|
23
|
+
const segments = decoded.split('/');
|
|
24
|
+
if (segments.some((s) => s === '' || s.startsWith('.')))
|
|
25
|
+
return null;
|
|
26
|
+
const root = resolve(dir);
|
|
27
|
+
const file = resolve(root, ...segments);
|
|
28
|
+
return file.startsWith(root + sep) ? file : null;
|
|
29
|
+
}
|
|
30
|
+
/** Versions the files under `dir`, re-hashing a file only when its mtime or size changed. */
|
|
31
|
+
export function publicAssets(dir) {
|
|
32
|
+
const cache = new Map();
|
|
33
|
+
function version(encoded) {
|
|
34
|
+
if (dir === null)
|
|
35
|
+
return null;
|
|
36
|
+
try {
|
|
37
|
+
const file = locate(dir, encoded);
|
|
38
|
+
if (file === null)
|
|
39
|
+
return null;
|
|
40
|
+
const stat = lstatSync(file);
|
|
41
|
+
if (!stat.isFile())
|
|
42
|
+
return null;
|
|
43
|
+
if (!realpathSync(file).startsWith(realpathSync(dir) + sep))
|
|
44
|
+
return null;
|
|
45
|
+
const known = cache.get(file);
|
|
46
|
+
if (known && known.mtimeMs === stat.mtimeMs && known.size === stat.size)
|
|
47
|
+
return known.version;
|
|
48
|
+
const bytes = readFileSync(file);
|
|
49
|
+
const fresh = assetVersion(bytes);
|
|
50
|
+
cache.set(file, { version: fresh, mtimeMs: stat.mtimeMs, size: bytes.length });
|
|
51
|
+
return fresh;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
url(path) {
|
|
59
|
+
const bare = path.startsWith('/public/') ? path.slice('/public/'.length) : path.startsWith('/') ? path.slice(1) : path;
|
|
60
|
+
let encoded;
|
|
61
|
+
try {
|
|
62
|
+
encoded = bare.split('/').map(encodeURIComponent).join('/');
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return '/public/';
|
|
66
|
+
}
|
|
67
|
+
const v = version(encoded);
|
|
68
|
+
return v === null ? `/public/${encoded}` : `/public/${encoded}?v=${v}`;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -20,7 +20,8 @@ export declare function cacheControl(opts?: CdnOptions): string;
|
|
|
20
20
|
export declare class PageCache {
|
|
21
21
|
#private;
|
|
22
22
|
readonly maxEntries: number;
|
|
23
|
-
|
|
23
|
+
/** `changedElsewhere`: asked on every lookup; true empties the cache first (a write the site's own core didn't make). */
|
|
24
|
+
constructor(maxEntries: number, changedElsewhere?: () => boolean);
|
|
24
25
|
get generation(): number;
|
|
25
26
|
get size(): number;
|
|
26
27
|
get(key: string): CachedResponse | undefined;
|
|
@@ -27,8 +27,11 @@ export class PageCache {
|
|
|
27
27
|
maxEntries;
|
|
28
28
|
#entries = new Map();
|
|
29
29
|
#generation = 0;
|
|
30
|
-
|
|
30
|
+
#changedElsewhere;
|
|
31
|
+
/** `changedElsewhere`: asked on every lookup; true empties the cache first (a write the site's own core didn't make). */
|
|
32
|
+
constructor(maxEntries, changedElsewhere = () => false) {
|
|
31
33
|
this.maxEntries = maxEntries;
|
|
34
|
+
this.#changedElsewhere = changedElsewhere;
|
|
32
35
|
}
|
|
33
36
|
get generation() {
|
|
34
37
|
return this.#generation;
|
|
@@ -37,6 +40,8 @@ export class PageCache {
|
|
|
37
40
|
return this.#entries.size;
|
|
38
41
|
}
|
|
39
42
|
get(key) {
|
|
43
|
+
if (this.#changedElsewhere())
|
|
44
|
+
this.clear();
|
|
40
45
|
const value = this.#entries.get(key);
|
|
41
46
|
if (value === undefined)
|
|
42
47
|
return undefined;
|
|
@@ -3,18 +3,23 @@ import type { TemplateDef } from '../../core/registry/define.js';
|
|
|
3
3
|
import type { RenderContext } from '../../core/registry/render.js';
|
|
4
4
|
import type { QueryApi } from '../../core/registry/route.js';
|
|
5
5
|
import type { DocumentData, LiveDocument, LiveState } from '../../core/types.js';
|
|
6
|
+
import { type PublicAssets } from './assets.js';
|
|
7
|
+
import { type CollectedHead } from './head.js';
|
|
6
8
|
export interface RenderContextOptions {
|
|
7
9
|
locale: string;
|
|
8
10
|
state: LiveState;
|
|
9
11
|
page: number;
|
|
10
12
|
baseUrl: string;
|
|
11
13
|
alternates: RenderContext['alternates'];
|
|
14
|
+
assets?: PublicAssets;
|
|
12
15
|
}
|
|
13
16
|
export type PreloadingRenderContext = RenderContext & {
|
|
14
17
|
/** Loads the media and documents `docs` refer to, so `image`, `file`, `link` and `richText` can resolve them. */
|
|
15
18
|
preload(docs: LiveDocument[]): Promise<void>;
|
|
16
19
|
/** As `preload`, for `data` of `template` that no document holds (a page a route renders). */
|
|
17
20
|
preloadData(template: TemplateDef, data: DocumentData): Promise<void>;
|
|
21
|
+
/** What `head` collected so far. */
|
|
22
|
+
headTags(): CollectedHead;
|
|
18
23
|
};
|
|
19
24
|
/**
|
|
20
25
|
* The `ctx` templates and blocks receive. Synchronous helpers resolve only what was preloaded:
|
|
@@ -26,4 +31,5 @@ export declare function createRenderContext(core: Core, opts: RenderContextOptio
|
|
|
26
31
|
export declare function queryApi(core: Core, opts: {
|
|
27
32
|
locale: string;
|
|
28
33
|
baseUrl: string;
|
|
34
|
+
assets?: PublicAssets;
|
|
29
35
|
}): QueryApi;
|
|
@@ -4,8 +4,11 @@ import { validateContent } from '../../core/content/validate.js';
|
|
|
4
4
|
import { isRasterImage } from '../../core/media/detect.js';
|
|
5
5
|
import { IMAGE_WIDTHS } from '../../core/media/variants.js';
|
|
6
6
|
import { richTextToHtml } from '../../core/richtext/html.js';
|
|
7
|
+
import { inlineTextToHtml } from '../../core/richtext/inline.js';
|
|
7
8
|
import { encodePath } from '../../core/site/paths.js';
|
|
8
|
-
import {
|
|
9
|
+
import { publicAssets } from './assets.js';
|
|
10
|
+
import { createHeadCollector } from './head.js';
|
|
11
|
+
import { escapeHtml, raw } from '../../jsx/html.js';
|
|
9
12
|
/** Rich text images get this width as `src` when the original is at least as wide. */
|
|
10
13
|
const RICH_TEXT_SRC_WIDTH = 1280;
|
|
11
14
|
const nonEmpty = (s) => typeof s === 'string' && s !== '';
|
|
@@ -54,6 +57,7 @@ function toEntry(doc) {
|
|
|
54
57
|
title: doc.title,
|
|
55
58
|
slug: doc.slug,
|
|
56
59
|
updatedAt: doc.updatedAt,
|
|
60
|
+
publishedAt: doc.publishedAt,
|
|
57
61
|
fields: doc.data.fields,
|
|
58
62
|
};
|
|
59
63
|
}
|
|
@@ -71,6 +75,17 @@ function sortEntries(entries, sort) {
|
|
|
71
75
|
return entries;
|
|
72
76
|
if (sort === 'oldest')
|
|
73
77
|
return [...entries].reverse();
|
|
78
|
+
if (sort === 'published') {
|
|
79
|
+
return [...entries].sort((a, b) => {
|
|
80
|
+
if (a.publishedAt === b.publishedAt)
|
|
81
|
+
return 0;
|
|
82
|
+
if (a.publishedAt === null)
|
|
83
|
+
return 1;
|
|
84
|
+
if (b.publishedAt === null)
|
|
85
|
+
return -1;
|
|
86
|
+
return a.publishedAt < b.publishedAt ? 1 : -1;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
74
89
|
const sign = sort.direction === 'desc' ? -1 : 1;
|
|
75
90
|
const value = (e) => e.fields[sort.field];
|
|
76
91
|
return [...entries].sort((a, b) => {
|
|
@@ -91,10 +106,12 @@ export function createRenderContext(core, opts) {
|
|
|
91
106
|
const { registry } = core;
|
|
92
107
|
const { locale, state } = opts;
|
|
93
108
|
const preview = state === 'preview';
|
|
109
|
+
const assets = opts.assets ?? publicAssets(null);
|
|
94
110
|
const media = new Map();
|
|
95
111
|
const docs = new Map();
|
|
96
112
|
const collections = new Map();
|
|
97
113
|
const globals = new Map();
|
|
114
|
+
const head = createHeadCollector();
|
|
98
115
|
/**
|
|
99
116
|
* Whether `doc` can be shown as is. In preview, a draft that isn't complete can't: an entry is
|
|
100
117
|
* then treated as not live, and a singleton or global falls back to its published version.
|
|
@@ -177,20 +194,24 @@ export function createRenderContext(core, opts) {
|
|
|
177
194
|
const text = nonEmpty(v.text) ? v.text : nonEmpty(target.title) ? target.title : target.href;
|
|
178
195
|
return { href: target.href, text, external: false };
|
|
179
196
|
}
|
|
197
|
+
const resolver = {
|
|
198
|
+
link: (groupId) => documentHref(groupId)?.href ?? null,
|
|
199
|
+
image: (id, alt) => {
|
|
200
|
+
const info = media.get(id);
|
|
201
|
+
if (!info)
|
|
202
|
+
return null;
|
|
203
|
+
const img = resolveImage(info, alt);
|
|
204
|
+
const width = Math.min(img.width ?? RICH_TEXT_SRC_WIDTH, RICH_TEXT_SRC_WIDTH);
|
|
205
|
+
return { src: img.src(width), srcset: img.srcset(), alt: img.alt, width: img.width, height: img.height };
|
|
206
|
+
},
|
|
207
|
+
};
|
|
180
208
|
function richText(doc) {
|
|
181
|
-
|
|
209
|
+
return raw(doc ? richTextToHtml(doc, resolver) : '');
|
|
210
|
+
}
|
|
211
|
+
function inline(value) {
|
|
212
|
+
if (value === null || value === undefined)
|
|
182
213
|
return raw('');
|
|
183
|
-
return raw(
|
|
184
|
-
link: (groupId) => documentHref(groupId)?.href ?? null,
|
|
185
|
-
image: (id, alt) => {
|
|
186
|
-
const info = media.get(id);
|
|
187
|
-
if (!info)
|
|
188
|
-
return null;
|
|
189
|
-
const img = resolveImage(info, alt);
|
|
190
|
-
const width = Math.min(img.width ?? RICH_TEXT_SRC_WIDTH, RICH_TEXT_SRC_WIDTH);
|
|
191
|
-
return { src: img.src(width), srcset: img.srcset(), alt: img.alt, width: img.width, height: img.height };
|
|
192
|
-
},
|
|
193
|
-
}));
|
|
214
|
+
return raw(typeof value === 'string' ? escapeHtml(value) : inlineTextToHtml(value, resolver));
|
|
194
215
|
}
|
|
195
216
|
async function entries(ids) {
|
|
196
217
|
const list = ids === null || ids === undefined ? [] : typeof ids === 'string' ? [ids] : [...ids];
|
|
@@ -259,16 +280,20 @@ export function createRenderContext(core, opts) {
|
|
|
259
280
|
preview,
|
|
260
281
|
page: opts.page,
|
|
261
282
|
baseUrl: opts.baseUrl,
|
|
283
|
+
asset: (path) => assets.url(path),
|
|
284
|
+
head: head.api,
|
|
262
285
|
alternates: opts.alternates,
|
|
263
286
|
image,
|
|
264
287
|
file,
|
|
265
288
|
link,
|
|
266
289
|
richText,
|
|
290
|
+
inline,
|
|
267
291
|
entries,
|
|
268
292
|
query,
|
|
269
293
|
global,
|
|
270
294
|
preload,
|
|
271
295
|
preloadData,
|
|
296
|
+
headTags: head.collected,
|
|
272
297
|
};
|
|
273
298
|
}
|
|
274
299
|
/** Published content at `locale`, the way templates query it, for one request. */
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { OgType } from '../../core/registry/define.js';
|
|
2
|
+
import type { HeadApi, HeadLink } from '../../core/registry/render.js';
|
|
3
3
|
import { type SafeHtml } from '../../jsx/html.js';
|
|
4
4
|
export interface HeadInput {
|
|
5
|
+
/** The final `<title>` text. */
|
|
5
6
|
title: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
description: string | null;
|
|
8
|
+
/** Absolute URL of the share image. */
|
|
9
|
+
image: string | null;
|
|
10
|
+
ogType: OgType;
|
|
11
|
+
/** Only for `ogType: 'article'` on a document page. */
|
|
12
|
+
article: {
|
|
13
|
+
publishedTime: string | null;
|
|
14
|
+
modifiedTime: string;
|
|
10
15
|
} | null;
|
|
11
16
|
/** Decoded site path, with `?page=N` when paginated; `null` for a page with no URL of its own, which gets noindex. */
|
|
12
17
|
canonical: string | null;
|
|
@@ -15,9 +20,27 @@ export interface HeadInput {
|
|
|
15
20
|
path: string;
|
|
16
21
|
}>;
|
|
17
22
|
defaultLocale: string;
|
|
18
|
-
image: ResolvedImage | null;
|
|
19
23
|
baseUrl: string;
|
|
20
24
|
preview: boolean;
|
|
25
|
+
/** What the render added through `ctx.head`. */
|
|
26
|
+
collected?: CollectedHead;
|
|
21
27
|
}
|
|
28
|
+
/** What templates and blocks added through `ctx.head`, in call order. */
|
|
29
|
+
export interface CollectedHead {
|
|
30
|
+
meta: Array<{
|
|
31
|
+
attr: 'name' | 'property';
|
|
32
|
+
key: string;
|
|
33
|
+
content: string;
|
|
34
|
+
}>;
|
|
35
|
+
links: HeadLink[];
|
|
36
|
+
/** Each already written as JSON and escaped for a `<script>`. */
|
|
37
|
+
jsonLd: string[];
|
|
38
|
+
}
|
|
39
|
+
export declare const NO_HEAD: CollectedHead;
|
|
40
|
+
/** The `ctx.head` of one render, and what it collected. */
|
|
41
|
+
export declare function createHeadCollector(): {
|
|
42
|
+
api: HeadApi;
|
|
43
|
+
collected(): CollectedHead;
|
|
44
|
+
};
|
|
22
45
|
export declare function buildHead(input: HeadInput): SafeHtml;
|
|
23
46
|
export declare function injectHead(html: string, head: SafeHtml): string;
|