create-ailk 0.32.0 → 0.34.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 +21 -3
- package/component-catalog.json +12 -1
- package/component-catalog.md +6 -5
- package/dist/export-content.d.ts +6 -3
- package/dist/export-content.js +82 -11
- package/dist/lib/env-catalog.js +4 -0
- package/dist/lib/import-mdx.d.ts +111 -0
- package/dist/lib/import-mdx.js +648 -46
- package/dist/migrate-content.d.ts +3 -1
- package/dist/migrate-content.js +52 -1
- package/dist/seed-flows.d.ts +1 -1
- package/dist/seed-flows.js +9 -4
- package/dist/surfaces.js +1 -0
- package/package.json +3 -3
- package/templates/apps/api/.env.example +11 -0
- package/templates/apps/api/CLAUDE.md +7 -5
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +13 -0
- package/templates/apps/mcp/CLAUDE.md +4 -2
- package/templates/apps/web/CLAUDE.md +4 -1
- package/templates/apps/web/app/[locale]/(auth)/__tests__/password-reset.test.tsx +28 -0
- package/templates/apps/web/app/[locale]/(auth)/verify-email/__tests__/actions.test.ts +94 -0
- package/templates/apps/web/app/[locale]/(auth)/verify-email/actions.ts +77 -0
- package/templates/apps/web/app/[locale]/(auth)/verify-email/page.tsx +79 -14
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +7 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +7 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +7 -0
- package/templates/apps/web/app/[locale]/contact/__tests__/contact.actions.test.ts +21 -0
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +15 -9
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +38 -105
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +72 -58
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +249 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +164 -20
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +269 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +179 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +108 -40
- package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +153 -0
- package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +151 -0
- package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +1 -1
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/page.test.tsx +3 -20
- package/templates/apps/web/app/[locale]/thanks/[slug]/page.tsx +2 -9
- package/templates/apps/web/auth.ts +22 -6
- package/templates/apps/web/lib/__tests__/account-config.test.ts +69 -0
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +99 -1
- package/templates/apps/web/lib/__tests__/telemetry-scrub.test.ts +20 -0
- package/templates/apps/web/lib/account-config.ts +52 -14
- package/templates/apps/web/lib/auth-email.ts +87 -5
- package/templates/apps/web/lib/mcp-oauth.ts +49 -6
- package/templates/apps/web/lib/telemetry-scrub.ts +6 -0
- package/templates/apps/web/messages/en.json +26 -1
- package/templates/database/seed.ts +7 -7
- package/versions.json +48 -48
- package/templates/apps/web/app/[locale]/thanks/[slug]/AccountInviteLink.tsx +0 -89
- package/templates/apps/web/app/[locale]/thanks/[slug]/__tests__/AccountInviteLink.test.tsx +0 -104
package/dist/lib/import-mdx.js
CHANGED
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
* reports `unchanged`; a changed layout on a live draft is refused
|
|
20
20
|
* `draft_is_live` and the page fails with that reason.
|
|
21
21
|
*
|
|
22
|
+
* A section string that holds inline HTML is converted first (#10804) — a
|
|
23
|
+
* link to `[label](href)`, a line break to a newline, a block to a blank
|
|
24
|
+
* line, every other tag unwrapped to its text — so the words and the layout
|
|
25
|
+
* carry no tag, which the hub's structure write refuses. The layout is then
|
|
26
|
+
* checked against the hub's section-string rules before any write, so a page
|
|
27
|
+
* the hub would refuse fails with the rule and the path, and a page whose
|
|
28
|
+
* draft holds no layout yet is never reported `unchanged`.
|
|
29
|
+
*
|
|
22
30
|
* create-ailk ships one runtime dependency, so the adapter is never imported:
|
|
23
31
|
* the caller injects it, and `loadSiteMdxAdapter` resolves the SITE's
|
|
24
32
|
* installed copy from its `apps/web` at run time (the #6937 precedent), and
|
|
@@ -29,7 +37,15 @@
|
|
|
29
37
|
* `<slug>/index.mdx` becomes a `BlogPosting` / `DocsDetail` page (the
|
|
30
38
|
* directory's own `index.mdx` its `BlogList` / `DocsList` index), its
|
|
31
39
|
* fumadocs frontmatter mapped to the stored vocabulary and written through the
|
|
32
|
-
* same converting path. Every outcome names the root it came from.
|
|
40
|
+
* same converting path. Every outcome names the root it came from. A key the
|
|
41
|
+
* vocabulary does not name rides in `siteFields`, and a blog post's tags are
|
|
42
|
+
* sent (#10806); a key the store cannot keep is named with its reason.
|
|
43
|
+
*
|
|
44
|
+
* Given `liveSource` (#10898 D5), each page carries the hub's live-source
|
|
45
|
+
* mark — the SHA-256 of the body it sends — so the hub lists the template's
|
|
46
|
+
* missing headings as advisory, not blocking; a file never supplies one. With
|
|
47
|
+
* the site's contract members (`publishCheck`), each written page's outcome
|
|
48
|
+
* carries the verdict the hub's publish gate will give it (D6).
|
|
33
49
|
*
|
|
34
50
|
* Given `publish` (#10659 D2), each page with no Live version is set Live
|
|
35
51
|
* after it is written (`POST …/publish`, the draft tip); a page already Live
|
|
@@ -41,8 +57,10 @@
|
|
|
41
57
|
* a status and a `[a-z0-9_]` error code reach output (SEC-7876-S1).
|
|
42
58
|
*
|
|
43
59
|
* Spec: docs/specs/10203-import-mdx-one-mdx-artifact-spec.md; the editorial
|
|
44
|
-
* walk docs/specs/10701-import-mdx-walks-the-editorial-spec.md
|
|
60
|
+
* walk docs/specs/10701-import-mdx-walks-the-editorial-spec.md; its site
|
|
61
|
+
* fields docs/specs/10806-the-editorial-import-drops-blog-spec.md.
|
|
45
62
|
*/
|
|
63
|
+
import { createHash } from "node:crypto";
|
|
46
64
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
47
65
|
import { createRequire } from "node:module";
|
|
48
66
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -57,6 +75,12 @@ const CONTENT_ADAPTERS_PACKAGE = "@working-theory/content-adapters";
|
|
|
57
75
|
const VALIDATION_PACKAGE = "@working-theory/validation";
|
|
58
76
|
/** The adapter package's frontmatter parser, resolved from its entry. */
|
|
59
77
|
const FRONTMATTER_PACKAGE = "gray-matter";
|
|
78
|
+
/** The page-type registry: a dependency of the adapter package (#10898 D6). */
|
|
79
|
+
const PAGE_TYPES_PACKAGE = "@working-theory/schema/page-types";
|
|
80
|
+
/** The hub's live-source content key (`LIVE_SOURCE_KEY`, api-content-write `content.ts`), restated: no runtime dep. */
|
|
81
|
+
const LIVE_SOURCE_KEY = "liveSource";
|
|
82
|
+
/** `EDITORIAL_FIELDS` (api-content-write `derive-publish.ts`): the editorial structure publish's repair builds. */
|
|
83
|
+
const EDITORIAL_STRUCTURE_FIELDS = ["author", "tags", "order", "parent"];
|
|
60
84
|
/** The adapter's locale shape (`BCP47_RE` in its `mdx/adapter.ts`). */
|
|
61
85
|
const LOCALE = /^[a-z]{2}(-[A-Z]{2})?$/;
|
|
62
86
|
/** `SLUG_PATTERN` in the adapter's `errors.ts`, restated: no runtime dep. */
|
|
@@ -71,10 +95,15 @@ const EDITORIAL_TYPES = {
|
|
|
71
95
|
/** The slug the runtime reads as a surface's own index. */
|
|
72
96
|
const INDEX_SLUG = "index";
|
|
73
97
|
const INDEX_TYPES = new Set(Object.values(EDITORIAL_TYPES).map((k) => k.index));
|
|
98
|
+
/** Each index type's own slug, its editorial directory: `BlogList/blog` shares `/blog` with `BlogList/index` (#10805 D5). */
|
|
99
|
+
const INDEX_OWN_SLUG = new Map(Object.entries(EDITORIAL_TYPES).map(([dir, k]) => [k.index, dir]));
|
|
100
|
+
/** `PAGE_TAG_TYPES` (the validation package's `site-fields.ts`), restated: the blog collection keeps a sent `tags`. */
|
|
101
|
+
const PAGE_TAG_TYPES = new Set(["BlogPosting", "BlogList"]);
|
|
74
102
|
/**
|
|
75
103
|
* `fumadocsToArtifactFrontmatter` (`apps/web/lib/runtime-source.ts`) restated —
|
|
76
|
-
* fumadocs key to stored key — less `tags`, which
|
|
77
|
-
* `sections`, which `convert` moves. Any other key
|
|
104
|
+
* fumadocs key to stored key — less `tags`, which only a blog page sends, plus
|
|
105
|
+
* `sections`, which `convert` moves. Any other key rides in `siteFields`
|
|
106
|
+
* (#10806 D4).
|
|
78
107
|
*/
|
|
79
108
|
const EDITORIAL_FIELDS = {
|
|
80
109
|
title: "title",
|
|
@@ -88,7 +117,15 @@ const EDITORIAL_FIELDS = {
|
|
|
88
117
|
sections: "sections",
|
|
89
118
|
};
|
|
90
119
|
/** Keys not sent and not reported: the path decides both, and a strip marker. */
|
|
91
|
-
const EDITORIAL_IGNORED = new Set(["type", "slug", "oss"]);
|
|
120
|
+
const EDITORIAL_IGNORED = new Set(["type", "slug", "oss", LIVE_SOURCE_KEY]);
|
|
121
|
+
/** Why a key is not sent (#10806 D4); `siteFieldRefusal`'s own reasons are the rest. */
|
|
122
|
+
const NOT_SENT = {
|
|
123
|
+
parent: "the path decides a blog post's parent",
|
|
124
|
+
agentTag: "a tag agents act on, or a site tag, is kept by AI",
|
|
125
|
+
notList: "not a list of tags",
|
|
126
|
+
full: "siteFields is full (32 keys or 64 KiB)",
|
|
127
|
+
olderSite: `the site's ${VALIDATION_PACKAGE} predates site fields; update its dependencies and re-run`,
|
|
128
|
+
};
|
|
92
129
|
/** `wksp_<uuidv7>` — the `@working-theory/ids` shape, restated: no runtime dep. */
|
|
93
130
|
const WORKSPACE_ID = /^wksp_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
94
131
|
/** A key is visible ASCII only: what an HTTP header can carry, with no space. */
|
|
@@ -338,35 +375,118 @@ function dateString(value) {
|
|
|
338
375
|
const iso = value.toISOString();
|
|
339
376
|
return iso.endsWith("T00:00:00.000Z") ? iso.slice(0, 10) : iso;
|
|
340
377
|
}
|
|
378
|
+
/** Below this depth a value is left as read: the site's rule refuses it as too deep. */
|
|
379
|
+
const DATES_MAX_DEPTH = 8;
|
|
380
|
+
/** `value` with every `Date` to a bounded depth as `dateString` gives it (#10806 D4). */
|
|
381
|
+
function datesAsStrings(value, depth = 1) {
|
|
382
|
+
if (value instanceof Date)
|
|
383
|
+
return dateString(value);
|
|
384
|
+
if (depth > DATES_MAX_DEPTH)
|
|
385
|
+
return value;
|
|
386
|
+
if (Array.isArray(value))
|
|
387
|
+
return value.map((item) => datesAsStrings(item, depth + 1));
|
|
388
|
+
if (value === null || typeof value !== "object")
|
|
389
|
+
return value;
|
|
390
|
+
if (Object.getPrototypeOf(value) !== Object.prototype)
|
|
391
|
+
return value;
|
|
392
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, datesAsStrings(item, depth + 1)]));
|
|
393
|
+
}
|
|
394
|
+
/** A tag as printed: control characters as `?`, at most 64 characters. */
|
|
395
|
+
function printedTag(tag) {
|
|
396
|
+
// eslint-disable-next-line no-control-regex -- the controls are what is replaced
|
|
397
|
+
return String(tag).replace(/[\u0000-\u001f\u007f-\u009f]/g, "?").slice(0, 64);
|
|
398
|
+
}
|
|
341
399
|
/**
|
|
342
400
|
* An editorial file as the adapter would return a page (#10701 D4): its
|
|
343
401
|
* fumadocs frontmatter mapped to the stored vocabulary, the path deciding the
|
|
344
|
-
* type and slug — and, for a blog page, its `parent` (#10775 D3)
|
|
345
|
-
*
|
|
402
|
+
* type and slug — and, for a blog page, its `parent` (#10775 D3). Every other
|
|
403
|
+
* key the site's rule accepts rides in `siteFields`, and a blog page sends its
|
|
404
|
+
* `tags` (#10806 D4); the keys not sent are named with their reasons.
|
|
346
405
|
*/
|
|
347
|
-
function editorialSource(page, parsed) {
|
|
406
|
+
function editorialSource(page, parsed, rules) {
|
|
348
407
|
const frontmatter = {
|
|
349
408
|
type: page.type,
|
|
350
409
|
slug: page.slug,
|
|
351
410
|
};
|
|
352
|
-
const
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
411
|
+
const notSent = [];
|
|
412
|
+
const siteFields = {};
|
|
413
|
+
const blog = PAGE_TAG_TYPES.has(page.type);
|
|
414
|
+
for (const [key, raw] of Object.entries(parsed.data)) {
|
|
415
|
+
if (EDITORIAL_IGNORED.has(key))
|
|
416
|
+
continue;
|
|
417
|
+
if (blog && key === "parent") {
|
|
418
|
+
notSent.push({ key, reason: NOT_SENT.parent });
|
|
419
|
+
}
|
|
420
|
+
else if (Object.hasOwn(EDITORIAL_FIELDS, key)) {
|
|
421
|
+
frontmatter[EDITORIAL_FIELDS[key]] = dateString(raw);
|
|
422
|
+
}
|
|
423
|
+
else if (rules === undefined) {
|
|
424
|
+
notSent.push({ key, reason: NOT_SENT.olderSite });
|
|
425
|
+
}
|
|
426
|
+
else if (blog && key === "tags") {
|
|
427
|
+
if (!Array.isArray(raw)) {
|
|
428
|
+
notSent.push({ key, reason: NOT_SENT.notList });
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
// Sent as written, so the stored list is what the store computes; a
|
|
432
|
+
// tag it keeps for itself is named.
|
|
433
|
+
frontmatter["tags"] = raw;
|
|
434
|
+
const kept = new Set(rules.publicPageTags(raw));
|
|
435
|
+
for (const tag of new Set(raw.filter((tag) => !kept.has(tag)))) {
|
|
436
|
+
notSent.push({ key: `tags: ${printedTag(tag)}`, reason: NOT_SENT.agentTag });
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
const value = datesAsStrings(raw);
|
|
441
|
+
const refused = rules.refusal(key, value);
|
|
442
|
+
const fits = Object.keys(siteFields).length < rules.maxKeys &&
|
|
443
|
+
new TextEncoder().encode(JSON.stringify({ ...siteFields, [key]: value })).length <=
|
|
444
|
+
rules.maxBytes;
|
|
445
|
+
if (refused !== null)
|
|
446
|
+
notSent.push({ key, reason: refused });
|
|
447
|
+
else if (!fits)
|
|
448
|
+
notSent.push({ key, reason: NOT_SENT.full });
|
|
449
|
+
else
|
|
450
|
+
siteFields[key] = value;
|
|
451
|
+
}
|
|
362
452
|
}
|
|
363
453
|
if (page.parent !== undefined)
|
|
364
454
|
frontmatter["parent"] = page.parent;
|
|
455
|
+
if (Object.keys(siteFields).length > 0)
|
|
456
|
+
frontmatter["siteFields"] = siteFields;
|
|
365
457
|
return {
|
|
366
458
|
source: { frontmatter, body: parsed.content },
|
|
367
|
-
|
|
459
|
+
notSent: notSent.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0)),
|
|
368
460
|
};
|
|
369
461
|
}
|
|
462
|
+
/** `a (reason); b, c (reason)` — keys in order, one segment per reason. */
|
|
463
|
+
function notSentList(notSent) {
|
|
464
|
+
const byReason = new Map();
|
|
465
|
+
for (const { key, reason } of notSent) {
|
|
466
|
+
byReason.set(reason, [...(byReason.get(reason) ?? []), key]);
|
|
467
|
+
}
|
|
468
|
+
return [...byReason]
|
|
469
|
+
.map(([reason, keys]) => `${keys.join(", ")} (${reason})`)
|
|
470
|
+
.join("; ");
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* The sent site fields and public tags a write's stored content lacks
|
|
474
|
+
* (#10806 D4): what a hub that predates site fields dropped.
|
|
475
|
+
*/
|
|
476
|
+
function notKept(sent, kept, rules) {
|
|
477
|
+
const keptFields = kept["siteFields"] !== null && typeof kept["siteFields"] === "object"
|
|
478
|
+
? kept["siteFields"]
|
|
479
|
+
: {};
|
|
480
|
+
const keptTags = Array.isArray(kept["tags"]) ? kept["tags"] : [];
|
|
481
|
+
const sentFields = Object.keys((sent["siteFields"] ?? {}));
|
|
482
|
+
const sentTags = PAGE_TAG_TYPES.has(String(sent["type"])) && Array.isArray(sent["tags"])
|
|
483
|
+
? rules.publicPageTags(sent["tags"])
|
|
484
|
+
: [];
|
|
485
|
+
return [
|
|
486
|
+
...sentFields.filter((key) => !Object.hasOwn(keptFields, key)).sort(),
|
|
487
|
+
...sentTags.filter((tag) => !keptTags.includes(tag)).map((tag) => `tags: ${printedTag(tag)}`),
|
|
488
|
+
];
|
|
489
|
+
}
|
|
370
490
|
// ── "Unchanged" (D4) ────────────────────────────────────────────────────────
|
|
371
491
|
function sortKeys(value) {
|
|
372
492
|
if (Array.isArray(value))
|
|
@@ -382,14 +502,21 @@ function canonical(value) {
|
|
|
382
502
|
return JSON.stringify(sortKeys(JSON.parse(JSON.stringify(value ?? null))));
|
|
383
503
|
}
|
|
384
504
|
/**
|
|
385
|
-
* Content
|
|
386
|
-
*
|
|
505
|
+
* Content as compared: the store's tagger writes `tags` on every version
|
|
506
|
+
* (#10342 D5), so they are dropped — except a blog page that sends them, whose
|
|
507
|
+
* public tags are the importer's (#10806 D4): compared as `publicTags` gives
|
|
508
|
+
* them, so a changed category is an update.
|
|
387
509
|
*/
|
|
388
|
-
function
|
|
510
|
+
function compared(value, sent, publicTags) {
|
|
389
511
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
390
512
|
return value;
|
|
391
|
-
const { tags
|
|
392
|
-
|
|
513
|
+
const { tags, ...rest } = value;
|
|
514
|
+
if (publicTags === undefined ||
|
|
515
|
+
!PAGE_TAG_TYPES.has(String(sent["type"])) ||
|
|
516
|
+
!Array.isArray(sent["tags"])) {
|
|
517
|
+
return rest;
|
|
518
|
+
}
|
|
519
|
+
return { ...rest, tags: publicTags(Array.isArray(tags) ? tags : []) };
|
|
393
520
|
}
|
|
394
521
|
function safeCode(value) {
|
|
395
522
|
return typeof value === "string" && SAFE_CODE.test(value) ? value : "unknown";
|
|
@@ -474,16 +601,27 @@ function wrongLocale(at, answer, locale) {
|
|
|
474
601
|
}
|
|
475
602
|
return failed(at, `the API does not serve locale ${locale}`, `not sent: the API does not serve locale ${locale}`);
|
|
476
603
|
}
|
|
477
|
-
|
|
604
|
+
/** `value` without the live-source mark. */
|
|
605
|
+
function withoutLiveSource(value) {
|
|
606
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
607
|
+
return value;
|
|
608
|
+
const { [LIVE_SOURCE_KEY]: _mark, ...rest } = value;
|
|
609
|
+
return rest;
|
|
610
|
+
}
|
|
611
|
+
async function writePage(t, page, locale, content, layout, publicTags) {
|
|
478
612
|
const { root, path, type, slug } = page;
|
|
479
613
|
const pagePath = `${t.base}/content/${encodeURIComponent(type)}/${encodeURIComponent(slug)}`;
|
|
480
614
|
const query = `?locale=${encodeURIComponent(locale)}`;
|
|
481
615
|
const address = `${pagePath}${query}`;
|
|
482
616
|
// The route's `statusOf`: anything but `draft` has a Live version.
|
|
483
617
|
let live = false;
|
|
618
|
+
let stored;
|
|
619
|
+
let sent = false;
|
|
484
620
|
const outcome = (result) => ({
|
|
485
621
|
outcome: { root, path, result, type, slug },
|
|
486
622
|
live,
|
|
623
|
+
stored,
|
|
624
|
+
sent,
|
|
487
625
|
});
|
|
488
626
|
// The words are written; now the layout, under the token the draft holds
|
|
489
627
|
// (`null` for a page that has none yet).
|
|
@@ -497,7 +635,11 @@ async function writePage(t, page, locale, content, layout) {
|
|
|
497
635
|
if ("network" in put || put.status !== 200)
|
|
498
636
|
return refusedAnswer(page, put);
|
|
499
637
|
return (wrongLocale(page, put, locale) ??
|
|
500
|
-
outcome(
|
|
638
|
+
outcome(
|
|
639
|
+
// #10804 D6 — with no token the hub writes the layout (or refuses a
|
|
640
|
+
// live tip), so a dry run's `written: false` never makes it unchanged.
|
|
641
|
+
result === "unchanged" &&
|
|
642
|
+
(structureToken === null || put.data["written"] === true)
|
|
501
643
|
? "updated"
|
|
502
644
|
: result));
|
|
503
645
|
};
|
|
@@ -515,8 +657,11 @@ async function writePage(t, page, locale, content, layout) {
|
|
|
515
657
|
live = read.data["status"] !== "draft";
|
|
516
658
|
const token = read.data["structureToken"];
|
|
517
659
|
const structureToken = typeof token === "string" ? token : null;
|
|
518
|
-
|
|
519
|
-
|
|
660
|
+
stored = read.data["content"];
|
|
661
|
+
// #10898 D5 — a live tip is never re-drafted for the mark alone.
|
|
662
|
+
const liveTip = read.data["status"] === "published";
|
|
663
|
+
if (canonical(compared(liveTip ? withoutLiveSource(stored) : stored, content, publicTags)) ===
|
|
664
|
+
canonical(compared(liveTip ? withoutLiveSource(content) : content, content, publicTags))) {
|
|
520
665
|
return done("unchanged", structureToken);
|
|
521
666
|
}
|
|
522
667
|
// The token is the version just compared against, so a draft saved
|
|
@@ -524,6 +669,8 @@ async function writePage(t, page, locale, content, layout) {
|
|
|
524
669
|
const saved = await call(t, "PATCH", address, content, version);
|
|
525
670
|
if ("network" in saved || saved.status !== 200)
|
|
526
671
|
return refusedAnswer(page, saved);
|
|
672
|
+
stored = saved.data["content"];
|
|
673
|
+
sent = true;
|
|
527
674
|
// A save carries the structure token forward (#10330 D5).
|
|
528
675
|
return (wrongLocale(page, saved, locale) ?? done("updated", structureToken));
|
|
529
676
|
}
|
|
@@ -536,9 +683,11 @@ async function writePage(t, page, locale, content, layout) {
|
|
|
536
683
|
if ("network" in created)
|
|
537
684
|
return refusedAnswer(page, created);
|
|
538
685
|
if (created.status === 201) {
|
|
686
|
+
stored = created.data["content"];
|
|
687
|
+
sent = true;
|
|
539
688
|
return wrongLocale(page, created, locale) ?? done("created");
|
|
540
689
|
}
|
|
541
|
-
// 409 slug_taken: another
|
|
690
|
+
// 409 slug_taken: another page holds this page's registry link (#10268
|
|
542
691
|
// D5) — reported as it is, since a re-read at this address finds nothing.
|
|
543
692
|
// Any other 409: created by someone else since the read — read it once more.
|
|
544
693
|
if (created.status !== 409 || created.code === "slug_taken") {
|
|
@@ -564,6 +713,323 @@ export function formatImportMdxReport(result) {
|
|
|
564
713
|
`created ${created} · updated ${updated} · unchanged ${unchanged} · skipped ${skipped} · failed ${failures}`,
|
|
565
714
|
].join("\n")}\n`;
|
|
566
715
|
}
|
|
716
|
+
// ── Inline HTML in section strings (#10804) ─────────────────────────────────
|
|
717
|
+
/** `HTML_TAG` (`content-draft.ts`, from `derive-publish.ts`, SEC-10589-01), restated: no runtime dep. */
|
|
718
|
+
const HTML_TAG = /<[A-Za-z!/?]/;
|
|
719
|
+
/** `checkSectionData`'s string and key rules (`content-draft.ts`), restated: no runtime dep. */
|
|
720
|
+
const SECTION_STRING_MAX = 2_000;
|
|
721
|
+
const SECTION_KEY_MAX = 100;
|
|
722
|
+
const SCRIPT_SCHEME = /^(?:javascript|vbscript|data):/;
|
|
723
|
+
/** `FAQ_ALLOWED_HREF` (`faq-questions.ts`), the hrefs `parseFaqAnswer` draws as links, restated. */
|
|
724
|
+
const LINK_HREF = /^(?:\/|#|https?:|mailto:|tel:)/i;
|
|
725
|
+
/** Elements removed with their content (D3). */
|
|
726
|
+
const DROPPED_ELEMENTS = new Set([
|
|
727
|
+
"script",
|
|
728
|
+
"style",
|
|
729
|
+
"template",
|
|
730
|
+
"iframe",
|
|
731
|
+
"noscript",
|
|
732
|
+
"svg",
|
|
733
|
+
"object",
|
|
734
|
+
"video",
|
|
735
|
+
"audio",
|
|
736
|
+
"canvas",
|
|
737
|
+
]);
|
|
738
|
+
/** Elements whose open or close tag is a paragraph break (D3). */
|
|
739
|
+
const BLOCK_ELEMENTS = new Set([
|
|
740
|
+
"p",
|
|
741
|
+
"div",
|
|
742
|
+
"section",
|
|
743
|
+
"article",
|
|
744
|
+
"header",
|
|
745
|
+
"footer",
|
|
746
|
+
"blockquote",
|
|
747
|
+
"figure",
|
|
748
|
+
"figcaption",
|
|
749
|
+
"pre",
|
|
750
|
+
"table",
|
|
751
|
+
"tr",
|
|
752
|
+
"dl",
|
|
753
|
+
"dt",
|
|
754
|
+
"dd",
|
|
755
|
+
"h1",
|
|
756
|
+
"h2",
|
|
757
|
+
"h3",
|
|
758
|
+
"h4",
|
|
759
|
+
"h5",
|
|
760
|
+
"h6",
|
|
761
|
+
"ul",
|
|
762
|
+
"ol",
|
|
763
|
+
"hr",
|
|
764
|
+
]);
|
|
765
|
+
/** What the layout keeps of a tag (D3): `a` only when it becomes a link. */
|
|
766
|
+
const CARRIED_ELEMENTS = new Set(["a", "br", "p", "ul", "li"]);
|
|
767
|
+
const NAMED_ENTITIES = {
|
|
768
|
+
amp: "&",
|
|
769
|
+
lt: "<",
|
|
770
|
+
gt: ">",
|
|
771
|
+
quot: '"',
|
|
772
|
+
apos: "'",
|
|
773
|
+
nbsp: "\u00a0",
|
|
774
|
+
};
|
|
775
|
+
const ENTITY = /&(?:#(\d+)|#[xX]([0-9A-Fa-f]+)|(amp|lt|gt|quot|apos|nbsp));/g;
|
|
776
|
+
const TAG_NAME = /\/?([A-Za-z][A-Za-z0-9-]*)/y;
|
|
777
|
+
const TAG_END = /[ \t\r\n\f]*(\/?)>/y;
|
|
778
|
+
/**
|
|
779
|
+
* One attribute, or one stray character a browser would skip. A `<` ends the
|
|
780
|
+
* scan whether it is unquoted or inside a quoted value, so a `<` that begins
|
|
781
|
+
* no tag costs only the gap to the next one and the tokenizer stays linear in
|
|
782
|
+
* the string (spec §9). D3 needs a quoted value to hold `>`, never `<`.
|
|
783
|
+
*/
|
|
784
|
+
const TAG_ATTR = /[ \t\r\n\f]*(?:([^ \t\r\n\f"'<>/=]+)(?:[ \t\r\n\f]*=[ \t\r\n\f]*(?:"([^"<]*)"|'([^'<]*)'|([^ \t\r\n\f<>]+)))?|[^ \t\r\n\f<>])/y;
|
|
785
|
+
const NEWLINE = 1;
|
|
786
|
+
const PARAGRAPH = 2;
|
|
787
|
+
function decodeEntities(text) {
|
|
788
|
+
return text.replace(ENTITY, (source, dec, hex, name) => {
|
|
789
|
+
if (name !== undefined)
|
|
790
|
+
return NAMED_ENTITIES[name];
|
|
791
|
+
const point = dec !== undefined ? Number(dec) : parseInt(hex, 16);
|
|
792
|
+
return point > 0 &&
|
|
793
|
+
point <= 0x10ffff &&
|
|
794
|
+
(point < 0xd800 || point > 0xdfff)
|
|
795
|
+
? String.fromCodePoint(point)
|
|
796
|
+
: source;
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
/** The tag at `at` (`<`, `/`?, a name, attributes, `/`?, `>`), or `undefined` when `<` begins none. */
|
|
800
|
+
function readTag(value, at) {
|
|
801
|
+
TAG_NAME.lastIndex = at + 1;
|
|
802
|
+
const name = TAG_NAME.exec(value)?.[1];
|
|
803
|
+
if (name === undefined)
|
|
804
|
+
return undefined;
|
|
805
|
+
let href;
|
|
806
|
+
for (let i = TAG_NAME.lastIndex;; i = TAG_ATTR.lastIndex) {
|
|
807
|
+
TAG_END.lastIndex = i;
|
|
808
|
+
const end = TAG_END.exec(value);
|
|
809
|
+
if (end !== null) {
|
|
810
|
+
return {
|
|
811
|
+
end: TAG_END.lastIndex,
|
|
812
|
+
close: value[at + 1] === "/",
|
|
813
|
+
selfClosing: end[1] === "/",
|
|
814
|
+
name: name.toLowerCase(),
|
|
815
|
+
...(href !== undefined && { href }),
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
TAG_ATTR.lastIndex = i;
|
|
819
|
+
const attr = TAG_ATTR.exec(value);
|
|
820
|
+
if (attr === null)
|
|
821
|
+
return undefined;
|
|
822
|
+
if (href === undefined && attr[1]?.toLowerCase() === "href") {
|
|
823
|
+
href = attr[2] ?? attr[3] ?? attr[4] ?? "";
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* A section string's inline HTML as the constrained Markdown the upstream
|
|
829
|
+
* renderers read (#10804 D3): a link with an allowed href becomes
|
|
830
|
+
* `[label](href)`, `<br>` a newline, a block or list item a paragraph break,
|
|
831
|
+
* and every other tag goes, its text kept. A string with no tag comes back
|
|
832
|
+
* byte-identical; the result never holds one. `notCarried` names, sorted,
|
|
833
|
+
* every tag the layout does not keep.
|
|
834
|
+
*/
|
|
835
|
+
export function inlineHtmlToMarkdown(value) {
|
|
836
|
+
if (!HTML_TAG.test(value))
|
|
837
|
+
return { text: value, notCarried: [] };
|
|
838
|
+
const pieces = [];
|
|
839
|
+
const notCarried = new Set();
|
|
840
|
+
const text = (raw) => {
|
|
841
|
+
const decoded = decodeEntities(raw.replace(/[ \t\r\n\f]+/g, " "));
|
|
842
|
+
decoded.split("\n").forEach((part, i) => {
|
|
843
|
+
if (i > 0)
|
|
844
|
+
pieces.push(NEWLINE);
|
|
845
|
+
if (part !== "")
|
|
846
|
+
pieces.push(part);
|
|
847
|
+
});
|
|
848
|
+
};
|
|
849
|
+
let link;
|
|
850
|
+
const closeLink = () => {
|
|
851
|
+
if (link === undefined)
|
|
852
|
+
return;
|
|
853
|
+
const label = pieces.slice(link.at);
|
|
854
|
+
const words = label.every((p) => typeof p === "string")
|
|
855
|
+
? label.join("")
|
|
856
|
+
: "";
|
|
857
|
+
if (words !== "" &&
|
|
858
|
+
!words.includes("]") &&
|
|
859
|
+
LINK_HREF.test(link.href) &&
|
|
860
|
+
!/[\s)]/.test(link.href)) {
|
|
861
|
+
pieces.splice(link.at, label.length, `[${words}](${link.href})`);
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
notCarried.add("a");
|
|
865
|
+
}
|
|
866
|
+
link = undefined;
|
|
867
|
+
};
|
|
868
|
+
let from = 0;
|
|
869
|
+
for (let lt = value.indexOf("<"); lt !== -1; lt = value.indexOf("<", Math.max(lt + 1, from))) {
|
|
870
|
+
if (value.startsWith("<!--", lt)) {
|
|
871
|
+
text(value.slice(from, lt));
|
|
872
|
+
const end = value.indexOf("-->", lt + 4);
|
|
873
|
+
from = end === -1 ? value.length : end + 3;
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
const tag = readTag(value, lt);
|
|
877
|
+
if (tag === undefined)
|
|
878
|
+
continue;
|
|
879
|
+
text(value.slice(from, lt));
|
|
880
|
+
from = tag.end;
|
|
881
|
+
const { name } = tag;
|
|
882
|
+
if (!CARRIED_ELEMENTS.has(name))
|
|
883
|
+
notCarried.add(name);
|
|
884
|
+
if (DROPPED_ELEMENTS.has(name)) {
|
|
885
|
+
if (!tag.close && !tag.selfClosing) {
|
|
886
|
+
const close = new RegExp(`</${name}[ \\t\\r\\n\\f]*>`, "gi");
|
|
887
|
+
close.lastIndex = from;
|
|
888
|
+
from = close.exec(value) === null ? value.length : close.lastIndex;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
else if (name === "a") {
|
|
892
|
+
closeLink();
|
|
893
|
+
if (!tag.close) {
|
|
894
|
+
link = { at: pieces.length, href: decodeEntities(tag.href ?? "") };
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
else if (name === "br") {
|
|
898
|
+
pieces.push(NEWLINE);
|
|
899
|
+
}
|
|
900
|
+
else if (name === "li") {
|
|
901
|
+
// An item with no text leaves no bullet.
|
|
902
|
+
if (tag.close && pieces.at(-1) === "- ")
|
|
903
|
+
pieces.pop();
|
|
904
|
+
pieces.push(PARAGRAPH);
|
|
905
|
+
if (!tag.close)
|
|
906
|
+
pieces.push("- ");
|
|
907
|
+
}
|
|
908
|
+
else if (BLOCK_ELEMENTS.has(name)) {
|
|
909
|
+
pieces.push(PARAGRAPH);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
text(value.slice(from));
|
|
913
|
+
closeLink();
|
|
914
|
+
// Spaces never touch a newline; a run holding a paragraph break, or two or
|
|
915
|
+
// more newlines, is one blank line; the ends are trimmed.
|
|
916
|
+
const parts = [];
|
|
917
|
+
let run;
|
|
918
|
+
for (const piece of pieces) {
|
|
919
|
+
if (typeof piece !== "string") {
|
|
920
|
+
if (run === undefined) {
|
|
921
|
+
while (parts.length > 0) {
|
|
922
|
+
const last = parts[parts.length - 1].replace(/ +$/, "");
|
|
923
|
+
if (last !== "") {
|
|
924
|
+
parts[parts.length - 1] = last;
|
|
925
|
+
break;
|
|
926
|
+
}
|
|
927
|
+
parts.pop();
|
|
928
|
+
}
|
|
929
|
+
run = { newlines: 0, paragraph: false };
|
|
930
|
+
}
|
|
931
|
+
if (piece === PARAGRAPH)
|
|
932
|
+
run.paragraph = true;
|
|
933
|
+
else
|
|
934
|
+
run.newlines += 1;
|
|
935
|
+
continue;
|
|
936
|
+
}
|
|
937
|
+
let words = piece;
|
|
938
|
+
if (run !== undefined) {
|
|
939
|
+
words = words.replace(/^ +/, "");
|
|
940
|
+
if (words === "")
|
|
941
|
+
continue;
|
|
942
|
+
if (parts.length > 0) {
|
|
943
|
+
parts.push(run.paragraph || run.newlines > 1 ? "\n\n" : "\n");
|
|
944
|
+
}
|
|
945
|
+
run = undefined;
|
|
946
|
+
}
|
|
947
|
+
else if (words.startsWith(" ") && parts.at(-1)?.endsWith(" ") === true) {
|
|
948
|
+
words = words.slice(1);
|
|
949
|
+
}
|
|
950
|
+
parts.push(words);
|
|
951
|
+
}
|
|
952
|
+
return {
|
|
953
|
+
text: parts
|
|
954
|
+
.join("")
|
|
955
|
+
.replace(/^[ \n]+|[ \n]+$/g, "")
|
|
956
|
+
.replace(/<(?=[A-Za-z!/?])/g, "<\u2060"),
|
|
957
|
+
notCarried: [...notCarried].sort(),
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
const isPlainObject = (value) => value !== null &&
|
|
961
|
+
typeof value === "object" &&
|
|
962
|
+
[Object.prototype, null].includes(Object.getPrototypeOf(value));
|
|
963
|
+
/**
|
|
964
|
+
* Each section with every string in its `data` that holds a tag converted by
|
|
965
|
+
* `inlineHtmlToMarkdown` (#10804 D2); keys and tag-free strings are kept as
|
|
966
|
+
* they are. `notCarried` is the sorted union of the names it did not carry.
|
|
967
|
+
*/
|
|
968
|
+
export function sectionsWithoutHtml(sections) {
|
|
969
|
+
const names = new Set();
|
|
970
|
+
const walk = (value) => {
|
|
971
|
+
if (typeof value === "string") {
|
|
972
|
+
const out = inlineHtmlToMarkdown(value);
|
|
973
|
+
for (const name of out.notCarried)
|
|
974
|
+
names.add(name);
|
|
975
|
+
return out.text;
|
|
976
|
+
}
|
|
977
|
+
if (Array.isArray(value))
|
|
978
|
+
return value.map(walk);
|
|
979
|
+
if (!isPlainObject(value))
|
|
980
|
+
return value;
|
|
981
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, walk(child)]));
|
|
982
|
+
};
|
|
983
|
+
return {
|
|
984
|
+
sections: sections.map((section) => isPlainObject(section) && "data" in section
|
|
985
|
+
? { ...section, data: walk(section.data) }
|
|
986
|
+
: section),
|
|
987
|
+
notCarried: [...names].sort(),
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
/** The first string or key rule of the hub's that `value` breaks, at `path`. */
|
|
991
|
+
function refusalAt(value, path) {
|
|
992
|
+
if (typeof value === "string") {
|
|
993
|
+
// A URL parser drops tabs, newlines and leading control characters.
|
|
994
|
+
// eslint-disable-next-line no-control-regex -- the control range is the point
|
|
995
|
+
const scheme = value.replace(/[\u0000- ]/g, "").toLowerCase();
|
|
996
|
+
const message = value.length > SECTION_STRING_MAX
|
|
997
|
+
? `A section string may hold at most ${SECTION_STRING_MAX} characters`
|
|
998
|
+
: HTML_TAG.test(value)
|
|
999
|
+
? "A section string may not hold an HTML tag"
|
|
1000
|
+
: SCRIPT_SCHEME.test(scheme)
|
|
1001
|
+
? "A section string may not use a script-bearing URL scheme"
|
|
1002
|
+
: undefined;
|
|
1003
|
+
return message === undefined ? undefined : `${message} (${path})`;
|
|
1004
|
+
}
|
|
1005
|
+
if (value === null || typeof value !== "object")
|
|
1006
|
+
return undefined;
|
|
1007
|
+
const array = Array.isArray(value);
|
|
1008
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1009
|
+
if (!array && (key.length > SECTION_KEY_MAX || HTML_TAG.test(key))) {
|
|
1010
|
+
return `A section key must be a short plain name (${path}.${key})`;
|
|
1011
|
+
}
|
|
1012
|
+
const refusal = refusalAt(child, array ? `${path}[${key}]` : `${path}.${key}`);
|
|
1013
|
+
if (refusal !== undefined)
|
|
1014
|
+
return refusal;
|
|
1015
|
+
}
|
|
1016
|
+
return undefined;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* The first section-string or key rule of the hub's structure write
|
|
1020
|
+
* (`checkSectionData`) the layout breaks, as `<message> (sections[i].data<path>)`,
|
|
1021
|
+
* or `undefined` (#10804 D5). The depth and size bounds are not restated.
|
|
1022
|
+
*/
|
|
1023
|
+
export function layoutRefusal(layout) {
|
|
1024
|
+
for (const [index, section] of layout.sections.entries()) {
|
|
1025
|
+
if (!isPlainObject(section) || section["data"] === undefined)
|
|
1026
|
+
continue;
|
|
1027
|
+
const refusal = refusalAt(section["data"], `sections[${index}].data`);
|
|
1028
|
+
if (refusal !== undefined)
|
|
1029
|
+
return refusal;
|
|
1030
|
+
}
|
|
1031
|
+
return undefined;
|
|
1032
|
+
}
|
|
567
1033
|
// ── The importer ────────────────────────────────────────────────────────────
|
|
568
1034
|
/** One whitespace-collapsed line of at most `ADAPTER_REASON_MAX` characters. */
|
|
569
1035
|
function adapterReason(err, stage = "adapter") {
|
|
@@ -573,14 +1039,19 @@ function adapterReason(err, stage = "adapter") {
|
|
|
573
1039
|
/**
|
|
574
1040
|
* What the page stores (#10534): with `sections` and a codec, its words after
|
|
575
1041
|
* the body's own text and its sections as the layout; else the page as read.
|
|
1042
|
+
* Both come from one array, its inline HTML converted (#10804 D2).
|
|
576
1043
|
*/
|
|
577
1044
|
function convert(source, codec) {
|
|
578
|
-
const { sections, ...frontmatter } = source.frontmatter;
|
|
579
|
-
if (!Array.isArray(
|
|
580
|
-
|
|
1045
|
+
const { sections: authored, ...frontmatter } = source.frontmatter;
|
|
1046
|
+
if (!Array.isArray(authored) ||
|
|
1047
|
+
authored.length === 0 ||
|
|
581
1048
|
codec === undefined) {
|
|
582
|
-
return {
|
|
1049
|
+
return {
|
|
1050
|
+
content: { ...source.frontmatter, body: source.body },
|
|
1051
|
+
notCarried: [],
|
|
1052
|
+
};
|
|
583
1053
|
}
|
|
1054
|
+
const { sections, notCarried } = sectionsWithoutHtml(authored);
|
|
584
1055
|
let words;
|
|
585
1056
|
try {
|
|
586
1057
|
words = codec(sections);
|
|
@@ -595,6 +1066,7 @@ function convert(source, codec) {
|
|
|
595
1066
|
body: lead === "" ? words : `${lead}\n\n${words}`,
|
|
596
1067
|
},
|
|
597
1068
|
layout: { kind: "sections", sections },
|
|
1069
|
+
notCarried,
|
|
598
1070
|
};
|
|
599
1071
|
}
|
|
600
1072
|
export async function importMdx(opts) {
|
|
@@ -616,15 +1088,17 @@ export async function importMdx(opts) {
|
|
|
616
1088
|
? { pages: [], skipped: [] }
|
|
617
1089
|
: planEditorial(editorialRoot, types, defaultLocale);
|
|
618
1090
|
const parseFrontmatter = opts.adapters.parseFrontmatter;
|
|
1091
|
+
const rules = opts.adapters.siteFields;
|
|
619
1092
|
// #10701 D3 — one route path holds one page, so an editorial index the run
|
|
620
|
-
// will write supersedes
|
|
621
|
-
// scaffold's teaser), which the create would refuse `slug_taken`.
|
|
1093
|
+
// will write supersedes the content page of its type at the surface's own
|
|
1094
|
+
// slug (the scaffold's teaser), which the create would refuse `slug_taken`.
|
|
1095
|
+
// Any other slug of the type has a link of its own (#10805 D5).
|
|
622
1096
|
const indexTypes = new Set(parseFrontmatter === undefined
|
|
623
1097
|
? []
|
|
624
1098
|
: editorial.pages
|
|
625
1099
|
.filter((p) => p.invalid === undefined && INDEX_TYPES.has(p.type))
|
|
626
1100
|
.map((p) => p.type));
|
|
627
|
-
const superseded = (p) => indexTypes.has(p.type) && p.slug
|
|
1101
|
+
const superseded = (p) => indexTypes.has(p.type) && p.slug === INDEX_OWN_SLUG.get(p.type);
|
|
628
1102
|
const pages = [
|
|
629
1103
|
...content.pages.filter((p) => !superseded(p)),
|
|
630
1104
|
...editorial.pages,
|
|
@@ -681,15 +1155,15 @@ export async function importMdx(opts) {
|
|
|
681
1155
|
}
|
|
682
1156
|
let read;
|
|
683
1157
|
try {
|
|
684
|
-
read = editorialSource(page, parseFrontmatter(readFileSync(join(editorialRoot, page.path), "utf8")));
|
|
1158
|
+
read = editorialSource(page, parseFrontmatter(readFileSync(join(editorialRoot, page.path), "utf8")), rules);
|
|
685
1159
|
}
|
|
686
1160
|
catch (err) {
|
|
687
1161
|
fail(adapterReason(err, "editorial"));
|
|
688
1162
|
continue;
|
|
689
1163
|
}
|
|
690
1164
|
source = read.source;
|
|
691
|
-
if (read.
|
|
692
|
-
onLine(`${page.path}: not imported — ${read.
|
|
1165
|
+
if (read.notSent.length > 0) {
|
|
1166
|
+
onLine(`${page.path}: not imported — ${notSentList(read.notSent)}`);
|
|
693
1167
|
}
|
|
694
1168
|
}
|
|
695
1169
|
else {
|
|
@@ -712,13 +1186,66 @@ export async function importMdx(opts) {
|
|
|
712
1186
|
fail(converted.reason);
|
|
713
1187
|
continue;
|
|
714
1188
|
}
|
|
1189
|
+
// #10898 D5 — a file never supplies the mark; the importer computes it.
|
|
1190
|
+
const { [LIVE_SOURCE_KEY]: _fileMark, ...words } = converted.content;
|
|
1191
|
+
const body = words["body"];
|
|
1192
|
+
converted.content =
|
|
1193
|
+
opts.liveSource === true && typeof body === "string"
|
|
1194
|
+
? {
|
|
1195
|
+
...words,
|
|
1196
|
+
[LIVE_SOURCE_KEY]: {
|
|
1197
|
+
bodySha256: createHash("sha256").update(body, "utf8").digest("hex"),
|
|
1198
|
+
},
|
|
1199
|
+
}
|
|
1200
|
+
: words;
|
|
1201
|
+
if (converted.notCarried.length > 0) {
|
|
1202
|
+
onLine(`${outcomePath(page)}: inline HTML not carried — ${converted.notCarried.join(", ")} (the layout holds no HTML; their text is kept)`);
|
|
1203
|
+
}
|
|
715
1204
|
if (converted.layout === undefined &&
|
|
716
1205
|
Array.isArray(source.frontmatter["sections"]) &&
|
|
717
1206
|
source.frontmatter["sections"].length > 0) {
|
|
718
1207
|
onLine(`${page.path}: keeps its words in sections — the site's ${VALIDATION_PACKAGE} has no words codec; update its dependencies and re-run`);
|
|
719
1208
|
}
|
|
720
|
-
|
|
1209
|
+
// #10804 D5 — a layout the hub would refuse fails here, in a dry run and
|
|
1210
|
+
// under --apply alike, before its words are saved.
|
|
1211
|
+
const refusal = converted.layout === undefined
|
|
1212
|
+
? undefined
|
|
1213
|
+
: layoutRefusal(converted.layout);
|
|
1214
|
+
if (refusal !== undefined) {
|
|
1215
|
+
fail(`layout: ${refusal}`);
|
|
1216
|
+
continue;
|
|
1217
|
+
}
|
|
1218
|
+
const result = await writePage(t, page, defaultLocale, converted.content, converted.layout, rules?.publicPageTags);
|
|
721
1219
|
halt = result.halt;
|
|
1220
|
+
// #10898 D5 — a hub that predates the mark strips it, so every re-run
|
|
1221
|
+
// would save the page again; say so. An answer that carries no content
|
|
1222
|
+
// says nothing about what was kept.
|
|
1223
|
+
if (opts.liveSource === true &&
|
|
1224
|
+
result.sent === true &&
|
|
1225
|
+
result.stored !== null &&
|
|
1226
|
+
typeof result.stored === "object" &&
|
|
1227
|
+
!Object.hasOwn(result.stored, LIVE_SOURCE_KEY)) {
|
|
1228
|
+
onLine(`${outcomePath(page)}: not kept by the hub: ${LIVE_SOURCE_KEY} (the hub predates the live-source mark; update it and re-run)`);
|
|
1229
|
+
}
|
|
1230
|
+
// #10898 D6 — what the hub's publish gate will answer for these words.
|
|
1231
|
+
const check = opts.liveSource === true ? opts.adapters.publishCheck : undefined;
|
|
1232
|
+
if (check !== undefined && !("reason" in result.outcome)) {
|
|
1233
|
+
const verdict = check(page.type, converted.content, converted.layout);
|
|
1234
|
+
if (verdict !== undefined)
|
|
1235
|
+
result.outcome = { ...result.outcome, publishVerdict: verdict };
|
|
1236
|
+
}
|
|
1237
|
+
// #10806 D4 — an older hub strips what it has no member for; say so.
|
|
1238
|
+
// An answer that carries no content says nothing about what was kept.
|
|
1239
|
+
const dropped = rules === undefined ||
|
|
1240
|
+
page.root !== "editorial" ||
|
|
1241
|
+
"reason" in result.outcome ||
|
|
1242
|
+
result.stored === null ||
|
|
1243
|
+
typeof result.stored !== "object"
|
|
1244
|
+
? []
|
|
1245
|
+
: notKept(converted.content, result.stored, rules);
|
|
1246
|
+
if (dropped.length > 0) {
|
|
1247
|
+
onLine(`${page.path}: not kept by the hub: ${dropped.join(", ")} (the hub predates site fields; update it and re-run)`);
|
|
1248
|
+
}
|
|
722
1249
|
if (opts.publish !== true || "reason" in result.outcome) {
|
|
723
1250
|
record(result.outcome);
|
|
724
1251
|
continue;
|
|
@@ -762,6 +1289,43 @@ export async function importMdx(opts) {
|
|
|
762
1289
|
...(opts.publish === true && { live, published }),
|
|
763
1290
|
};
|
|
764
1291
|
}
|
|
1292
|
+
/**
|
|
1293
|
+
* The hub's publish gate over a live-source page, as the site's contract
|
|
1294
|
+
* reads it: the page's words checked against its type's template and the
|
|
1295
|
+
* structure publish's repair would build — the layout when the page converts,
|
|
1296
|
+
* an editorial template's frontmatter quartet, else none — with the
|
|
1297
|
+
* required-heading findings advisory. Publish repairs every `script` finding,
|
|
1298
|
+
* so only the rest block.
|
|
1299
|
+
*/
|
|
1300
|
+
export function publishCheckOf(members) {
|
|
1301
|
+
return (type, content, layout) => {
|
|
1302
|
+
const template = members.registry.find((entry) => entry.key === type)?.template;
|
|
1303
|
+
if (template === undefined)
|
|
1304
|
+
return undefined;
|
|
1305
|
+
const text = (key) => {
|
|
1306
|
+
const value = content[key];
|
|
1307
|
+
return typeof value === "string" ? value : "";
|
|
1308
|
+
};
|
|
1309
|
+
const structure = layout ??
|
|
1310
|
+
(members.templates[template]?.kind === "editorial"
|
|
1311
|
+
? {
|
|
1312
|
+
kind: "editorial",
|
|
1313
|
+
frontmatter: Object.fromEntries(EDITORIAL_STRUCTURE_FIELDS.filter((field) => content[field] !== undefined).map((field) => [field, content[field]])),
|
|
1314
|
+
}
|
|
1315
|
+
: null);
|
|
1316
|
+
const report = members.liveSourceReport(members.checkPage({
|
|
1317
|
+
template,
|
|
1318
|
+
title: text("title"),
|
|
1319
|
+
description: text("description"),
|
|
1320
|
+
slug: text("slug"),
|
|
1321
|
+
body: text("body"),
|
|
1322
|
+
}, structure));
|
|
1323
|
+
const blocking = report.issues.filter((issue) => issue.fixer !== "script");
|
|
1324
|
+
return blocking.length === 0
|
|
1325
|
+
? { publishable: true, advisory: report.advisory ?? [] }
|
|
1326
|
+
: { publishable: false, status: report.status, blocking };
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
765
1329
|
// ── The site's own adapter (D1) ─────────────────────────────────────────────
|
|
766
1330
|
/** Whether a `node_modules` at or above `dir` holds the adapter package. */
|
|
767
1331
|
function installedAbove(dir) {
|
|
@@ -806,16 +1370,19 @@ export async function loadSiteMdxAdapter(siteRoot) {
|
|
|
806
1370
|
!types.every((type) => typeof type === "string")) {
|
|
807
1371
|
throw new ImportMdxRefusedError(`import-mdx: ${CONTENT_ADAPTERS_PACKAGE} in ${web} does not export createMdxAdapter and SCHEMA_ORG_TYPES. Install the site's dependencies (pnpm install) first. Nothing was sent.`);
|
|
808
1372
|
}
|
|
809
|
-
// The codec the adapter's own validation package carries (#10534)
|
|
810
|
-
// that predates
|
|
811
|
-
|
|
1373
|
+
// The codec the adapter's own validation package carries (#10534), and its
|
|
1374
|
+
// site-field rule (#10806 D4); one that predates either, or none, leaves
|
|
1375
|
+
// pages unconverted or site fields unsent, and the run says so.
|
|
1376
|
+
let validation = {};
|
|
812
1377
|
try {
|
|
813
|
-
const
|
|
814
|
-
|
|
1378
|
+
const path = createRequire(entry).resolve(VALIDATION_PACKAGE);
|
|
1379
|
+
validation = (await import(pathToFileURL(path).href));
|
|
815
1380
|
}
|
|
816
1381
|
catch {
|
|
817
|
-
// Not resolvable from the adapter: no codec.
|
|
1382
|
+
// Not resolvable from the adapter: no codec and no site-field rule.
|
|
818
1383
|
}
|
|
1384
|
+
const codec = validation["sectionsToMarkdown"];
|
|
1385
|
+
const { siteFieldRefusal: refusal, publicPageTags, SITE_FIELDS_MAX_KEYS: maxKeys, SITE_FIELDS_MAX_BYTES: maxBytes, } = validation;
|
|
819
1386
|
// The adapter's own frontmatter parser (#10701 D1), for the editorial tree;
|
|
820
1387
|
// none leaves every editorial page failed, and the run says so.
|
|
821
1388
|
let matter;
|
|
@@ -826,11 +1393,46 @@ export async function loadSiteMdxAdapter(siteRoot) {
|
|
|
826
1393
|
catch {
|
|
827
1394
|
// Not resolvable from the adapter: no parser.
|
|
828
1395
|
}
|
|
1396
|
+
// #10898 D6 — the site's own page-type registry, beside its contract; a
|
|
1397
|
+
// validation package that predates the live-source report, or no registry,
|
|
1398
|
+
// leaves the dry run's publish verdict unchecked, and the run says so.
|
|
1399
|
+
let registry;
|
|
1400
|
+
try {
|
|
1401
|
+
const path = createRequire(entry).resolve(PAGE_TYPES_PACKAGE);
|
|
1402
|
+
registry = (await import(pathToFileURL(path).href))["pageTypeRegistry"];
|
|
1403
|
+
}
|
|
1404
|
+
catch {
|
|
1405
|
+
// Not resolvable from the adapter: no registry.
|
|
1406
|
+
}
|
|
1407
|
+
const { checkPage, liveSourceReport, PAGE_TEMPLATES: templates } = validation;
|
|
829
1408
|
return {
|
|
830
1409
|
...mod,
|
|
831
1410
|
...(typeof codec === "function" && {
|
|
832
1411
|
sectionsToMarkdown: codec,
|
|
833
1412
|
}),
|
|
1413
|
+
...(typeof refusal === "function" &&
|
|
1414
|
+
typeof publicPageTags === "function" &&
|
|
1415
|
+
typeof maxKeys === "number" &&
|
|
1416
|
+
typeof maxBytes === "number" && {
|
|
1417
|
+
siteFields: {
|
|
1418
|
+
refusal: refusal,
|
|
1419
|
+
publicPageTags: publicPageTags,
|
|
1420
|
+
maxKeys,
|
|
1421
|
+
maxBytes,
|
|
1422
|
+
},
|
|
1423
|
+
}),
|
|
1424
|
+
...(typeof checkPage === "function" &&
|
|
1425
|
+
typeof liveSourceReport === "function" &&
|
|
1426
|
+
templates !== null &&
|
|
1427
|
+
typeof templates === "object" &&
|
|
1428
|
+
Array.isArray(registry) && {
|
|
1429
|
+
publishCheck: publishCheckOf({
|
|
1430
|
+
checkPage: checkPage,
|
|
1431
|
+
liveSourceReport: liveSourceReport,
|
|
1432
|
+
templates: templates,
|
|
1433
|
+
registry: registry,
|
|
1434
|
+
}),
|
|
1435
|
+
}),
|
|
834
1436
|
...(typeof matter === "function" && {
|
|
835
1437
|
parseFrontmatter: (raw) => {
|
|
836
1438
|
const { data, content } = matter(raw);
|