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
|
@@ -4,7 +4,7 @@ export function renderSitemap(entries, baseUrl) {
|
|
|
4
4
|
const url = (path) => escapeHtml(`${baseUrl}${path === '/' ? '/' : encodePath(path)}`);
|
|
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
|
-
return `<url><loc>${url(e.path)}</loc
|
|
7
|
+
return `<url><loc>${url(e.path)}</loc>${e.updatedAt === undefined ? '' : `<lastmod>${escapeHtml(e.updatedAt.slice(0, 10))}</lastmod>`}${links.join('')}</url>`;
|
|
8
8
|
});
|
|
9
9
|
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">${items.join('')}</urlset>\n`;
|
|
10
10
|
}
|
package/dist/config.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
2
|
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
6
|
import { InlayError } from './core/errors.js';
|
|
7
|
+
import { siteDirUrl } from './core/release/site-dir.js';
|
|
7
8
|
export function defineConfig(c) {
|
|
8
9
|
return c;
|
|
9
10
|
}
|
|
@@ -47,7 +48,7 @@ export async function loadConfig(file) {
|
|
|
47
48
|
const media = config.media !== undefined ? fromBase(config.media) : near('media');
|
|
48
49
|
return {
|
|
49
50
|
config: {
|
|
50
|
-
site: config.site,
|
|
51
|
+
site: { ...config.site, siteDir: siteDirUrl(realpathSync(dir)) },
|
|
51
52
|
...(db !== undefined && { db }),
|
|
52
53
|
...(backups !== undefined && { backups }),
|
|
53
54
|
...(media !== undefined && { media }),
|
|
@@ -73,7 +73,7 @@ export function toAgent(registry, type, data, refs) {
|
|
|
73
73
|
slots,
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
const RICH_TEXT = new Set(['richText']);
|
|
76
|
+
const RICH_TEXT = new Set(['richText', 'inlineText']);
|
|
77
77
|
/** Every `inlay:` link and image target in the document's rich text, with what it points to. */
|
|
78
78
|
export function agentLinks(registry, type, data, refs) {
|
|
79
79
|
const { template } = registry.getType(type);
|
|
@@ -27,12 +27,15 @@ function decorate(registry, meta, json) {
|
|
|
27
27
|
meta.kind === 'ref' && meta.target !== undefined
|
|
28
28
|
? t('agent.refTarget', { label: registry.getType(meta.target).label })
|
|
29
29
|
: undefined,
|
|
30
|
+
meta.suggestedLength !== undefined ? t('agent.suggestedLength', { n: meta.suggestedLength }) : undefined,
|
|
30
31
|
meta.help,
|
|
31
32
|
].filter((part) => part !== undefined);
|
|
32
33
|
if (description.length > 0)
|
|
33
34
|
json.description = description.join(' ');
|
|
34
35
|
if (meta.setting)
|
|
35
36
|
json['x-setting'] = true;
|
|
37
|
+
if (meta.suggestedLength !== undefined)
|
|
38
|
+
json['x-suggestedLength'] = meta.suggestedLength;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* The JSON Schema (draft 2020-12) of an `AgentDocument` of `type`, as the assistant
|
package/dist/core/boot.js
CHANGED
|
@@ -48,6 +48,13 @@ export async function upgradeDatabase(db, core, systemMigrations, auth, opts = {
|
|
|
48
48
|
document: { id: d.id, type: d.type, locale: d.locale, title: d.title },
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
+
for (const { from, hidden } of await core.listCodeRedirects()) {
|
|
52
|
+
if (hidden)
|
|
53
|
+
report.warnings.push({ code: 'redirect_hidden', message: t('report.redirectHidden', { from }), redirect: { from } });
|
|
54
|
+
}
|
|
55
|
+
for (const from of await core.codeRedirectLoops()) {
|
|
56
|
+
report.warnings.push({ code: 'redirect_loop', message: t('report.redirectLoop', { from }), redirect: { from } });
|
|
57
|
+
}
|
|
51
58
|
return report;
|
|
52
59
|
}
|
|
53
60
|
/** True for a database that has never been set up: no content tables yet. */
|
package/dist/core/check.js
CHANGED
|
@@ -82,7 +82,12 @@ export async function checkWithoutDatabase(opts) {
|
|
|
82
82
|
const db = join(dir, 'empty.db');
|
|
83
83
|
await writeFile(db, '');
|
|
84
84
|
const report = await checkDatabase({ ...opts, db });
|
|
85
|
-
return {
|
|
85
|
+
return {
|
|
86
|
+
...emptyCheckReport(),
|
|
87
|
+
ok: report.ok,
|
|
88
|
+
problems: report.problems,
|
|
89
|
+
warnings: report.warnings.filter((w) => w.code !== 'redirect_hidden'),
|
|
90
|
+
};
|
|
86
91
|
}
|
|
87
92
|
finally {
|
|
88
93
|
await rm(dir, { recursive: true, force: true });
|
|
@@ -5,12 +5,13 @@ export declare class DryRun extends Error {
|
|
|
5
5
|
/**
|
|
6
6
|
* Runs `fn` in a transaction. When `deps.db` is already a transaction, `fn`
|
|
7
7
|
* runs in a savepoint of it: a throw rolls back only what `fn` wrote, and
|
|
8
|
-
* the rest commits or rolls back with the outer transaction.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* SQLITE_BUSY_SNAPSHOT; it waits for that connection
|
|
12
|
-
*
|
|
13
|
-
*
|
|
8
|
+
* the rest commits or rolls back with the outer transaction. A new transaction
|
|
9
|
+
* takes the write lock before `fn` reads anything, so a commit from another
|
|
10
|
+
* connection (another process on the same database) can't make its first write
|
|
11
|
+
* fail with SQLITE_BUSY or SQLITE_BUSY_SNAPSHOT; it waits for that connection
|
|
12
|
+
* instead. `write` says the caller needs that guarantee for everything it
|
|
13
|
+
* reads: inside a transaction it throws `error.transactionWrite`, since the
|
|
14
|
+
* outer one may not have taken the lock first.
|
|
14
15
|
*/
|
|
15
16
|
export declare function withTransaction<T>(deps: CoreDeps, fn: (tx: CoreDeps) => Promise<T>, opts?: {
|
|
16
17
|
write?: true;
|
|
@@ -7,18 +7,18 @@ const savepoints = new WeakMap();
|
|
|
7
7
|
/**
|
|
8
8
|
* Runs `fn` in a transaction. When `deps.db` is already a transaction, `fn`
|
|
9
9
|
* runs in a savepoint of it: a throw rolls back only what `fn` wrote, and
|
|
10
|
-
* the rest commits or rolls back with the outer transaction.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* SQLITE_BUSY_SNAPSHOT; it waits for that connection
|
|
14
|
-
*
|
|
15
|
-
*
|
|
10
|
+
* the rest commits or rolls back with the outer transaction. A new transaction
|
|
11
|
+
* takes the write lock before `fn` reads anything, so a commit from another
|
|
12
|
+
* connection (another process on the same database) can't make its first write
|
|
13
|
+
* fail with SQLITE_BUSY or SQLITE_BUSY_SNAPSHOT; it waits for that connection
|
|
14
|
+
* instead. `write` says the caller needs that guarantee for everything it
|
|
15
|
+
* reads: inside a transaction it throws `error.transactionWrite`, since the
|
|
16
|
+
* outer one may not have taken the lock first.
|
|
16
17
|
*/
|
|
17
18
|
export async function withTransaction(deps, fn, opts = {}) {
|
|
18
19
|
if (!deps.db.isTransaction) {
|
|
19
20
|
return deps.db.transaction().execute(async (trx) => {
|
|
20
|
-
|
|
21
|
-
await sql `update releases set name = name where id = ''`.execute(trx);
|
|
21
|
+
await sql `update releases set name = name where id = ''`.execute(trx);
|
|
22
22
|
return fn({ ...deps, db: trx });
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -7,7 +7,7 @@ export interface PublishResult {
|
|
|
7
7
|
action: 'publish' | 'unpublish';
|
|
8
8
|
}>;
|
|
9
9
|
}
|
|
10
|
-
export declare function recordEvent(deps: CoreDeps, ctx: Ctx, message: string | null, items: PublishResult['items']): Promise<number | null>;
|
|
10
|
+
export declare function recordEvent(deps: CoreDeps, ctx: Ctx, message: string | null, items: PublishResult['items'], at?: string): Promise<number | null>;
|
|
11
11
|
export declare function publish(deps: CoreDeps, documentIds: string[], ctx: Ctx, opts?: {
|
|
12
12
|
message?: string;
|
|
13
13
|
expect?: Record<string, number>;
|
|
@@ -9,13 +9,13 @@ import { documentTitle, parseData, summaryQuery, toSummary, whereVisible } from
|
|
|
9
9
|
import { documentRefPaths, mediaRefPaths, syncRefs } from './refs.js';
|
|
10
10
|
import { docLabels } from './schema.js';
|
|
11
11
|
import { contentIssue, validateContent } from './validate.js';
|
|
12
|
-
export async function recordEvent(deps, ctx, message, items) {
|
|
12
|
+
export async function recordEvent(deps, ctx, message, items, at = deps.now().toISOString()) {
|
|
13
13
|
if (items.length === 0)
|
|
14
14
|
return null;
|
|
15
15
|
const row = await deps.db
|
|
16
16
|
.insertInto('publish_events')
|
|
17
17
|
.values({
|
|
18
|
-
at
|
|
18
|
+
at,
|
|
19
19
|
user_id: ctx.actor.id,
|
|
20
20
|
user_name: ctx.actor.name,
|
|
21
21
|
source: ctx.source,
|
|
@@ -127,6 +127,7 @@ export async function publish(deps, documentIds, ctx, opts = {}) {
|
|
|
127
127
|
}
|
|
128
128
|
if (opts.dryRun)
|
|
129
129
|
return { eventId: null, items };
|
|
130
|
+
const at = deps.now().toISOString();
|
|
130
131
|
for (const item of items) {
|
|
131
132
|
await autoRedirect(tx, ctx, docs.get(item.documentId));
|
|
132
133
|
await trx
|
|
@@ -135,12 +136,13 @@ export async function publish(deps, documentIds, ctx, opts = {}) {
|
|
|
135
136
|
published_rev: eb.ref('head_rev'),
|
|
136
137
|
published_slug: eb.ref('head_slug'),
|
|
137
138
|
published_path: eb.ref('head_path'),
|
|
139
|
+
first_published_at: eb.fn.coalesce('first_published_at', eb.val(at)),
|
|
138
140
|
}))
|
|
139
141
|
.where('id', '=', item.documentId)
|
|
140
142
|
.execute();
|
|
141
143
|
await syncRefs(tx, item.documentId);
|
|
142
144
|
}
|
|
143
|
-
return { eventId: await recordEvent(tx, ctx, opts.message ?? null, items), items };
|
|
145
|
+
return { eventId: await recordEvent(tx, ctx, opts.message ?? null, items, at), items };
|
|
144
146
|
}, opts);
|
|
145
147
|
}
|
|
146
148
|
export async function unpublish(deps, documentIds, ctx, opts = {}) {
|
|
@@ -20,6 +20,7 @@ export declare function headQuery(deps: CoreDeps): SelectQueryBuilder<Database,
|
|
|
20
20
|
created_at: string;
|
|
21
21
|
deleted_at: string | null;
|
|
22
22
|
edition: number | null;
|
|
23
|
+
first_published_at: string | null;
|
|
23
24
|
group_id: string;
|
|
24
25
|
head_path: string | null;
|
|
25
26
|
head_rev: number | null;
|
|
@@ -41,6 +42,7 @@ export declare function summaryQuery(deps: CoreDeps): SelectQueryBuilder<Databas
|
|
|
41
42
|
created_at: string;
|
|
42
43
|
deleted_at: string | null;
|
|
43
44
|
edition: number | null;
|
|
45
|
+
first_published_at: string | null;
|
|
44
46
|
group_id: string;
|
|
45
47
|
head_path: string | null;
|
|
46
48
|
head_rev: number | null;
|
|
@@ -67,6 +69,7 @@ export declare function summaryBase(deps: CoreDeps): SelectQueryBuilder<Database
|
|
|
67
69
|
created_at: string;
|
|
68
70
|
deleted_at: string | null;
|
|
69
71
|
edition: number | null;
|
|
72
|
+
first_published_at: string | null;
|
|
70
73
|
group_id: string;
|
|
71
74
|
head_path: string | null;
|
|
72
75
|
head_rev: number | null;
|
|
@@ -72,7 +72,8 @@ function readNode(s, value, opts, path, gaps, required, inList) {
|
|
|
72
72
|
}
|
|
73
73
|
return listChecks(s, def).safeParse(out).success ? out : unfit([], required, opts, path, gaps);
|
|
74
74
|
}
|
|
75
|
-
const
|
|
75
|
+
const meta = fieldMeta(s);
|
|
76
|
+
const result = s.safeParse(meta?.readStored ? meta.readStored(value) : value);
|
|
76
77
|
if (result.success)
|
|
77
78
|
return result.data;
|
|
78
79
|
if (OPTIONAL.has(def.type))
|
|
@@ -82,7 +83,7 @@ function readNode(s, value, opts, path, gaps, required, inList) {
|
|
|
82
83
|
if (fallback.success)
|
|
83
84
|
return fallback.data;
|
|
84
85
|
}
|
|
85
|
-
return unfit(
|
|
86
|
+
return unfit(meta?.empty, required, opts, path, gaps);
|
|
86
87
|
}
|
|
87
88
|
const listCache = new WeakMap();
|
|
88
89
|
/** The array's own checks (such as min and max) over items that were already read. */
|
|
@@ -80,7 +80,7 @@ export async function checkReferences(deps, type, data, opts = {}) {
|
|
|
80
80
|
issue(ref, 'wrong_collection', 'issue.wrongCollection', { collection });
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
else if ((ref.meta.kind === 'link' || ref.meta.kind === 'richText') && !isRoutable(deps, target)) {
|
|
83
|
+
else if ((ref.meta.kind === 'link' || ref.meta.kind === 'richText' || ref.meta.kind === 'inlineText') && !isRoutable(deps, target)) {
|
|
84
84
|
issue(ref, 'not_routable', 'issue.notRoutable');
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -2,7 +2,7 @@ import { fieldValues } from '../fields/walk.js';
|
|
|
2
2
|
import { richTextText } from '../richtext/schema.js';
|
|
3
3
|
import { documentSchema } from './schema.js';
|
|
4
4
|
import { parseData, summaryQuery, toSummary } from './read.js';
|
|
5
|
-
const KINDS = new Set(['text', 'textarea', 'richText']);
|
|
5
|
+
const KINDS = new Set(['text', 'textarea', 'richText', 'inlineText']);
|
|
6
6
|
const SNIPPET = 160;
|
|
7
7
|
/** Lower-cased text without accents, with each normalized character's index in the original. */
|
|
8
8
|
function fold(text) {
|
|
@@ -68,7 +68,7 @@ export async function searchEntries(deps, type, query, opts = {}) {
|
|
|
68
68
|
const data = parseData(deps, row.type, row.head_data);
|
|
69
69
|
const parts = [];
|
|
70
70
|
for (const found of fieldValues(schema, data, KINDS)) {
|
|
71
|
-
if (found.meta.kind === 'richText') {
|
|
71
|
+
if (found.meta.kind === 'richText' || found.meta.kind === 'inlineText') {
|
|
72
72
|
if (typeof found.value === 'object' && found.value !== null)
|
|
73
73
|
parts.push(richTextText(found.value));
|
|
74
74
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an image target in shipped Markdown names: a library image (`inlay:`), a file inside the site's folder
|
|
3
|
+
* (`url` is its `file:` URL's href, the key it goes by everywhere), or something shipped content can't use.
|
|
4
|
+
*/
|
|
5
|
+
export type ImageTarget = {
|
|
6
|
+
kind: 'library';
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'file';
|
|
9
|
+
url: string;
|
|
10
|
+
path: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'remote';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'rooted';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'outside';
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'other';
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* What `src`, an image target as written in shipped Markdown, names. A path relative to the site's folder
|
|
22
|
+
* (`siteDir`, a `file:` URL ending in `/`) and a `file:` URL name the same file by the same `url`. Only the names are
|
|
23
|
+
* looked at here: `realInside` checks where the file really is.
|
|
24
|
+
*/
|
|
25
|
+
export declare function imageTarget(src: string, siteDir: string | null): ImageTarget;
|
|
26
|
+
/**
|
|
27
|
+
* `path` with every link followed, if that is inside the site's folder; null when it isn't or either can't be
|
|
28
|
+
* resolved. Read the file by the path returned, so it is the one that was checked.
|
|
29
|
+
*/
|
|
30
|
+
export declare function realInside(path: string, siteDir: string): Promise<string | null>;
|
|
31
|
+
/** `realInside`, without waiting. */
|
|
32
|
+
export declare function realInsideSync(path: string, siteDir: string): string | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { realpathSync } from 'node:fs';
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { isAbsolute, relative, sep } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
const SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
6
|
+
/** True if `path` is below `root`, going by the names alone. */
|
|
7
|
+
function contains(root, path) {
|
|
8
|
+
const rel = relative(root, path);
|
|
9
|
+
return rel !== '' && rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* What `src`, an image target as written in shipped Markdown, names. A path relative to the site's folder
|
|
13
|
+
* (`siteDir`, a `file:` URL ending in `/`) and a `file:` URL name the same file by the same `url`. Only the names are
|
|
14
|
+
* looked at here: `realInside` checks where the file really is.
|
|
15
|
+
*/
|
|
16
|
+
export function imageTarget(src, siteDir) {
|
|
17
|
+
if (src.startsWith('inlay:'))
|
|
18
|
+
return { kind: 'library' };
|
|
19
|
+
if (/^https?:/i.test(src))
|
|
20
|
+
return { kind: 'remote' };
|
|
21
|
+
if (src.startsWith('/'))
|
|
22
|
+
return { kind: 'rooted' };
|
|
23
|
+
const isFileUrl = /^file:/i.test(src);
|
|
24
|
+
if (!isFileUrl && SCHEME.test(src))
|
|
25
|
+
return { kind: 'other' };
|
|
26
|
+
if (siteDir === null)
|
|
27
|
+
return { kind: 'outside' };
|
|
28
|
+
try {
|
|
29
|
+
const url = isFileUrl ? new URL(src) : new URL(src, siteDir);
|
|
30
|
+
const path = fileURLToPath(url);
|
|
31
|
+
if (!contains(fileURLToPath(siteDir), path))
|
|
32
|
+
return { kind: 'outside' };
|
|
33
|
+
return { kind: 'file', url: url.href, path };
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// A file: URL naming another host, or a path no file can have.
|
|
37
|
+
return { kind: 'outside' };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `path` with every link followed, if that is inside the site's folder; null when it isn't or either can't be
|
|
42
|
+
* resolved. Read the file by the path returned, so it is the one that was checked.
|
|
43
|
+
*/
|
|
44
|
+
export async function realInside(path, siteDir) {
|
|
45
|
+
try {
|
|
46
|
+
const [root, real] = await Promise.all([realpath(fileURLToPath(siteDir)), realpath(path)]);
|
|
47
|
+
return contains(root, real) ? real : null;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** `realInside`, without waiting. */
|
|
54
|
+
export function realInsideSync(path, siteDir) {
|
|
55
|
+
try {
|
|
56
|
+
const real = realpathSync(path);
|
|
57
|
+
return contains(realpathSync(fileURLToPath(siteDir)), real) ? real : null;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -15,7 +15,7 @@ export interface PendingFile {
|
|
|
15
15
|
export type KeyResolver = (ref: ShippedDocumentRef) => string | null;
|
|
16
16
|
/**
|
|
17
17
|
* Turns shipped content as a developer writes it into the stored shape:
|
|
18
|
-
* Markdown strings in rich text fields become rich text, and `{ file, alt? }`
|
|
18
|
+
* Markdown strings in rich text and inline text fields become rich text, and `{ file, alt? }`
|
|
19
19
|
* in image and file fields is read from disk, checked like an upload, and
|
|
20
20
|
* replaced by `{ media, alt? }`. References to other shipped documents by key
|
|
21
21
|
* become their group ids: `{ key }` in `ref` fields, `{ document: { type, key? } }`
|
|
@@ -28,12 +28,18 @@ export declare function resolveShippedInput(deps: CoreDeps, type: string, input:
|
|
|
28
28
|
files: Map<string, PendingFile>;
|
|
29
29
|
issues: ContentIssue[];
|
|
30
30
|
}>;
|
|
31
|
+
/** `input`, shipped content of `type`, with each rich-text Markdown string in its fields and slots replaced by `map`'s. */
|
|
32
|
+
export declare function mapRichText(registry: Registry, type: string, input: ContentInput, map: (markdown: string) => unknown): ContentInput;
|
|
31
33
|
/**
|
|
32
34
|
* Every `{ file }` named in the registry's shipped content (template fields and slots), once per source: the
|
|
33
|
-
* source as written (a file: URL's href or an absolute path)
|
|
34
|
-
* a
|
|
35
|
+
* source as written (a file: URL's href or an absolute path), the local path it names, and the path to `read` it
|
|
36
|
+
* by. Images named by a file in rich-text Markdown are listed too, by their `file:` URL's href, so one file named
|
|
37
|
+
* several ways is listed once; such an image is read by its real path, the one checked to be inside the site's
|
|
38
|
+
* folder. Values that don't name a local file, and images outside the site's folder or missing, are left out;
|
|
39
|
+
* applying the content reports them.
|
|
35
40
|
*/
|
|
36
41
|
export declare function shippedFiles(registry: Registry): Array<{
|
|
37
42
|
source: string;
|
|
38
43
|
path: string;
|
|
44
|
+
read: string;
|
|
39
45
|
}>;
|