create-ailk 0.42.1 → 0.44.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 +33 -10
- package/component-catalog.json +23 -0
- package/dist/cli.js +34 -0
- package/dist/compare-renders.d.ts +67 -0
- package/dist/compare-renders.js +274 -0
- package/dist/lib/import-mdx.d.ts +32 -15
- package/dist/lib/import-mdx.js +197 -188
- package/dist/lib/render-capture.d.ts +22 -0
- package/dist/lib/render-capture.js +125 -0
- package/dist/migrate-content.d.ts +9 -16
- package/dist/migrate-content.js +46 -82
- package/package.json +3 -3
- package/site-templates/shapes/local-business-service/content/en/Service/first-job.mdx +49 -26
- package/site-templates/shapes/local-business-service/content/en/Service/second-job.mdx +49 -26
- package/site-templates/shapes/local-business-service/content/en/Service/third-job.mdx +49 -26
- package/site-templates/shapes/organization-service/content/en/Service/first-engagement.mdx +49 -26
- package/site-templates/shapes/organization-service/content/en/Service/second-engagement.mdx +49 -26
- package/site-templates/shapes/organization-service/content/en/Service/third-engagement.mdx +49 -26
- package/site-templates/shapes/person-service/content/en/Service/first-engagement.mdx +49 -26
- package/site-templates/shapes/person-service/content/en/Service/second-engagement.mdx +49 -26
- package/site-templates/shapes/person-service/content/en/Service/third-engagement.mdx +49 -26
- package/templates/apps/api/CLAUDE.md +23 -5
- package/templates/apps/mcp/CLAUDE.md +32 -3
- package/templates/apps/web/package.json +1 -1
- package/versions.json +50 -50
package/dist/lib/import-mdx.js
CHANGED
|
@@ -3,24 +3,25 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Reads a site's default-locale MDX pages through the site's own MDX adapter
|
|
5
5
|
* and writes each one as a `text/page` Artifact through the tenant-guarded
|
|
6
|
-
* workspace content routes. Per page (D3): read the draft
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* workspace content routes. Per page (D3, #11843 D1): read the draft, then
|
|
7
|
+
* save once — `save_page` (`PUT …/content/:type/:slug`) for a page and
|
|
8
|
+
* `save_document` (`POST …/documents/save`) for a `Document`, with
|
|
9
|
+
* `version: null` on a 404 and the read's version and layout token otherwise
|
|
10
|
+
* — or write nothing when the read already holds what the save would store,
|
|
11
|
+
* so a second run over the same files creates nothing and reports every page
|
|
12
|
+
* `unchanged` (#11843 D4). A file the adapter rejects is `failed` with its path
|
|
10
13
|
* and reason and the run goes on. The seed step (U6b) and `migrate-content`
|
|
11
14
|
* (U6c) both call it; this module adds no command.
|
|
12
15
|
*
|
|
13
|
-
* A page whose frontmatter carries `sections` is
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* and sends the layout once more (#11749 D2), so the live page does not change
|
|
23
|
-
* until it is published. A second refusal fails the page with that reason.
|
|
16
|
+
* A page whose frontmatter carries `sections` is saved in the section form
|
|
17
|
+
* (#10534, #11843 D1): the sections are `save_page`'s words, and the hub
|
|
18
|
+
* builds the body from them, so the text before the first section — which
|
|
19
|
+
* nothing renders — is not sent (D3). Any other page's words are its body.
|
|
20
|
+
* The importer compares the read with what the save would store, its words
|
|
21
|
+
* as the codec (`sectionsToMarkdown`, ADR 0038) writes them, so a page the
|
|
22
|
+
* earlier importer stored after a lead is still `unchanged`. An edit to a
|
|
23
|
+
* live page appends a draft, so the live page does not change until it is
|
|
24
|
+
* published.
|
|
24
25
|
*
|
|
25
26
|
* A section string that holds inline HTML is converted first (#10804) — a
|
|
26
27
|
* link to `[label](href)`, a line break to a newline, a block to a blank
|
|
@@ -28,7 +29,9 @@
|
|
|
28
29
|
* carry no tag, which the hub's structure write refuses. The layout is then
|
|
29
30
|
* checked against the hub's section-string rules before any write, so a page
|
|
30
31
|
* the hub would refuse fails with the rule and the path, and a page whose
|
|
31
|
-
* draft holds no layout yet is never reported `unchanged`.
|
|
32
|
+
* draft holds no layout yet is never reported `unchanged`. A page that fails
|
|
33
|
+
* its type's checks is refused `422 invalid` by the save, and nothing is
|
|
34
|
+
* stored (#11843 D2).
|
|
32
35
|
*
|
|
33
36
|
* create-ailk ships one runtime dependency, so the adapter is never imported:
|
|
34
37
|
* the caller injects it, and `loadSiteMdxAdapter` resolves the SITE's
|
|
@@ -44,11 +47,9 @@
|
|
|
44
47
|
* vocabulary does not name rides in `siteFields`, and a blog post's tags are
|
|
45
48
|
* sent (#10806); a key the store cannot keep is named with its reason.
|
|
46
49
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* the site's contract members (`publishCheck`), each written page's outcome
|
|
51
|
-
* carries the verdict the hub's publish gate will give it (D6).
|
|
50
|
+
* No page carries the hub's live-source mark: no save keeps it (#11843 D7).
|
|
51
|
+
* With the site's contract members (`publishCheck`), each written page's
|
|
52
|
+
* outcome carries the verdict the hub's publish gate will give it (#10898 D6).
|
|
52
53
|
*
|
|
53
54
|
* Given `publish` (#10659 D2), each page with no Live version is set Live
|
|
54
55
|
* after it is written (`POST …/publish`, the draft tip); a page already Live
|
|
@@ -61,9 +62,9 @@
|
|
|
61
62
|
*
|
|
62
63
|
* Spec: docs/specs/10203-import-mdx-one-mdx-artifact-spec.md; the editorial
|
|
63
64
|
* walk docs/specs/10701-import-mdx-walks-the-editorial-spec.md; its site
|
|
64
|
-
* fields docs/specs/10806-the-editorial-import-drops-blog-spec.md
|
|
65
|
+
* fields docs/specs/10806-the-editorial-import-drops-blog-spec.md; the saves
|
|
66
|
+
* docs/specs/11843-the-scaffold-s-importer-saves-spec.md.
|
|
65
67
|
*/
|
|
66
|
-
import { createHash } from "node:crypto";
|
|
67
68
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
68
69
|
import { createRequire } from "node:module";
|
|
69
70
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -80,10 +81,18 @@ const VALIDATION_PACKAGE = "@working-theory/validation";
|
|
|
80
81
|
const FRONTMATTER_PACKAGE = "gray-matter";
|
|
81
82
|
/** The page-type registry: a dependency of the adapter package (#10898 D6). */
|
|
82
83
|
const PAGE_TYPES_PACKAGE = "@working-theory/schema/page-types";
|
|
83
|
-
/** The hub's live-source content key (`LIVE_SOURCE_KEY`, api-content-write `content.ts`), restated:
|
|
84
|
+
/** The hub's live-source content key (`LIVE_SOURCE_KEY`, api-content-write `content.ts`), restated: never sent (#11843 D7). */
|
|
84
85
|
const LIVE_SOURCE_KEY = "liveSource";
|
|
85
86
|
/** The hub's written-from record (`WRITTEN_FROM_KEY`, same file), restated: never taken from a file (#11707 D9). */
|
|
86
87
|
const WRITTEN_FROM_KEY = "writtenFrom";
|
|
88
|
+
/** `DOCUMENT_TYPE` (the validation package's `content-draft.ts`), restated: saved with `save_document` (#11843 D10). */
|
|
89
|
+
const DOCUMENT_TYPE = "Document";
|
|
90
|
+
/**
|
|
91
|
+
* The frontmatter keys never sent in `fields` (#11843 D2): the ones the save
|
|
92
|
+
* takes from the address and the words, and the two hub records a file never
|
|
93
|
+
* supplies (#10898 D5, #11707 D9).
|
|
94
|
+
*/
|
|
95
|
+
const NOT_FIELDS = new Set(["sections", "type", "slug", "locale", LIVE_SOURCE_KEY, WRITTEN_FROM_KEY]);
|
|
87
96
|
/** `EDITORIAL_FIELDS` (api-content-write `derive-publish.ts`): the editorial structure publish's repair builds. */
|
|
88
97
|
const EDITORIAL_STRUCTURE_FIELDS = ["author", "tags", "order", "parent"];
|
|
89
98
|
/** The adapter's locale shape (`BCP47_RE` in its `mdx/adapter.ts`). */
|
|
@@ -532,7 +541,7 @@ function retryAfterSeconds(header) {
|
|
|
532
541
|
? seconds
|
|
533
542
|
: RATE_LIMIT_WAIT_MAX_S;
|
|
534
543
|
}
|
|
535
|
-
async function call(t, method, url, body
|
|
544
|
+
async function call(t, method, url, body) {
|
|
536
545
|
for (let retry = 0;; retry++) {
|
|
537
546
|
let response;
|
|
538
547
|
try {
|
|
@@ -541,10 +550,6 @@ async function call(t, method, url, body, ifMatch) {
|
|
|
541
550
|
headers: {
|
|
542
551
|
authorization: `Bearer ${t.key}`,
|
|
543
552
|
...(body !== undefined && { "content-type": "application/json" }),
|
|
544
|
-
// #10264 — the version rides `x-draft-version`; `if-match` rides
|
|
545
|
-
// beside it for one release so this importer still saves against an
|
|
546
|
-
// API that predates the new header (the route prefers the new one).
|
|
547
|
-
...(ifMatch !== undefined && { "x-draft-version": ifMatch, "if-match": ifMatch }),
|
|
548
553
|
},
|
|
549
554
|
...(body !== undefined && { body: JSON.stringify(body) }),
|
|
550
555
|
// A redirect would re-send the key and the body to another URL.
|
|
@@ -596,126 +601,121 @@ function refusedAnswer(at, answer) {
|
|
|
596
601
|
}
|
|
597
602
|
/**
|
|
598
603
|
* A success answered for another locale: the API does not serve `locale`. A
|
|
599
|
-
* success with no locale at all is not the API's answer shape: that page
|
|
604
|
+
* success with no locale at all is not the API's answer shape: that page
|
|
605
|
+
* fails. A read names its locale at `data.locale`, a save at
|
|
606
|
+
* `data.address.locale` (#11843 D1).
|
|
600
607
|
*/
|
|
601
|
-
function wrongLocale(at, answer, locale) {
|
|
602
|
-
if ("network" in answer
|
|
608
|
+
function wrongLocale(at, answer, locale, of) {
|
|
609
|
+
if ("network" in answer)
|
|
603
610
|
return undefined;
|
|
604
|
-
|
|
611
|
+
const address = answer.data["address"];
|
|
612
|
+
const answered = of === "read"
|
|
613
|
+
? answer.data["locale"]
|
|
614
|
+
: address !== null && typeof address === "object"
|
|
615
|
+
? address["locale"]
|
|
616
|
+
: undefined;
|
|
617
|
+
if (answered === locale)
|
|
618
|
+
return undefined;
|
|
619
|
+
if (typeof answered !== "string") {
|
|
605
620
|
return failed(at, `${answer.status} unknown`);
|
|
606
621
|
}
|
|
607
622
|
return failed(at, `the API does not serve locale ${locale}`, `not sent: the API does not serve locale ${locale}`);
|
|
608
623
|
}
|
|
609
|
-
/**
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
624
|
+
/**
|
|
625
|
+
* Records a save carries forward when the file sends none (#11843 D4): never
|
|
626
|
+
* compared unless the file sends it, or every run would save again. The
|
|
627
|
+
* live-source mark is never kept, so never compared.
|
|
628
|
+
*/
|
|
629
|
+
const CARRIED_RECORDS = [WRITTEN_FROM_KEY, "pageChange", "reader", "narrator"];
|
|
630
|
+
/** The stored content's fields, as compared with the fields a save sends. */
|
|
631
|
+
function storedFields(stored, fields) {
|
|
632
|
+
if (stored === null || typeof stored !== "object" || Array.isArray(stored))
|
|
633
|
+
return {};
|
|
634
|
+
const { type: _t, slug: _s, body: _b, locale: _l, [LIVE_SOURCE_KEY]: _m, ...rest } = stored;
|
|
635
|
+
for (const key of CARRIED_RECORDS)
|
|
636
|
+
if (!Object.hasOwn(fields, key))
|
|
637
|
+
delete rest[key];
|
|
614
638
|
return rest;
|
|
615
639
|
}
|
|
616
|
-
|
|
640
|
+
/**
|
|
641
|
+
* Whether the stored body holds the page's words (#11843 D4): exactly, or —
|
|
642
|
+
* for a layout — after a lead, as the earlier importer stored it.
|
|
643
|
+
*/
|
|
644
|
+
function sameWords(storedBody, save) {
|
|
645
|
+
if (typeof storedBody !== "string")
|
|
646
|
+
return false;
|
|
647
|
+
return (storedBody === save.body ||
|
|
648
|
+
(save.layout !== undefined && storedBody.endsWith(`\n\n${save.body}`)));
|
|
649
|
+
}
|
|
650
|
+
async function writePage(t, page, locale, save, publicTags) {
|
|
617
651
|
const { root, path, type, slug } = page;
|
|
618
|
-
const pagePath = `${t.base}/content/${encodeURIComponent(type)}/${encodeURIComponent(slug)}`;
|
|
619
652
|
const query = `?locale=${encodeURIComponent(locale)}`;
|
|
620
|
-
const address = `${
|
|
653
|
+
const address = `${t.base}/content/${encodeURIComponent(type)}/${encodeURIComponent(slug)}${query}`;
|
|
654
|
+
const document = type === DOCUMENT_TYPE;
|
|
621
655
|
// The route's `statusOf`: anything but `draft` has a Live version.
|
|
622
656
|
let live = false;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const outcome = (result, layoutOnly = false) => ({
|
|
657
|
+
const sent = { ...save.fields, type };
|
|
658
|
+
const outcome = (result, stored, layoutOnly = false) => ({
|
|
626
659
|
outcome: { root, path, result, type, slug, ...(layoutOnly && { layoutOnly: true }) },
|
|
627
660
|
live,
|
|
628
|
-
stored,
|
|
629
|
-
sent,
|
|
661
|
+
...(stored !== undefined && { stored }),
|
|
630
662
|
});
|
|
631
|
-
//
|
|
632
|
-
//
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
663
|
+
// #11843 D1 — one save: `save_document` for a Document, else `save_page`,
|
|
664
|
+
// with the sections as a layout's words and `{ body }` for the rest.
|
|
665
|
+
const write = (version, structureToken) => document
|
|
666
|
+
? call(t, "POST", `${t.base}/documents/save`, {
|
|
667
|
+
address: { type, slug, locale },
|
|
668
|
+
version,
|
|
669
|
+
fields: save.fields,
|
|
670
|
+
words: { body: save.body },
|
|
671
|
+
})
|
|
672
|
+
: call(t, "PUT", address, {
|
|
673
|
+
version,
|
|
638
674
|
structureToken,
|
|
639
|
-
|
|
675
|
+
fields: save.fields,
|
|
676
|
+
words: save.layout === undefined ? { body: save.body } : save.layout.sections,
|
|
640
677
|
});
|
|
641
|
-
let put = await writeLayout();
|
|
642
|
-
// #11749 D2 — the hub refuses a layout on a live tip and names the remedy:
|
|
643
|
-
// save a draft (the same words, under the version read), then write the
|
|
644
|
-
// layout once more. A save carries the structure token forward (§1).
|
|
645
|
-
const redraft = version !== undefined &&
|
|
646
|
-
!("network" in put) &&
|
|
647
|
-
put.status === 409 &&
|
|
648
|
-
put.code === "draft_is_live";
|
|
649
|
-
if (redraft) {
|
|
650
|
-
const saved = await call(t, "PATCH", address, content, version);
|
|
651
|
-
if ("network" in saved || saved.status !== 200)
|
|
652
|
-
return refusedAnswer(page, saved);
|
|
653
|
-
stored = saved.data["content"];
|
|
654
|
-
sent = true;
|
|
655
|
-
const mismatch = wrongLocale(page, saved, locale);
|
|
656
|
-
if (mismatch !== undefined)
|
|
657
|
-
return mismatch;
|
|
658
|
-
put = await writeLayout();
|
|
659
|
-
}
|
|
660
|
-
if ("network" in put || put.status !== 200)
|
|
661
|
-
return refusedAnswer(page, put);
|
|
662
|
-
// #10804 D6 — with no token the hub writes the layout (or refuses a
|
|
663
|
-
// live tip), so a dry run's `written: false` never makes it unchanged.
|
|
664
|
-
const layoutOnly = result === "unchanged" &&
|
|
665
|
-
(redraft || structureToken === null || put.data["written"] === true);
|
|
666
|
-
return (wrongLocale(page, put, locale) ??
|
|
667
|
-
outcome(layoutOnly ? "updated" : result, layoutOnly));
|
|
668
|
-
};
|
|
669
678
|
for (let reread = false;; reread = true) {
|
|
670
679
|
const read = await call(t, "GET", address);
|
|
671
680
|
if ("network" in read)
|
|
672
681
|
return refusedAnswer(page, read);
|
|
682
|
+
let version = null;
|
|
683
|
+
let structureToken = null;
|
|
684
|
+
let layoutOnly = false;
|
|
673
685
|
if (read.status === 200) {
|
|
674
|
-
const mismatch = wrongLocale(page, read, locale);
|
|
686
|
+
const mismatch = wrongLocale(page, read, locale, "read");
|
|
675
687
|
if (mismatch !== undefined)
|
|
676
688
|
return mismatch;
|
|
677
|
-
const
|
|
678
|
-
if (typeof
|
|
689
|
+
const readVersion = read.data["version"];
|
|
690
|
+
if (typeof readVersion !== "string")
|
|
679
691
|
return failed(page, "200 unknown");
|
|
692
|
+
version = readVersion;
|
|
680
693
|
live = read.data["status"] !== "draft";
|
|
681
694
|
const token = read.data["structureToken"];
|
|
682
|
-
|
|
683
|
-
stored = read.data["content"];
|
|
684
|
-
// #
|
|
685
|
-
const
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const saved = await call(t, "PATCH", address, content, version);
|
|
693
|
-
if ("network" in saved || saved.status !== 200)
|
|
694
|
-
return refusedAnswer(page, saved);
|
|
695
|
-
stored = saved.data["content"];
|
|
696
|
-
sent = true;
|
|
697
|
-
// A save carries the structure token forward (#10330 D5).
|
|
698
|
-
return (wrongLocale(page, saved, locale) ?? done("updated", structureToken));
|
|
695
|
+
structureToken = typeof token === "string" ? token : null;
|
|
696
|
+
const stored = read.data["content"];
|
|
697
|
+
// #11843 D4 — one comparison, before any write.
|
|
698
|
+
const sameFields = canonical(compared(storedFields(stored, save.fields), sent, publicTags)) ===
|
|
699
|
+
canonical(compared(save.fields, sent, publicTags));
|
|
700
|
+
const sameBody = sameWords(stored?.["body"], save);
|
|
701
|
+
const sameLayout = save.layout === undefined || canonical(read.data["structure"]) === canonical(save.layout);
|
|
702
|
+
if (sameFields && sameBody && sameLayout)
|
|
703
|
+
return outcome("unchanged");
|
|
704
|
+
layoutOnly = sameFields && sameBody;
|
|
699
705
|
}
|
|
700
|
-
if (read.status !== 404 || reread)
|
|
706
|
+
else if (read.status !== 404 || reread) {
|
|
701
707
|
return refusedAnswer(page, read);
|
|
702
|
-
const created = await call(t, "POST", `${t.base}/content`, {
|
|
703
|
-
...content,
|
|
704
|
-
locale,
|
|
705
|
-
});
|
|
706
|
-
if ("network" in created)
|
|
707
|
-
return refusedAnswer(page, created);
|
|
708
|
-
if (created.status === 201) {
|
|
709
|
-
stored = created.data["content"];
|
|
710
|
-
sent = true;
|
|
711
|
-
return wrongLocale(page, created, locale) ?? done("created");
|
|
712
|
-
}
|
|
713
|
-
// 409 slug_taken: another page holds this page's registry link (#10268
|
|
714
|
-
// D5) — reported as it is, since a re-read at this address finds nothing.
|
|
715
|
-
// Any other 409: created by someone else since the read — read it once more.
|
|
716
|
-
if (created.status !== 409 || created.code === "slug_taken") {
|
|
717
|
-
return refusedAnswer(page, created);
|
|
718
708
|
}
|
|
709
|
+
const saved = await write(version, structureToken);
|
|
710
|
+
if ("network" in saved)
|
|
711
|
+
return refusedAnswer(page, saved);
|
|
712
|
+
// #11843 D5 — created by someone else since the read: read it once more.
|
|
713
|
+
if (version === null && saved.status === 409 && saved.code === "stale" && !reread)
|
|
714
|
+
continue;
|
|
715
|
+
if (saved.status !== (version === null ? 201 : 200))
|
|
716
|
+
return refusedAnswer(page, saved);
|
|
717
|
+
return (wrongLocale(page, saved, locale, "save") ??
|
|
718
|
+
outcome(version === null ? "created" : "updated", saved.data["fields"], layoutOnly));
|
|
719
719
|
}
|
|
720
720
|
}
|
|
721
721
|
// ── The report (D6) ─────────────────────────────────────────────────────────
|
|
@@ -1060,19 +1060,19 @@ function adapterReason(err, stage = "adapter") {
|
|
|
1060
1060
|
return `${stage}: ${message.replace(/\s+/g, " ").trim().slice(0, ADAPTER_REASON_MAX)}`;
|
|
1061
1061
|
}
|
|
1062
1062
|
/**
|
|
1063
|
-
* What the page
|
|
1064
|
-
* the
|
|
1065
|
-
*
|
|
1063
|
+
* What the page saves (#10534, #11843 D1–D3): its fields — the frontmatter
|
|
1064
|
+
* less the keys the address and the words own, and the two hub records a file
|
|
1065
|
+
* never supplies (#10898 D5, #11707 D9) — and, with `sections` and a codec,
|
|
1066
|
+
* the sections as its layout and the codec's words as the body the hub will
|
|
1067
|
+
* build from them; else the file's body. The text before a page's first
|
|
1068
|
+
* section is not sent: nothing renders it (D3). Both come from one array, its
|
|
1069
|
+
* inline HTML converted (#10804 D2).
|
|
1066
1070
|
*/
|
|
1067
1071
|
function convert(source, codec) {
|
|
1068
|
-
const
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
return {
|
|
1073
|
-
content: { ...source.frontmatter, body: source.body },
|
|
1074
|
-
notCarried: [],
|
|
1075
|
-
};
|
|
1072
|
+
const fields = Object.fromEntries(Object.entries(source.frontmatter).filter(([key]) => !NOT_FIELDS.has(key)));
|
|
1073
|
+
const authored = source.frontmatter["sections"];
|
|
1074
|
+
if (!Array.isArray(authored) || authored.length === 0 || codec === undefined) {
|
|
1075
|
+
return { fields, body: source.body, notCarried: [] };
|
|
1076
1076
|
}
|
|
1077
1077
|
const { sections, notCarried } = sectionsWithoutHtml(authored);
|
|
1078
1078
|
let words;
|
|
@@ -1082,15 +1082,7 @@ function convert(source, codec) {
|
|
|
1082
1082
|
catch (err) {
|
|
1083
1083
|
return { reason: adapterReason(err, "codec") };
|
|
1084
1084
|
}
|
|
1085
|
-
|
|
1086
|
-
return {
|
|
1087
|
-
content: {
|
|
1088
|
-
...frontmatter,
|
|
1089
|
-
body: lead === "" ? words : `${lead}\n\n${words}`,
|
|
1090
|
-
},
|
|
1091
|
-
layout: { kind: "sections", sections },
|
|
1092
|
-
notCarried,
|
|
1093
|
-
};
|
|
1085
|
+
return { fields, body: words, layout: { kind: "sections", sections }, notCarried };
|
|
1094
1086
|
}
|
|
1095
1087
|
export async function importMdx(opts) {
|
|
1096
1088
|
const defaultLocale = opts.defaultLocale ?? "en";
|
|
@@ -1114,7 +1106,7 @@ export async function importMdx(opts) {
|
|
|
1114
1106
|
const rules = opts.adapters.siteFields;
|
|
1115
1107
|
// #10701 D3 — one route path holds one page, so an editorial index the run
|
|
1116
1108
|
// will write supersedes the content page of its type at the surface's own
|
|
1117
|
-
// slug (the scaffold's teaser), which the
|
|
1109
|
+
// slug (the scaffold's teaser), which the save would refuse at `address.slug`.
|
|
1118
1110
|
// Any other slug of the type has a link of its own (#10805 D5).
|
|
1119
1111
|
const indexTypes = new Set(parseFrontmatter === undefined
|
|
1120
1112
|
? []
|
|
@@ -1149,6 +1141,12 @@ export async function importMdx(opts) {
|
|
|
1149
1141
|
// first in processing order wins and the rest fail. Two pages of different
|
|
1150
1142
|
// types may share a slug (#10268 D7): the store addresses by type too.
|
|
1151
1143
|
const addresses = new Map();
|
|
1144
|
+
// #11793 D7 (Q7), #11843 D6 — an older site's packages cannot say which
|
|
1145
|
+
// types are laid out in sections, so its pages without sections are sent
|
|
1146
|
+
// as their body, and the hub refuses one of a sections type.
|
|
1147
|
+
if (opts.adapters.laidOutInSections === undefined) {
|
|
1148
|
+
onLine("import-mdx: the site's packages cannot say which page types are laid out in sections; pages without sections are sent as their body; the hub refuses one of a type laid out in sections");
|
|
1149
|
+
}
|
|
1152
1150
|
let halt;
|
|
1153
1151
|
let publishRefused;
|
|
1154
1152
|
let live = 0;
|
|
@@ -1209,29 +1207,31 @@ export async function importMdx(opts) {
|
|
|
1209
1207
|
fail(converted.reason);
|
|
1210
1208
|
continue;
|
|
1211
1209
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1210
|
+
const authored = source.frontmatter["sections"];
|
|
1211
|
+
const hasSections = Array.isArray(authored) && authored.length > 0;
|
|
1212
|
+
const sectionsRule = opts.adapters.laidOutInSections?.(page.type);
|
|
1213
|
+
// #11843 D6, D10 — an editorial page's words, and a document's, are its
|
|
1214
|
+
// body: a file of either with sections is never stored as markers with no layout.
|
|
1215
|
+
if (hasSections && (page.type === DOCUMENT_TYPE || sectionsRule === false)) {
|
|
1216
|
+
fail(page.type === DOCUMENT_TYPE
|
|
1217
|
+
? "sections: a Document's words are its body (save_document takes { body }), and this file has sections; move their words into the body"
|
|
1218
|
+
: `sections: a ${page.type} page's words are its body, and this file has sections; move their words into the body`);
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
// #11793 D7 — a page laid out in sections is never stored with no layout,
|
|
1222
|
+
// and (#11843) a file's sections are never dropped: each fails here,
|
|
1223
|
+
// naming why, before anything is sent for it.
|
|
1224
|
+
if (converted.layout === undefined && (hasSections || sectionsRule === true)) {
|
|
1225
|
+
fail(hasSections
|
|
1226
|
+
? `sections: the site's ${VALIDATION_PACKAGE} has no words codec — update its dependencies and re-run`
|
|
1227
|
+
: `sections: a ${page.type} page is laid out in sections, and this file has none — move its words into frontmatter sections`);
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1225
1230
|
if (converted.notCarried.length > 0) {
|
|
1226
1231
|
onLine(`${outcomePath(page)}: inline HTML not carried — ${converted.notCarried.join(", ")} (the layout holds no HTML; their text is kept)`);
|
|
1227
1232
|
}
|
|
1228
|
-
if (converted.layout === undefined &&
|
|
1229
|
-
Array.isArray(source.frontmatter["sections"]) &&
|
|
1230
|
-
source.frontmatter["sections"].length > 0) {
|
|
1231
|
-
onLine(`${page.path}: keeps its words in sections — the site's ${VALIDATION_PACKAGE} has no words codec; update its dependencies and re-run`);
|
|
1232
|
-
}
|
|
1233
1233
|
// #10804 D5 — a layout the hub would refuse fails here, in a dry run and
|
|
1234
|
-
// under --apply alike, before
|
|
1234
|
+
// under --apply alike, before anything is saved.
|
|
1235
1235
|
const refusal = converted.layout === undefined
|
|
1236
1236
|
? undefined
|
|
1237
1237
|
: layoutRefusal(converted.layout);
|
|
@@ -1239,34 +1239,25 @@ export async function importMdx(opts) {
|
|
|
1239
1239
|
fail(`layout: ${refusal}`);
|
|
1240
1240
|
continue;
|
|
1241
1241
|
}
|
|
1242
|
-
const result = await writePage(t, page, defaultLocale, converted
|
|
1242
|
+
const result = await writePage(t, page, defaultLocale, converted, rules?.publicPageTags);
|
|
1243
1243
|
halt = result.halt;
|
|
1244
|
-
// #10898
|
|
1245
|
-
//
|
|
1246
|
-
|
|
1247
|
-
if (opts.liveSource === true &&
|
|
1248
|
-
result.sent === true &&
|
|
1249
|
-
result.stored !== null &&
|
|
1250
|
-
typeof result.stored === "object" &&
|
|
1251
|
-
!Object.hasOwn(result.stored, LIVE_SOURCE_KEY)) {
|
|
1252
|
-
onLine(`${outcomePath(page)}: not kept by the hub: ${LIVE_SOURCE_KEY} (the hub predates the live-source mark; update it and re-run)`);
|
|
1253
|
-
}
|
|
1254
|
-
// #10898 D6 — what the hub's publish gate will answer for these words.
|
|
1255
|
-
const check = opts.liveSource === true ? opts.adapters.publishCheck : undefined;
|
|
1244
|
+
// #10898 D6, #11843 D7 — what the hub's publish gate will answer for the
|
|
1245
|
+
// page as it is now stored, with no live-source mark.
|
|
1246
|
+
const check = opts.adapters.publishCheck;
|
|
1256
1247
|
if (check !== undefined && !("reason" in result.outcome)) {
|
|
1257
|
-
const verdict = check(page.type, converted.
|
|
1248
|
+
const verdict = check(page.type, { ...converted.fields, type: page.type, slug: page.slug, body: converted.body }, converted.layout);
|
|
1258
1249
|
if (verdict !== undefined)
|
|
1259
1250
|
result.outcome = { ...result.outcome, publishVerdict: verdict };
|
|
1260
1251
|
}
|
|
1261
1252
|
// #10806 D4 — an older hub strips what it has no member for; say so.
|
|
1262
|
-
// An answer that carries no
|
|
1253
|
+
// An answer that carries no fields says nothing about what was kept.
|
|
1263
1254
|
const dropped = rules === undefined ||
|
|
1264
1255
|
page.root !== "editorial" ||
|
|
1265
1256
|
"reason" in result.outcome ||
|
|
1266
1257
|
result.stored === null ||
|
|
1267
1258
|
typeof result.stored !== "object"
|
|
1268
1259
|
? []
|
|
1269
|
-
: notKept(converted.
|
|
1260
|
+
: notKept({ ...converted.fields, type: page.type }, result.stored, rules);
|
|
1270
1261
|
if (dropped.length > 0) {
|
|
1271
1262
|
onLine(`${page.path}: not kept by the hub: ${dropped.join(", ")} (the hub predates site fields; update it and re-run)`);
|
|
1272
1263
|
}
|
|
@@ -1314,12 +1305,12 @@ export async function importMdx(opts) {
|
|
|
1314
1305
|
};
|
|
1315
1306
|
}
|
|
1316
1307
|
/**
|
|
1317
|
-
* The hub's publish gate over a
|
|
1318
|
-
*
|
|
1319
|
-
*
|
|
1320
|
-
*
|
|
1321
|
-
*
|
|
1322
|
-
* so only the rest block.
|
|
1308
|
+
* The hub's publish gate over a page, as the site's contract reads it: the
|
|
1309
|
+
* page's words checked against its type's template and the structure
|
|
1310
|
+
* publish's repair would build — the layout when the page converts, an
|
|
1311
|
+
* editorial template's frontmatter quartet, else none. No live-source split
|
|
1312
|
+
* is applied: no save keeps the mark (#11843 D7). Publish repairs every
|
|
1313
|
+
* `script` finding, so only the rest block.
|
|
1323
1314
|
*/
|
|
1324
1315
|
export function publishCheckOf(members) {
|
|
1325
1316
|
return (type, content, layout) => {
|
|
@@ -1337,19 +1328,34 @@ export function publishCheckOf(members) {
|
|
|
1337
1328
|
frontmatter: Object.fromEntries(EDITORIAL_STRUCTURE_FIELDS.filter((field) => content[field] !== undefined).map((field) => [field, content[field]])),
|
|
1338
1329
|
}
|
|
1339
1330
|
: null);
|
|
1340
|
-
const report = members.
|
|
1331
|
+
const report = members.checkPage({
|
|
1341
1332
|
template,
|
|
1342
1333
|
title: text("title"),
|
|
1343
1334
|
description: text("description"),
|
|
1344
1335
|
slug: text("slug"),
|
|
1345
1336
|
body: text("body"),
|
|
1346
|
-
}, structure)
|
|
1337
|
+
}, structure);
|
|
1347
1338
|
const blocking = report.issues.filter((issue) => issue.fixer !== "script");
|
|
1348
1339
|
return blocking.length === 0
|
|
1349
1340
|
? { publishable: true, advisory: report.advisory ?? [] }
|
|
1350
1341
|
: { publishable: false, status: report.status, blocking };
|
|
1351
1342
|
};
|
|
1352
1343
|
}
|
|
1344
|
+
/**
|
|
1345
|
+
* #11793 D7 — the rule `laidOutInSections`: a type is laid out in sections
|
|
1346
|
+
* when the site's registry names it and its template's kind is `sections`. A
|
|
1347
|
+
* registry entry whose template the site's validation package lacks answers
|
|
1348
|
+
* false, never throws, so mismatched site packages never stop the run
|
|
1349
|
+
* (SEC-11793-06).
|
|
1350
|
+
*/
|
|
1351
|
+
export function sectionsRuleOf(registry, templates) {
|
|
1352
|
+
return (type) => {
|
|
1353
|
+
const template = registry.find((entry) => entry?.key === type)?.template;
|
|
1354
|
+
return (typeof template === "string" &&
|
|
1355
|
+
Object.hasOwn(templates, template) &&
|
|
1356
|
+
templates[template]?.kind === "sections");
|
|
1357
|
+
};
|
|
1358
|
+
}
|
|
1353
1359
|
// ── The site's own adapter (D1) ─────────────────────────────────────────────
|
|
1354
1360
|
/** Whether a `node_modules` at or above `dir` holds the adapter package. */
|
|
1355
1361
|
function installedAbove(dir) {
|
|
@@ -1418,8 +1424,8 @@ export async function loadSiteMdxAdapter(siteRoot) {
|
|
|
1418
1424
|
// Not resolvable from the adapter: no parser.
|
|
1419
1425
|
}
|
|
1420
1426
|
// #10898 D6 — the site's own page-type registry, beside its contract; a
|
|
1421
|
-
// validation package
|
|
1422
|
-
//
|
|
1427
|
+
// validation package with no content check, or no registry, leaves the dry
|
|
1428
|
+
// run's publish verdict unchecked, and the run says so.
|
|
1423
1429
|
let registry;
|
|
1424
1430
|
try {
|
|
1425
1431
|
const path = createRequire(entry).resolve(PAGE_TYPES_PACKAGE);
|
|
@@ -1428,7 +1434,7 @@ export async function loadSiteMdxAdapter(siteRoot) {
|
|
|
1428
1434
|
catch {
|
|
1429
1435
|
// Not resolvable from the adapter: no registry.
|
|
1430
1436
|
}
|
|
1431
|
-
const { checkPage,
|
|
1437
|
+
const { checkPage, PAGE_TEMPLATES: templates } = validation;
|
|
1432
1438
|
return {
|
|
1433
1439
|
...mod,
|
|
1434
1440
|
...(typeof codec === "function" && {
|
|
@@ -1446,17 +1452,20 @@ export async function loadSiteMdxAdapter(siteRoot) {
|
|
|
1446
1452
|
},
|
|
1447
1453
|
}),
|
|
1448
1454
|
...(typeof checkPage === "function" &&
|
|
1449
|
-
typeof liveSourceReport === "function" &&
|
|
1450
1455
|
templates !== null &&
|
|
1451
1456
|
typeof templates === "object" &&
|
|
1452
1457
|
Array.isArray(registry) && {
|
|
1453
1458
|
publishCheck: publishCheckOf({
|
|
1454
1459
|
checkPage: checkPage,
|
|
1455
|
-
liveSourceReport: liveSourceReport,
|
|
1456
1460
|
templates: templates,
|
|
1457
1461
|
registry: registry,
|
|
1458
1462
|
}),
|
|
1459
1463
|
}),
|
|
1464
|
+
...(templates !== null &&
|
|
1465
|
+
typeof templates === "object" &&
|
|
1466
|
+
Array.isArray(registry) && {
|
|
1467
|
+
laidOutInSections: sectionsRuleOf(registry, templates),
|
|
1468
|
+
}),
|
|
1460
1469
|
...(typeof matter === "function" && {
|
|
1461
1470
|
parseFrontmatter: (raw) => {
|
|
1462
1471
|
const { data, content } = matter(raw);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ComparisonPage } from "./render-comparison.js";
|
|
2
|
+
/**
|
|
3
|
+
* A page that passes every call through to `page` and stores, for each of
|
|
4
|
+
* `paths` on `origin` at each viewport, what it answered. It writes nowhere
|
|
5
|
+
* but under `dir`, and renders nothing it is not asked to.
|
|
6
|
+
*/
|
|
7
|
+
export declare function recordingPage(page: ComparisonPage, o: {
|
|
8
|
+
dir: string;
|
|
9
|
+
origin: string;
|
|
10
|
+
paths: readonly string[];
|
|
11
|
+
}): ComparisonPage;
|
|
12
|
+
/**
|
|
13
|
+
* A page that answers from a capture under `dir` and never navigates. A path
|
|
14
|
+
* the capture does not list, or a capture missing its render or its
|
|
15
|
+
* screenshot, fails that render, so the comparison fails rather than
|
|
16
|
+
* comparing against nothing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function replayPage(o: {
|
|
19
|
+
dir: string;
|
|
20
|
+
origin: string;
|
|
21
|
+
paths: readonly string[];
|
|
22
|
+
}): ComparisonPage;
|