inlaycms 0.4.1 → 0.6.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 +18 -709
- package/assets/admin/admin.css +1 -1
- package/assets/admin/admin.js +1 -1
- package/assets/admin/editor.js +63 -46
- package/assets/site/consent.js +1 -0
- package/dist/adapters/admin/context.d.ts +1 -1
- package/dist/adapters/admin/context.js +1 -0
- package/dist/adapters/admin/publish.js +2 -2
- package/dist/adapters/admin/routes.d.ts +2 -0
- package/dist/adapters/admin/routes.js +2 -0
- package/dist/adapters/admin/screens/backups.js +2 -2
- package/dist/adapters/admin/screens/editor.js +5 -2
- package/dist/adapters/admin/screens/integrations.d.ts +4 -0
- package/dist/adapters/admin/screens/integrations.js +140 -0
- package/dist/adapters/admin/screens/lists.js +2 -1
- package/dist/adapters/admin/screens/releases.js +9 -4
- package/dist/adapters/admin/views/data-table.js +1 -1
- package/dist/adapters/admin/views/layout.d.ts +1 -1
- package/dist/adapters/admin/views/layout.js +15 -2
- package/dist/adapters/cli/bin.js +8 -3
- package/dist/adapters/cli/main.js +12 -2
- package/dist/adapters/mcp/agent-refs.d.ts +2 -1
- package/dist/adapters/mcp/agent-refs.js +4 -4
- package/dist/adapters/mcp/tools/publish.js +1 -1
- package/dist/adapters/mcp/tools/read.js +19 -4
- package/dist/adapters/mcp/tools/write.js +5 -1
- package/dist/adapters/site/cache.d.ts +8 -2
- package/dist/adapters/site/cache.js +13 -4
- package/dist/adapters/site/code-files.d.ts +44 -0
- package/dist/adapters/site/code-files.js +212 -0
- package/dist/adapters/site/consent.d.ts +9 -0
- package/dist/adapters/site/consent.js +26 -0
- package/dist/adapters/site/context.d.ts +9 -1
- package/dist/adapters/site/context.js +106 -27
- package/dist/adapters/site/csp.d.ts +11 -0
- package/dist/adapters/site/csp.js +36 -0
- package/dist/adapters/site/head.d.ts +2 -0
- package/dist/adapters/site/head.js +7 -20
- package/dist/adapters/site/headers.d.ts +5 -2
- package/dist/adapters/site/headers.js +13 -6
- package/dist/adapters/site/integrations.d.ts +48 -0
- package/dist/adapters/site/integrations.js +118 -0
- package/dist/adapters/site/media-routes.d.ts +2 -0
- package/dist/adapters/site/media-routes.js +2 -1
- package/dist/adapters/site/plugin.d.ts +2 -0
- package/dist/adapters/site/plugin.js +78 -40
- package/dist/adapters/site/preview.d.ts +2 -0
- package/dist/adapters/site/preview.js +10 -5
- package/dist/adapters/site/render.d.ts +31 -14
- package/dist/adapters/site/render.js +33 -7
- package/dist/adapters/site/routes.d.ts +3 -0
- package/dist/adapters/site/routes.js +11 -6
- package/dist/adapters/site/scripts.d.ts +6 -0
- package/dist/adapters/site/scripts.js +27 -0
- package/dist/adapters/site/sitemap.d.ts +2 -1
- package/dist/adapters/site/sitemap.js +3 -3
- package/dist/core/auth/roles.d.ts +1 -1
- package/dist/core/auth/roles.js +1 -0
- package/dist/core/boot.d.ts +2 -0
- package/dist/core/boot.js +3 -0
- package/dist/core/content/shipped-input.js +1 -2
- package/dist/core/content/validate.d.ts +7 -0
- package/dist/core/content/validate.js +24 -1
- package/dist/core/core.d.ts +29 -0
- package/dist/core/core.js +10 -2
- package/dist/core/db/migrate.js +2 -0
- package/dist/core/db/migrations/0008_integrations.d.ts +3 -0
- package/dist/core/db/migrations/0008_integrations.js +11 -0
- package/dist/core/db/schema.d.ts +11 -0
- package/dist/core/export/export.js +4 -0
- package/dist/core/export/format.d.ts +11 -0
- package/dist/core/export/format.js +4 -0
- package/dist/core/export/import.js +2 -1
- package/dist/core/export/replace.d.ts +6 -1
- package/dist/core/export/replace.js +4 -1
- package/dist/core/export/report.d.ts +6 -0
- package/dist/core/export/report.js +7 -0
- package/dist/core/fields/builtins.d.ts +4 -0
- package/dist/core/fields/builtins.js +11 -1
- package/dist/core/fields/widgets.js +5 -1
- package/dist/core/integrations/integrations.d.ts +32 -0
- package/dist/core/integrations/integrations.js +80 -0
- package/dist/core/integrations/warnings.d.ts +4 -0
- package/dist/core/integrations/warnings.js +29 -0
- package/dist/core/media/store.d.ts +2 -0
- package/dist/core/media/store.js +17 -1
- package/dist/core/media/variants.d.ts +14 -0
- package/dist/core/media/variants.js +54 -0
- package/dist/core/messages/en.d.ts +83 -2
- package/dist/core/messages/en.js +83 -2
- package/dist/core/registry/code-image.d.ts +16 -0
- package/dist/core/registry/code-image.js +13 -0
- package/dist/core/registry/define.d.ts +12 -0
- package/dist/core/registry/define.js +3 -0
- package/dist/core/registry/designed.d.ts +6 -0
- package/dist/core/registry/designed.js +8 -0
- package/dist/core/registry/integration.d.ts +48 -0
- package/dist/core/registry/integration.js +29 -0
- package/dist/core/registry/js.d.ts +9 -0
- package/dist/core/registry/js.js +39 -0
- package/dist/core/registry/registry.js +46 -0
- package/dist/core/registry/render.d.ts +45 -5
- package/dist/core/release/bundle.d.ts +3 -1
- package/dist/core/release/bundle.js +169 -11
- package/dist/core/release/manifest.d.ts +29 -6
- package/dist/core/release/manifest.js +26 -25
- package/dist/core/release/pack.js +13 -2
- package/dist/core/release/pointer.js +14 -3
- package/dist/core/release/read.d.ts +4 -2
- package/dist/core/release/read.js +12 -12
- package/dist/core/release/window.d.ts +11 -0
- package/dist/core/release/window.js +34 -0
- package/dist/core/report.d.ts +3 -0
- package/dist/core/richtext/headings.d.ts +10 -0
- package/dist/core/richtext/headings.js +37 -0
- package/dist/core/richtext/html.d.ts +10 -1
- package/dist/core/richtext/html.js +17 -6
- package/dist/core/richtext/markdown-text.d.ts +24 -0
- package/dist/core/richtext/markdown-text.js +38 -0
- package/dist/core/richtext/markdown.js +44 -3
- package/dist/core/richtext/schema.d.ts +12 -3
- package/dist/core/richtext/schema.js +34 -0
- package/dist/core/site/live.d.ts +6 -0
- package/dist/core/site/live.js +25 -0
- package/dist/core/site/paths.d.ts +5 -0
- package/dist/core/site/paths.js +32 -0
- package/dist/core/site/resolve.js +17 -6
- package/dist/core/version.d.ts +4 -0
- package/dist/core/version.js +4 -0
- package/dist/host/activate.js +2 -1
- package/dist/host/app.d.ts +2 -0
- package/dist/host/app.js +1 -0
- package/dist/host/diff.d.ts +11 -0
- package/dist/host/diff.js +40 -0
- package/dist/host/ipc.d.ts +2 -0
- package/dist/host/ipc.js +5 -1
- package/dist/host/preview-worker.js +2 -2
- package/dist/host/primary.js +15 -4
- package/dist/host/push.d.ts +5 -1
- package/dist/host/push.js +18 -6
- package/dist/host/serve.js +1 -1
- package/dist/host/store.d.ts +1 -2
- package/dist/host/store.js +32 -6
- package/dist/host/worker.js +9 -3
- package/dist/image-modules.d.ts +29 -0
- package/dist/image-modules.js +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +4 -0
- package/dist/site.d.ts +9 -2
- package/dist/site.js +5 -0
- package/package.json +5 -1
|
@@ -9,7 +9,7 @@ import { DEFAULT_MAX_BYTES, DEFAULT_UPLOAD_TYPES } from '../../core/media/detect
|
|
|
9
9
|
import { t } from '../../core/messages/index.js';
|
|
10
10
|
import { externalTarget } from '../../core/redirects/rule.js';
|
|
11
11
|
import { buildRegistry } from '../../core/registry/registry.js';
|
|
12
|
-
import { encodePath, normalizePath, splitLocale } from '../../core/site/paths.js';
|
|
12
|
+
import { encodePath, normalizePath, presentHref, splitLocale } from '../../core/site/paths.js';
|
|
13
13
|
import { loadAdminAssets } from '../admin/assets.js';
|
|
14
14
|
import { registerAdminRoutes } from '../admin/routes.js';
|
|
15
15
|
import { resolveTheme, themeContrastProblems } from '../admin/theme.js';
|
|
@@ -20,16 +20,19 @@ import { fetchRemoteFile } from '../mcp/fetch-url.js';
|
|
|
20
20
|
import { registerMcpRoute } from '../mcp/route.js';
|
|
21
21
|
import { createInlayMcpHandler } from '../mcp/server.js';
|
|
22
22
|
import { sendWebResponse, toWebRequest } from '../web.js';
|
|
23
|
+
import { loadConsentAsset, registerConsentRoute } from './consent.js';
|
|
23
24
|
import { publicAssets } from './assets.js';
|
|
24
25
|
import { cacheControl, etagMatches, PageCache, response } from './cache.js';
|
|
25
26
|
import { createRenderContext } from './context.js';
|
|
26
27
|
import { registerSiteHeaders, siteHeaders } from './headers.js';
|
|
28
|
+
import { createSiteIntegrations } from './integrations.js';
|
|
27
29
|
import { startBackupSchedule } from './backup-schedule.js';
|
|
28
30
|
import { isLockedRequest, registerSiteLockGate, registerUnlockRoute } from './lock.js';
|
|
31
|
+
import { codeFilesFor, registerCodeFileRoutes } from './code-files.js';
|
|
29
32
|
import { registerMediaRoutes } from './media-routes.js';
|
|
30
33
|
import { registerPublicRoutes } from './public.js';
|
|
31
34
|
import { previewLink, readPreview, registerPreviewRoutes } from './preview.js';
|
|
32
|
-
import { catalogPage,
|
|
35
|
+
import { catalogPage, renderPageResult } from './render.js';
|
|
33
36
|
import { registerReleaseRoutes } from './routes.js';
|
|
34
37
|
import { renderSitemap } from './sitemap.js';
|
|
35
38
|
/** Where tests find the plugin's `AuthService` on `app.inlay`; not part of the public API. */
|
|
@@ -116,18 +119,23 @@ function createApi(core, cache, service, opts) {
|
|
|
116
119
|
};
|
|
117
120
|
return Object.defineProperty(api, AUTH, { value: service, enumerable: false });
|
|
118
121
|
}
|
|
119
|
-
function registerSiteRoutes(app, core, cache, opts) {
|
|
122
|
+
function registerSiteRoutes(app, core, cache, integrations, opts) {
|
|
120
123
|
const { registry } = core;
|
|
121
|
-
const { notFound } = registry.site;
|
|
124
|
+
const { notFound, trailingSlash: mode } = registry.site;
|
|
125
|
+
const always = mode === 'always';
|
|
122
126
|
const { baseUrl, cdn, assets } = opts;
|
|
123
127
|
const banner = opts.release === undefined ? {} : { release: opts.release };
|
|
124
128
|
async function notFoundPage(locale, state) {
|
|
125
129
|
if (notFound !== null) {
|
|
126
130
|
const doc = await core.liveSingleton(notFound, locale, { state });
|
|
127
131
|
if (doc)
|
|
128
|
-
return
|
|
132
|
+
return renderPageResult(core, doc, { state, page: 1, baseUrl, assets, integrations, ...banner });
|
|
129
133
|
}
|
|
130
|
-
return catalogPage('site.notFound.title', 'site.notFound');
|
|
134
|
+
return { html: catalogPage('site.notFound.title', 'site.notFound'), scriptHashes: [] };
|
|
135
|
+
}
|
|
136
|
+
/** `page` as a response carrying its own content-security-policy, when Inlay sets one. */
|
|
137
|
+
async function pageResponse(status, page) {
|
|
138
|
+
return response(status, page.html, HTML, (await integrations.policy(page.scriptHashes)) ?? undefined);
|
|
131
139
|
}
|
|
132
140
|
function localeOf(rawPath) {
|
|
133
141
|
const path = normalizePath(rawPath);
|
|
@@ -139,29 +147,34 @@ function registerSiteRoutes(app, core, cache, opts) {
|
|
|
139
147
|
if (hit !== undefined)
|
|
140
148
|
reply.header('x-inlay-cache', hit ? 'hit' : 'miss');
|
|
141
149
|
reply.header('cache-control', control).header('vary', 'Cookie').header('etag', res.etag);
|
|
150
|
+
if (res.csp !== undefined)
|
|
151
|
+
reply.header('content-security-policy', res.csp);
|
|
142
152
|
if (etagMatches(request.headers['if-none-match'], res.etag))
|
|
143
153
|
return reply.code(304).send();
|
|
144
154
|
return reply.code(res.status).type(res.type).send(res.body);
|
|
145
155
|
}
|
|
146
156
|
/** Preview responses are never stored or revalidated. */
|
|
147
|
-
function sendPreview(reply, status,
|
|
148
|
-
|
|
157
|
+
async function sendPreview(reply, status, page) {
|
|
158
|
+
const csp = await integrations.policy(page.scriptHashes);
|
|
159
|
+
if (csp !== null)
|
|
160
|
+
reply.header('content-security-policy', csp);
|
|
161
|
+
return reply.code(status).type(HTML).send(page.html);
|
|
149
162
|
}
|
|
150
163
|
/** Serves `key` from the cache, or renders it and stores the result unless a live change landed meanwhile. */
|
|
151
|
-
async function cached(request, reply, key,
|
|
164
|
+
async function cached(request, reply, key, render) {
|
|
152
165
|
if (!cache)
|
|
153
|
-
return send(request, reply,
|
|
166
|
+
return send(request, reply, await render(), undefined);
|
|
154
167
|
const hit = cache.get(key);
|
|
155
168
|
if (hit)
|
|
156
169
|
return send(request, reply, hit, true);
|
|
157
170
|
const generation = cache.generation;
|
|
158
|
-
const res =
|
|
171
|
+
const res = await render();
|
|
159
172
|
cache.set(key, res, generation);
|
|
160
173
|
return send(request, reply, res, false);
|
|
161
174
|
}
|
|
162
175
|
const missing = async (request, reply, locale, state) => state === 'preview'
|
|
163
176
|
? sendPreview(reply, 404, await notFoundPage(locale, state))
|
|
164
|
-
: cached(request, reply, `404:${locale}`,
|
|
177
|
+
: cached(request, reply, `404:${locale}`, async () => pageResponse(404, await notFoundPage(locale, state)));
|
|
165
178
|
/** A cookie that previews a staged release reaches this app only when that preview isn't available: the live site answers. */
|
|
166
179
|
function stateOf(request) {
|
|
167
180
|
if (request.headers.cookie === undefined)
|
|
@@ -182,7 +195,8 @@ function registerSiteRoutes(app, core, cache, opts) {
|
|
|
182
195
|
return await missing(request, reply, localeOf(path), state);
|
|
183
196
|
const pageNumber = Number(pageParam ?? 1);
|
|
184
197
|
const normalized = normalizePath(path);
|
|
185
|
-
const
|
|
198
|
+
const presented = normalized === null ? null : presentHref(encodePath(normalized), mode);
|
|
199
|
+
const canonical = presented !== null && presented === path;
|
|
186
200
|
const key = preview || normalized === null || !canonical
|
|
187
201
|
? null
|
|
188
202
|
: pageNumber > 1
|
|
@@ -192,20 +206,26 @@ function registerSiteRoutes(app, core, cache, opts) {
|
|
|
192
206
|
if (hit)
|
|
193
207
|
return send(request, reply, hit, true);
|
|
194
208
|
const generation = cache?.generation ?? 0;
|
|
195
|
-
|
|
209
|
+
if (always && presented !== null && !canonical && registry.getRoutePaths.has(normalized ?? '')) {
|
|
210
|
+
return reply.redirect(`${presented}${search}`, 301);
|
|
211
|
+
}
|
|
212
|
+
const lookup = always && path.length > 1 && path.endsWith('/') ? path.slice(0, -1) : path;
|
|
213
|
+
const match = await core.resolvePath(lookup, { state });
|
|
196
214
|
if (match.kind === 'redirect') {
|
|
197
215
|
if (match.external === true && externalTarget(match.location) === match.location) {
|
|
198
216
|
return reply.redirect(match.location, match.status);
|
|
199
217
|
}
|
|
200
218
|
if (match.external !== true && match.location.startsWith('/') && !match.location.startsWith('//')) {
|
|
201
|
-
return reply.redirect(`${match.location}${search}`, match.status);
|
|
219
|
+
return reply.redirect(`${presentHref(match.location, mode)}${search}`, match.status);
|
|
202
220
|
}
|
|
203
221
|
}
|
|
204
222
|
if (match.kind === 'page') {
|
|
205
|
-
|
|
223
|
+
if (always && !canonical && presented !== null)
|
|
224
|
+
return reply.redirect(`${presented}${search}`, 301);
|
|
225
|
+
const page = await renderPageResult(core, match.document, { state, page: pageNumber, baseUrl, assets, integrations, ...banner });
|
|
206
226
|
if (preview)
|
|
207
|
-
return sendPreview(reply, 200,
|
|
208
|
-
const res =
|
|
227
|
+
return await sendPreview(reply, 200, page);
|
|
228
|
+
const res = await pageResponse(200, page);
|
|
209
229
|
if (cache && key !== null) {
|
|
210
230
|
cache.set(key, res, generation);
|
|
211
231
|
return send(request, reply, res, false);
|
|
@@ -229,7 +249,7 @@ function registerSiteRoutes(app, core, cache, opts) {
|
|
|
229
249
|
// A site that is down has no sitemap to give: an empty one would tell search engines its pages are gone.
|
|
230
250
|
app.get('/sitemap.xml', async (request, reply) => opts.noSite === 'unavailable'
|
|
231
251
|
? unavailable(request, reply)
|
|
232
|
-
: cached(request, reply, 'sitemap.xml',
|
|
252
|
+
: cached(request, reply, 'sitemap.xml', async () => response(200, renderSitemap(await core.sitemapEntries(), baseUrl, core.registry.site.trailingSlash), 'application/xml')));
|
|
233
253
|
app.get('/robots.txt', async (request, reply) => {
|
|
234
254
|
reply.type('text/plain; charset=utf-8');
|
|
235
255
|
if (isLockedRequest(request))
|
|
@@ -325,6 +345,7 @@ const plugin = async (app, opts) => {
|
|
|
325
345
|
...(opts.now && { now: opts.now }),
|
|
326
346
|
...(opts.content && { content: opts.content }),
|
|
327
347
|
...(opts.shippedFiles && { shippedFiles: opts.shippedFiles }),
|
|
348
|
+
...(opts.codeFiles && { codeFiles: opts.codeFiles }),
|
|
328
349
|
auth: { secret, baseUrl, ...(opts.rateLimit !== undefined && { rateLimit: opts.rateLimit }) },
|
|
329
350
|
});
|
|
330
351
|
const { db, report, auth } = booted;
|
|
@@ -350,12 +371,42 @@ const plugin = async (app, opts) => {
|
|
|
350
371
|
}
|
|
351
372
|
}
|
|
352
373
|
const core = opts.readOnly ? readOnlyCore(booted.core) : booted.core;
|
|
353
|
-
for (const warning of report.warnings)
|
|
354
|
-
|
|
374
|
+
for (const warning of report.warnings) {
|
|
375
|
+
if ('document' in warning)
|
|
376
|
+
app.log.warn({ document: warning.document }, warning.message);
|
|
377
|
+
else if ('redirect' in warning)
|
|
378
|
+
app.log.warn({ redirect: warning.redirect }, warning.message);
|
|
379
|
+
else
|
|
380
|
+
app.log.warn(warning.message);
|
|
381
|
+
}
|
|
355
382
|
for (const warning of report.shipped.warnings ?? [])
|
|
356
383
|
app.log.warn(warning.message);
|
|
357
384
|
const now = opts.now ?? (() => new Date());
|
|
358
|
-
|
|
385
|
+
// A commit from another connection (the other worker during a `serve` swap, a second `inlaycms dev`) changes
|
|
386
|
+
// data_version; this connection's own writes don't, and the live ones among them clear the cache below.
|
|
387
|
+
let seen = dataVersion(db);
|
|
388
|
+
const changedElsewhere = () => {
|
|
389
|
+
const version = dataVersion(db);
|
|
390
|
+
if (version === seen)
|
|
391
|
+
return false;
|
|
392
|
+
seen = version;
|
|
393
|
+
return true;
|
|
394
|
+
};
|
|
395
|
+
const cache = opts.cache === false ? undefined : new PageCache(opts.cache?.maxEntries ?? 500, changedElsewhere);
|
|
396
|
+
// Without a page cache, an empty one still counts live changes, so the integrations' settings are read again after one.
|
|
397
|
+
const generations = cache ?? new PageCache(0, changedElsewhere);
|
|
398
|
+
const stopGenerations = core.onLiveChange(() => generations.clear());
|
|
399
|
+
app.addHook('onClose', async () => stopGenerations());
|
|
400
|
+
const consentAsset = await loadConsentAsset();
|
|
401
|
+
registerConsentRoute(app, consentAsset);
|
|
402
|
+
const siteIntegrations = createSiteIntegrations({
|
|
403
|
+
core,
|
|
404
|
+
site: registry.site,
|
|
405
|
+
generation: () => generations.generation,
|
|
406
|
+
consentUrl: consentAsset.url,
|
|
407
|
+
log: (err, message) => app.log.error({ err }, message),
|
|
408
|
+
});
|
|
409
|
+
registerSiteHeaders(app, siteHeaders(baseUrl, registry.site.headers), () => siteIntegrations.policy());
|
|
359
410
|
const lockOptions = { db, service: auth, secret, baseUrl, now, publicPaths };
|
|
360
411
|
registerSiteLockGate(app, { ...lockOptions, ...(opts.preview === 'forced' && opts.release && { release: opts.release.id }) });
|
|
361
412
|
registerUnlockRoute(app, { ...lockOptions, rateLimit: opts.rateLimit !== false });
|
|
@@ -375,21 +426,6 @@ const plugin = async (app, opts) => {
|
|
|
375
426
|
await db.destroy();
|
|
376
427
|
});
|
|
377
428
|
const siteAssets = publicAssets(opts.publicDir ?? null);
|
|
378
|
-
// A commit from another connection (the other worker during a `serve` swap, a second `inlaycms dev`) changes
|
|
379
|
-
// data_version; this connection's own writes don't, and the live ones among them clear the cache below.
|
|
380
|
-
let seen = dataVersion(db);
|
|
381
|
-
const changedElsewhere = () => {
|
|
382
|
-
const version = dataVersion(db);
|
|
383
|
-
if (version === seen)
|
|
384
|
-
return false;
|
|
385
|
-
seen = version;
|
|
386
|
-
return true;
|
|
387
|
-
};
|
|
388
|
-
const cache = opts.cache === false ? undefined : new PageCache(opts.cache?.maxEntries ?? 500, changedElsewhere);
|
|
389
|
-
if (cache) {
|
|
390
|
-
const stop = core.onLiveChange(() => cache.clear());
|
|
391
|
-
app.addHook('onClose', async () => stop());
|
|
392
|
-
}
|
|
393
429
|
if (baseUrl.startsWith('https:') && !app.initialConfig.https)
|
|
394
430
|
warnWithoutTrustProxy(app, baseUrl);
|
|
395
431
|
app.decorate('inlay', createApi(core, cache, auth, { baseUrl, secret, now, host: opts.host ?? null, assets: siteAssets }));
|
|
@@ -415,6 +451,7 @@ const plugin = async (app, opts) => {
|
|
|
415
451
|
release: opts.release ?? null,
|
|
416
452
|
...(opts.readOnly && { readOnly: true }),
|
|
417
453
|
...(opts.releasesDir !== undefined && { releasesDir: opts.releasesDir }),
|
|
454
|
+
mediaDir: opts.media ?? next('media'),
|
|
418
455
|
...(opts.trustedKeys && { trustedKeys: opts.trustedKeys }),
|
|
419
456
|
...(opts.adminHost && { host: opts.adminHost }),
|
|
420
457
|
});
|
|
@@ -439,11 +476,12 @@ const plugin = async (app, opts) => {
|
|
|
439
476
|
},
|
|
440
477
|
});
|
|
441
478
|
registerMediaRoutes(app, core);
|
|
479
|
+
registerCodeFileRoutes(app, codeFilesFor(core), core);
|
|
442
480
|
if (opts.publicDir !== undefined)
|
|
443
481
|
registerPublicRoutes(app, { dir: opts.publicDir, maxAge: opts.publicMaxAge ?? 3600 });
|
|
444
|
-
registerReleaseRoutes(app, { core, registry, baseUrl, assets: siteAssets, secrets: opts.secrets ?? {}, fetch: opts.fetch ?? ((input, init) => globalThis.fetch(input, init)), log: app.log, preview: opts.preview === 'forced' });
|
|
445
|
-
registerPreviewRoutes(app, { secret, baseUrl, now });
|
|
446
|
-
registerSiteRoutes(app, core, cache, {
|
|
482
|
+
registerReleaseRoutes(app, { core, registry, baseUrl, assets: siteAssets, integrations: siteIntegrations, secrets: opts.secrets ?? {}, fetch: opts.fetch ?? ((input, init) => globalThis.fetch(input, init)), log: app.log, preview: opts.preview === 'forced' });
|
|
483
|
+
registerPreviewRoutes(app, { secret, baseUrl, now, trailingSlash: registry.site.trailingSlash });
|
|
484
|
+
registerSiteRoutes(app, core, cache, siteIntegrations, {
|
|
447
485
|
baseUrl,
|
|
448
486
|
secret,
|
|
449
487
|
now,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FastifyInstance, FastifyReply, FastifyRequest } from 'fastify';
|
|
2
|
+
import { type TrailingSlash } from '../../core/site/paths.js';
|
|
2
3
|
import type { LiveState } from '../../core/types.js';
|
|
3
4
|
export declare const PREVIEW_COOKIE = "inlay_preview";
|
|
4
5
|
export declare const PREVIEW_PATH = "/_inlay/preview";
|
|
@@ -33,4 +34,5 @@ export declare function registerPreviewRoutes(app: FastifyInstance, opts: {
|
|
|
33
34
|
secret: string;
|
|
34
35
|
baseUrl: string;
|
|
35
36
|
now: () => Date;
|
|
37
|
+
trailingSlash?: TrailingSlash;
|
|
36
38
|
}): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createPreviewToken, verifyPreviewToken } from '../../core/preview.js';
|
|
2
|
-
import { encodePath, normalizePath } from '../../core/site/paths.js';
|
|
2
|
+
import { encodePath, normalizePath, presentHref } from '../../core/site/paths.js';
|
|
3
3
|
import { catalogPage, PREVIEW_EXIT_PATH } from './render.js';
|
|
4
4
|
export const PREVIEW_COOKIE = 'inlay_preview';
|
|
5
5
|
export const PREVIEW_PATH = '/_inlay/preview';
|
|
@@ -37,12 +37,16 @@ export function readPreview(request, secret, now) {
|
|
|
37
37
|
export function previewState(request, secret, now) {
|
|
38
38
|
return readPreview(request, secret, now).state;
|
|
39
39
|
}
|
|
40
|
-
/** `raw` when it's a clean, encoded site-relative path, otherwise `/`. */
|
|
41
|
-
function safeTarget(raw) {
|
|
40
|
+
/** `raw` in its presented form when it's a clean, encoded site-relative path, otherwise `/`. */
|
|
41
|
+
function safeTarget(raw, mode) {
|
|
42
42
|
if (typeof raw !== 'string')
|
|
43
43
|
return '/';
|
|
44
44
|
const normalized = normalizePath(raw);
|
|
45
|
-
|
|
45
|
+
if (normalized === null)
|
|
46
|
+
return '/';
|
|
47
|
+
const encoded = encodePath(normalized);
|
|
48
|
+
const presented = presentHref(encoded, mode);
|
|
49
|
+
return raw === encoded || raw === presented ? presented : '/';
|
|
46
50
|
}
|
|
47
51
|
/** Turns preview off for this browser. */
|
|
48
52
|
export function clearPreviewCookie(reply, baseUrl) {
|
|
@@ -59,6 +63,7 @@ function setCookie(reply, value, maxAge, secure) {
|
|
|
59
63
|
* release a release link previews); `GET /_inlay/preview/exit` turns it off.
|
|
60
64
|
*/
|
|
61
65
|
export function registerPreviewRoutes(app, opts) {
|
|
66
|
+
const mode = opts.trailingSlash ?? 'never';
|
|
62
67
|
const secure = opts.baseUrl.startsWith('https:');
|
|
63
68
|
app.get(PREVIEW_PATH, async (request, reply) => {
|
|
64
69
|
const query = request.query;
|
|
@@ -73,7 +78,7 @@ export function registerPreviewRoutes(app, opts) {
|
|
|
73
78
|
.send(catalogPage('preview.expired.title', 'preview.expired'));
|
|
74
79
|
}
|
|
75
80
|
setCookie(reply, token, Math.ceil((valid.expiresAt.getTime() - now.getTime()) / 1000), secure);
|
|
76
|
-
return reply.redirect(safeTarget(query.path), 302);
|
|
81
|
+
return reply.redirect(safeTarget(query.path, mode), 302);
|
|
77
82
|
});
|
|
78
83
|
app.get(PREVIEW_EXIT_PATH, async (_request, reply) => {
|
|
79
84
|
setCookie(reply, '', 0, secure);
|
|
@@ -4,23 +4,34 @@ import type { TemplateDef } from '../../core/registry/define.js';
|
|
|
4
4
|
import type { ContentIssue, DocumentData, LiveDocument, LiveState } from '../../core/types.js';
|
|
5
5
|
import { type SafeHtml } from '../../jsx/html.js';
|
|
6
6
|
import type { PublicAssets } from './assets.js';
|
|
7
|
+
import { type SiteIntegrations } from './integrations.js';
|
|
7
8
|
export declare const PREVIEW_EXIT_PATH = "/_inlay/preview/exit";
|
|
8
9
|
/** A page Inlay renders itself (in the catalog's language), with `body` (Inlay-built HTML) under its `title` heading. */
|
|
9
10
|
export declare function inlayPage(title: string, body: SafeHtml): string;
|
|
10
11
|
/** A page Inlay renders itself, in the catalog's language. */
|
|
11
12
|
export declare function catalogPage(titleId: MessageId, bodyId: MessageId): string;
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
/** A rendered page and the `'sha256-…'` hashes of the inline scripts it wrote through `ctx.script`. */
|
|
14
|
+
export interface RenderedPage {
|
|
15
|
+
html: string;
|
|
16
|
+
scriptHashes: string[];
|
|
17
|
+
}
|
|
18
|
+
type PageOptions = {
|
|
18
19
|
state: LiveState;
|
|
19
20
|
page: number;
|
|
20
21
|
baseUrl: string;
|
|
21
22
|
release?: string;
|
|
22
23
|
assets?: PublicAssets;
|
|
23
|
-
|
|
24
|
+
/** Renders the site's active integrations into the page; without it, none are. */
|
|
25
|
+
integrations?: SiteIntegrations;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Renders `doc` through its template, with its enabled slots rendered by their blocks. Render errors propagate.
|
|
29
|
+
* In preview the page gets the preview banner (naming `release`, the name of the staged release previewed, when
|
|
30
|
+
* given), and a draft that fails strict validation gets a list of its problems instead of its template.
|
|
31
|
+
*/
|
|
32
|
+
export declare function renderPage(core: Core, doc: LiveDocument, opts: PageOptions): Promise<string>;
|
|
33
|
+
/** `renderPage`, with the hashes of the page's inline scripts. */
|
|
34
|
+
export declare function renderPageResult(core: Core, doc: LiveDocument, opts: PageOptions): Promise<RenderedPage>;
|
|
24
35
|
export type PaneResult = {
|
|
25
36
|
ok: true;
|
|
26
37
|
html: string;
|
|
@@ -35,16 +46,22 @@ export declare function renderPane(core: Core, doc: LiveDocument, opts: {
|
|
|
35
46
|
page: number;
|
|
36
47
|
baseUrl: string;
|
|
37
48
|
}): Promise<PaneResult>;
|
|
38
|
-
|
|
39
|
-
* `template` rendered with `data` (already read with `fill`) as a published page at `path` that no document backs,
|
|
40
|
-
* such as one a route returns: no canonical link and no alternates. Its title is the `title` field when that is
|
|
41
|
-
* text, else the template's label or name. Render errors propagate.
|
|
42
|
-
*/
|
|
43
|
-
export declare function renderTemplateData(core: Core, template: TemplateDef, data: DocumentData, opts: {
|
|
49
|
+
type TemplateDataOptions = {
|
|
44
50
|
locale: string;
|
|
45
51
|
path: string;
|
|
46
52
|
baseUrl: string;
|
|
47
53
|
canonical?: string | null;
|
|
48
54
|
assets?: PublicAssets;
|
|
49
55
|
preview?: boolean;
|
|
50
|
-
|
|
56
|
+
/** Renders the site's active integrations into the page; without it, none are. */
|
|
57
|
+
integrations?: SiteIntegrations;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* `template` rendered with `data` (already read with `fill`) as a published page at `path` that no document backs,
|
|
61
|
+
* such as one a route returns: no canonical link and no alternates. Its title is the `title` field when that is
|
|
62
|
+
* text, else the template's label or name. Render errors propagate.
|
|
63
|
+
*/
|
|
64
|
+
export declare function renderTemplateData(core: Core, template: TemplateDef, data: DocumentData, opts: TemplateDataOptions): Promise<string>;
|
|
65
|
+
/** `renderTemplateData`, with the hashes of the page's inline scripts. */
|
|
66
|
+
export declare function renderTemplateResult(core: Core, template: TemplateDef, data: DocumentData, opts: TemplateDataOptions): Promise<RenderedPage>;
|
|
67
|
+
export {};
|
|
@@ -2,9 +2,11 @@ import { validateContent } from '../../core/content/validate.js';
|
|
|
2
2
|
import { InlayError } from '../../core/errors.js';
|
|
3
3
|
import { fieldMeta } from '../../core/fields/define.js';
|
|
4
4
|
import { t } from '../../core/messages/index.js';
|
|
5
|
+
import { presentPath } from '../../core/site/paths.js';
|
|
5
6
|
import { escapeHtml, raw, renderToString, toHtml } from '../../jsx/html.js';
|
|
6
|
-
import { createRenderContext } from './context.js';
|
|
7
|
+
import { createRenderContext, pageUrl } from './context.js';
|
|
7
8
|
import { buildHead, injectHead } from './head.js';
|
|
9
|
+
import { injectIntegrations } from './integrations.js';
|
|
8
10
|
import { isHomePath, mediaShareImage, pageTitle, resolveSeoDefaults } from './seo.js';
|
|
9
11
|
const DOCTYPE = /^\s*<!doctype\s/i;
|
|
10
12
|
const BODY = /<body\b[^>]*>/i;
|
|
@@ -52,6 +54,10 @@ function withPreviewBanner(html, release) {
|
|
|
52
54
|
* given), and a draft that fails strict validation gets a list of its problems instead of its template.
|
|
53
55
|
*/
|
|
54
56
|
export async function renderPage(core, doc, opts) {
|
|
57
|
+
return (await renderPageResult(core, doc, opts)).html;
|
|
58
|
+
}
|
|
59
|
+
/** `renderPage`, with the hashes of the page's inline scripts. */
|
|
60
|
+
export async function renderPageResult(core, doc, opts) {
|
|
55
61
|
const { release, ...render } = opts;
|
|
56
62
|
if (render.state !== 'preview')
|
|
57
63
|
return renderTemplate(core, doc, render);
|
|
@@ -59,9 +65,10 @@ export async function renderPage(core, doc, opts) {
|
|
|
59
65
|
if (!checked.ok) {
|
|
60
66
|
const items = checked.issues.map((issue) => `<li>${escapeHtml(issue.message)}</li>`).join('');
|
|
61
67
|
const body = raw(`<p>${escapeHtml(t('preview.incomplete'))}</p><ul>${items}</ul>`);
|
|
62
|
-
return withPreviewBanner(catalogDocument('preview.incomplete.title', body), release);
|
|
68
|
+
return { html: withPreviewBanner(catalogDocument('preview.incomplete.title', body), release), scriptHashes: [] };
|
|
63
69
|
}
|
|
64
|
-
|
|
70
|
+
const rendered = await renderTemplate(core, doc, render);
|
|
71
|
+
return { html: withPreviewBanner(rendered.html, release), scriptHashes: rendered.scriptHashes };
|
|
65
72
|
}
|
|
66
73
|
export const SLOT_START = (key) => `<!--inlay:slot ${key}-->`;
|
|
67
74
|
export const SLOT_END = (key) => `<!--/inlay:slot ${key}-->`;
|
|
@@ -73,7 +80,7 @@ export async function renderPane(core, doc, opts) {
|
|
|
73
80
|
const checked = validateContent(core.registry, doc.type, doc.data, 'strict');
|
|
74
81
|
if (!checked.ok)
|
|
75
82
|
return { ok: false, issues: checked.issues };
|
|
76
|
-
return { ok: true, html: await renderTemplate(core, doc, { ...opts, state: 'preview' }, { pane: true }) };
|
|
83
|
+
return { ok: true, html: (await renderTemplate(core, doc, { ...opts, state: 'preview' }, { pane: true })).html };
|
|
77
84
|
}
|
|
78
85
|
/** `template` rendered with `data` and its enabled slots rendered by their blocks: the page before its head is added. */
|
|
79
86
|
async function renderBody(template, data, page, ctx, internal) {
|
|
@@ -95,6 +102,12 @@ async function renderBody(template, data, page, ctx, internal) {
|
|
|
95
102
|
return renderToString(template.render({ fields: data.fields, slots, data: slotData, page }, ctx));
|
|
96
103
|
}
|
|
97
104
|
const withDoctype = (html) => (DOCTYPE.test(html) ? html : `<!doctype html>${html}`);
|
|
105
|
+
/** `html` with the active integrations rendered for `page` through `ctx.script`, when `integrations` is given. */
|
|
106
|
+
async function withIntegrations(html, integrations, page, ctx) {
|
|
107
|
+
if (!integrations)
|
|
108
|
+
return html;
|
|
109
|
+
return injectIntegrations(html, await integrations.render(page, ctx.script));
|
|
110
|
+
}
|
|
98
111
|
async function renderTemplate(core, doc, opts, internal = {}) {
|
|
99
112
|
const { template } = core.registry.getType(doc.type);
|
|
100
113
|
if (!template.render)
|
|
@@ -116,6 +129,7 @@ async function renderTemplate(core, doc, opts, internal = {}) {
|
|
|
116
129
|
contentLocale: doc.contentLocale,
|
|
117
130
|
fallback: doc.fallback,
|
|
118
131
|
path: doc.path ?? '',
|
|
132
|
+
url: pageUrl(doc.path ?? '', core.registry.site.trailingSlash),
|
|
119
133
|
publishedAt: doc.publishedAt,
|
|
120
134
|
page: opts.page,
|
|
121
135
|
};
|
|
@@ -136,6 +150,7 @@ async function renderTemplate(core, doc, opts, internal = {}) {
|
|
|
136
150
|
alternates: doc.fallback ? [] : alternates.filter((a) => !a.fallback),
|
|
137
151
|
defaultLocale: core.registry.defaultLocale,
|
|
138
152
|
baseUrl: opts.baseUrl,
|
|
153
|
+
trailingSlash: core.registry.site.trailingSlash,
|
|
139
154
|
preview: opts.state === 'preview',
|
|
140
155
|
collected: ctx.headTags(),
|
|
141
156
|
});
|
|
@@ -144,10 +159,13 @@ async function renderTemplate(core, doc, opts, internal = {}) {
|
|
|
144
159
|
const open = HEAD_OPEN.exec(out);
|
|
145
160
|
if (open) {
|
|
146
161
|
const at = open.index + open[0].length;
|
|
147
|
-
out = `${out.slice(0, at)}<base href="${escapeHtml(doc.path)}">${out.slice(at)}`;
|
|
162
|
+
out = `${out.slice(0, at)}<base href="${escapeHtml(presentPath(doc.path, core.registry.site.trailingSlash))}">${out.slice(at)}`;
|
|
148
163
|
}
|
|
149
164
|
}
|
|
150
|
-
|
|
165
|
+
if (!internal.pane) {
|
|
166
|
+
out = await withIntegrations(out, opts.integrations, { path: page.path, locale: doc.locale, preview: ctx.preview }, ctx);
|
|
167
|
+
}
|
|
168
|
+
return { html: withDoctype(out), scriptHashes: ctx.scriptHashes() };
|
|
151
169
|
}
|
|
152
170
|
/**
|
|
153
171
|
* `template` rendered with `data` (already read with `fill`) as a published page at `path` that no document backs,
|
|
@@ -155,6 +173,10 @@ async function renderTemplate(core, doc, opts, internal = {}) {
|
|
|
155
173
|
* text, else the template's label or name. Render errors propagate.
|
|
156
174
|
*/
|
|
157
175
|
export async function renderTemplateData(core, template, data, opts) {
|
|
176
|
+
return (await renderTemplateResult(core, template, data, opts)).html;
|
|
177
|
+
}
|
|
178
|
+
/** `renderTemplateData`, with the hashes of the page's inline scripts. */
|
|
179
|
+
export async function renderTemplateResult(core, template, data, opts) {
|
|
158
180
|
const ctx = createRenderContext(core, {
|
|
159
181
|
locale: opts.locale,
|
|
160
182
|
state: 'published',
|
|
@@ -173,6 +195,7 @@ export async function renderTemplateData(core, template, data, opts) {
|
|
|
173
195
|
contentLocale: opts.locale,
|
|
174
196
|
fallback: false,
|
|
175
197
|
path: opts.path,
|
|
198
|
+
url: pageUrl(opts.path, core.registry.site.trailingSlash),
|
|
176
199
|
publishedAt: null,
|
|
177
200
|
page: 1,
|
|
178
201
|
};
|
|
@@ -189,10 +212,13 @@ export async function renderTemplateData(core, template, data, opts) {
|
|
|
189
212
|
alternates: [],
|
|
190
213
|
defaultLocale: core.registry.defaultLocale,
|
|
191
214
|
baseUrl: opts.baseUrl,
|
|
215
|
+
trailingSlash: core.registry.site.trailingSlash,
|
|
192
216
|
preview: opts.preview === true,
|
|
193
217
|
collected: ctx.headTags(),
|
|
194
218
|
});
|
|
195
|
-
|
|
219
|
+
const at = { path: opts.path, locale: opts.locale, preview: opts.preview === true };
|
|
220
|
+
const out = await withIntegrations(injectHead(html, head), opts.integrations, at, ctx);
|
|
221
|
+
return { html: withDoctype(out), scriptHashes: ctx.scriptHashes() };
|
|
196
222
|
}
|
|
197
223
|
/** The value of the first top-level field marked by `f.seo()`. */
|
|
198
224
|
function seoValue(fields, values) {
|
|
@@ -2,11 +2,14 @@ import type { FastifyBaseLogger, FastifyInstance } from 'fastify';
|
|
|
2
2
|
import type { Core } from '../../core/core.js';
|
|
3
3
|
import type { Registry } from '../../core/registry/registry.js';
|
|
4
4
|
import { type PublicAssets } from './assets.js';
|
|
5
|
+
import type { SiteIntegrations } from './integrations.js';
|
|
5
6
|
export interface ReleaseRouteOptions {
|
|
6
7
|
core: Core;
|
|
7
8
|
registry: Registry;
|
|
8
9
|
baseUrl: string;
|
|
9
10
|
assets?: PublicAssets;
|
|
11
|
+
/** Renders the active integrations into a rendered template's page, and gives it its content-security-policy. */
|
|
12
|
+
integrations?: SiteIntegrations;
|
|
10
13
|
/** The site is a staged release's forced preview: its renders stay noindex, with no canonical. */
|
|
11
14
|
preview?: boolean;
|
|
12
15
|
/** Host-supplied secret values; a route sees only the ones its site declares. */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { normalizeContent } from '../../core/content/schema.js';
|
|
2
2
|
import { readData } from '../../core/content/reader.js';
|
|
3
3
|
import { t } from '../../core/messages/index.js';
|
|
4
|
-
import { encodePath } from '../../core/site/paths.js';
|
|
4
|
+
import { encodePath, presentPath } from '../../core/site/paths.js';
|
|
5
5
|
import { publicAssets } from './assets.js';
|
|
6
6
|
import { queryApi } from './context.js';
|
|
7
|
-
import { catalogPage,
|
|
7
|
+
import { catalogPage, renderTemplateResult } from './render.js';
|
|
8
8
|
const BODY_LIMIT = 1024 * 1024;
|
|
9
9
|
const HTML = 'text/html; charset=utf-8';
|
|
10
10
|
/** Headers a route never sees: routes run anonymous. */
|
|
@@ -89,9 +89,10 @@ export function registerReleaseRoutes(app, opts) {
|
|
|
89
89
|
register(scope, route);
|
|
90
90
|
});
|
|
91
91
|
function register(scope, route) {
|
|
92
|
+
const url = route.method === 'GET' ? presentPath(route.path, registry.site.trailingSlash) : route.path;
|
|
92
93
|
scope.route({
|
|
93
94
|
method: route.method,
|
|
94
|
-
url
|
|
95
|
+
url,
|
|
95
96
|
handler: async (request, reply) => {
|
|
96
97
|
const query = plainQuery(request.url);
|
|
97
98
|
const type = request.headers['content-type'] ?? '';
|
|
@@ -112,9 +113,13 @@ export function registerReleaseRoutes(app, opts) {
|
|
|
112
113
|
async render(template, data = {}, o = {}) {
|
|
113
114
|
const read = templateRegistry(registry, template);
|
|
114
115
|
const doc = readData(read, template.name, normalizeContent(read, template.name, data), { fill: true }).data;
|
|
115
|
-
const canonical = route.sitemap === true && request.url.split('?')[0] === encodePath(
|
|
116
|
-
const
|
|
117
|
-
|
|
116
|
+
const canonical = route.sitemap === true && request.url.split('?')[0] === encodePath(url) ? route.path : null;
|
|
117
|
+
const rendered = await renderTemplateResult(core, template, doc, { locale, path: route.path, baseUrl, canonical, assets, preview: opts.preview === true, ...(opts.integrations && { integrations: opts.integrations }) });
|
|
118
|
+
const csp = (await opts.integrations?.policy(rendered.scriptHashes)) ?? null;
|
|
119
|
+
const headers = { 'content-type': HTML };
|
|
120
|
+
if (csp !== null)
|
|
121
|
+
headers['content-security-policy'] = csp;
|
|
122
|
+
return { status: o.status ?? 200, headers, body: rendered.html };
|
|
118
123
|
},
|
|
119
124
|
fetch: opts.fetch,
|
|
120
125
|
secrets,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ScriptApi } from '../../core/registry/render.js';
|
|
2
|
+
/** The `ctx.script` of one render, and the `'sha256-…'` hashes of the inline scripts it wrote, in call order. */
|
|
3
|
+
export declare function createScriptCollector(): {
|
|
4
|
+
api: ScriptApi;
|
|
5
|
+
hashes(): string[];
|
|
6
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { InlayError } from '../../core/errors.js';
|
|
3
|
+
import { isSafeUrl } from '../../core/fields/define.js';
|
|
4
|
+
import { JsCode } from '../../core/registry/js.js';
|
|
5
|
+
import { escapeHtml, raw } from '../../jsx/html.js';
|
|
6
|
+
const UNSAFE_CODE = /<\/script|<!--/i;
|
|
7
|
+
/** The `ctx.script` of one render, and the `'sha256-…'` hashes of the inline scripts it wrote, in call order. */
|
|
8
|
+
export function createScriptCollector() {
|
|
9
|
+
const hashes = new Set();
|
|
10
|
+
const api = (input) => {
|
|
11
|
+
if (typeof input === 'string' || input instanceof JsCode) {
|
|
12
|
+
// the browser hashes the text as it parsed it: line breaks as \n, and NUL replaced, so NUL is refused
|
|
13
|
+
const code = (typeof input === 'string' ? input : input.code).replace(/\r\n?/g, '\n');
|
|
14
|
+
if (UNSAFE_CODE.test(code) || code.includes('\u0000'))
|
|
15
|
+
throw new InlayError('config', 'config.scriptCode');
|
|
16
|
+
hashes.add(`'sha256-${createHash('sha256').update(code).digest('base64')}'`);
|
|
17
|
+
return raw(`<script>${code}</script>`);
|
|
18
|
+
}
|
|
19
|
+
const { src } = input;
|
|
20
|
+
const ok = isSafeUrl(src) && (/^https:\/\//i.test(src) || (src.startsWith('/') && !src.startsWith('//')));
|
|
21
|
+
if (!ok)
|
|
22
|
+
throw new InlayError('config', 'config.scriptSrc', { src });
|
|
23
|
+
const type = input.type === 'module' ? ' type="module"' : '';
|
|
24
|
+
return raw(`<script${type} src="${escapeHtml(src)}"${input.async ? ' async' : ''}${input.defer ? ' defer' : ''}></script>`);
|
|
25
|
+
};
|
|
26
|
+
return { api, hashes: () => [...hashes] };
|
|
27
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TrailingSlash } from '../../core/site/paths.js';
|
|
1
2
|
interface Item {
|
|
2
3
|
path: string;
|
|
3
4
|
updatedAt?: string;
|
|
@@ -6,5 +7,5 @@ interface Item {
|
|
|
6
7
|
path: string;
|
|
7
8
|
}>;
|
|
8
9
|
}
|
|
9
|
-
export declare function renderSitemap(entries: readonly Item[], baseUrl: string): string;
|
|
10
|
+
export declare function renderSitemap(entries: readonly Item[], baseUrl: string, trailingSlash: TrailingSlash): string;
|
|
10
11
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { escapeHtml } from '../../jsx/html.js';
|
|
2
|
-
import { encodePath } from '../../core/site/paths.js';
|
|
3
|
-
export function renderSitemap(entries, baseUrl) {
|
|
4
|
-
const url = (path) => escapeHtml(`${baseUrl}${path === '/' ? '/' : encodePath(path)}`);
|
|
2
|
+
import { encodePath, presentHref } from '../../core/site/paths.js';
|
|
3
|
+
export function renderSitemap(entries, baseUrl, trailingSlash) {
|
|
4
|
+
const url = (path) => escapeHtml(`${baseUrl}${path === '/' ? '/' : presentHref(encodePath(path), trailingSlash)}`);
|
|
5
5
|
const items = entries.map((e) => {
|
|
6
6
|
const links = e.alternates.map((a) => `<xhtml:link rel="alternate" hreflang="${escapeHtml(a.locale)}" href="${url(a.path)}"/>`);
|
|
7
7
|
return `<url><loc>${url(e.path)}</loc>${e.updatedAt === undefined ? '' : `<lastmod>${escapeHtml(e.updatedAt.slice(0, 10))}</lastmod>`}${links.join('')}</url>`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Actor, Ctx, RevisionSource, Role } from '../types.js';
|
|
2
|
-
export type Action = 'content.read' | 'content.write' | 'content.publish' | 'entry.delete' | 'entry.restore' | 'backup.create' | 'backup.read' | 'content.export' | 'content.import' | 'media.write' | 'redirects.write' | 'users.manage' | 'site.protect' | 'release.push' | 'release.activate' | 'release.manage';
|
|
2
|
+
export type Action = 'content.read' | 'content.write' | 'content.publish' | 'entry.delete' | 'entry.restore' | 'backup.create' | 'backup.read' | 'content.export' | 'content.import' | 'media.write' | 'redirects.write' | 'users.manage' | 'site.protect' | 'integrations.manage' | 'release.push' | 'release.activate' | 'release.manage';
|
|
3
3
|
export declare function can(role: Role, action: Action): boolean;
|
|
4
4
|
/** Whether an API key may push releases: its user is an owner now and the key was made with the `release:push` permission. */
|
|
5
5
|
export declare function canPush(actor: Actor, permissions: {
|