@taprootio/site-authoring 0.55.0 → 0.59.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 +91 -22
- package/package.json +2 -2
- package/src/api.js +90 -17
- package/src/authors-contract.js +71 -3
- package/src/block-flow.js +4 -2
- package/src/changelog.json +104 -0
- package/src/chrome-additions.js +106 -0
- package/src/chrome-features.js +43 -10
- package/src/chrome-input.js +137 -30
- package/src/chrome-report.js +4 -2
- package/src/cli.js +144 -38
- package/src/constants.js +1 -0
- package/src/content/button-styles.js +27 -0
- package/src/content/components.js +76 -10
- package/src/content/free-form-section-registry.json +9 -0
- package/src/content/free-form-sections.js +55 -16
- package/src/content/markdown.js +133 -56
- package/src/content/media-presentation.js +37 -0
- package/src/content/tiptap-prosemirror.ts +26 -10
- package/src/credentials.js +2 -1
- package/src/delivery-check.js +10 -2
- package/src/font-catalog.js +9 -6
- package/src/footer-content.js +1 -1
- package/src/footer-contract.js +3 -0
- package/src/footer-draft-hash.js +1 -0
- package/src/heading-outline.js +94 -6
- package/src/image-description-contract.js +5 -3
- package/src/image-description-write.js +26 -0
- package/src/index.js +1 -0
- package/src/output.js +2 -1
- package/src/page-metadata.js +15 -13
- package/src/page-structure-checks.js +14 -25
- package/src/placed-image-ids.js +42 -17
- package/src/presentation-reference.js +63 -18
- package/src/problems.js +147 -4
- package/src/reference-help.js +122 -60
- package/src/site-check-findings.js +2 -3
- package/src/site-check-rules.json +0 -1
- package/src/site-health-findings.js +7 -9
- package/src/site-health-image-checks.js +4 -1
- package/src/site-health-precheck.js +23 -6
- package/src/site-navigation-groups.js +16 -0
- package/src/status-warning-paints.js +175 -0
- package/src/template-token-reach.json +13 -18
- package/src/theme-proposals.js +143 -55
- package/src/theme-resolve.js +14 -1
- package/src/theme-validation.js +70 -38
- package/src/token-reach.js +20 -0
- package/src/typed-page-reference.js +25 -3
- package/src/typed-pages.js +73 -14
- package/src/verbs/authors.js +198 -33
- package/src/verbs/changelog.js +23 -2
- package/src/verbs/delivery-check.js +43 -9
- package/src/verbs/index.js +4 -2
- package/src/verbs/media-images.js +4 -4
- package/src/verbs/pages-push.js +138 -67
- package/src/verbs/plan.js +28 -20
- package/src/verbs/pull.js +226 -26
- package/src/verbs/theme-push.js +59 -15
- package/src/verbs/theme-resolve.js +109 -11
- package/src/verbs/validate.js +97 -16
- package/src/workspace-check.js +4 -4
- package/src/workspace-context-usage.js +180 -0
- package/src/workspace.js +48 -1
- package/test/fixtures/default-site-theme.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { LIMITS } from "./constants.js";
|
|
2
|
+
import { usedInOf, withoutUsedIn } from "./status-warning-paints.js";
|
|
3
|
+
|
|
4
|
+
// The chrome extras may use at most this much of a result, whatever room is left.
|
|
5
|
+
const MAXIMUM_ADDITION_BYTES = 8 * 1024;
|
|
6
|
+
// Room kept for the envelope a verb wraps around its fields.
|
|
7
|
+
const ENVELOPE_RESERVE_BYTES = 2048;
|
|
8
|
+
|
|
9
|
+
const bytes = (value) => Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
10
|
+
|
|
11
|
+
/** The skipped-link report cut to `room` bytes: the count stays, the list shrinks, and `truncated` says so. */
|
|
12
|
+
export function boundSkippedLinks(skipped, room = MAXIMUM_ADDITION_BYTES) {
|
|
13
|
+
if (bytes(skipped) <= room) return skipped;
|
|
14
|
+
const items = [];
|
|
15
|
+
let used = bytes({ ...skipped, items: [], truncated: true });
|
|
16
|
+
// The report did not fit, so at least one row goes: `truncated: true` is shorter than a `false` it replaces.
|
|
17
|
+
for (const item of skipped.items.slice(0, -1)) {
|
|
18
|
+
const size = bytes(item) + (items.length === 0 ? 0 : 1);
|
|
19
|
+
if (used + size > room) break;
|
|
20
|
+
items.push(item);
|
|
21
|
+
used += size;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
...skipped,
|
|
25
|
+
items,
|
|
26
|
+
...(items.length < skipped.items.length || skipped.truncated ? { truncated: true } : {}),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Adds the context-usage fields (TR01426) to a finished, already fitted result from the bytes it has left: each
|
|
32
|
+
* warning's `usedIn` list and `contextUsageSkipped`. They never displace a field that is already in the result.
|
|
33
|
+
* When they do not all fit, `usedIn` lists are shed first, last warning first, and then the skipped rows are cut
|
|
34
|
+
* to the total; a summary that cannot fit is left out of the JSON.
|
|
35
|
+
*/
|
|
36
|
+
export function addUsageFields(result, { usedIn = new Map(), skipped } = {}) {
|
|
37
|
+
const records = result.statusWarningPaints;
|
|
38
|
+
const wanted = records === undefined ? [] : [...usedIn].filter(([warning]) => records.some((record) => record.warning === warning));
|
|
39
|
+
if (wanted.length === 0 && skipped === undefined) return result;
|
|
40
|
+
// The result is already wrapped, so what it measures is what is left.
|
|
41
|
+
const room = LIMITS.githubOutputBytes - bytes(result);
|
|
42
|
+
// Adding a list to a record costs its comma and `"usedIn":[...]`, which is the object's size less its two braces.
|
|
43
|
+
const listCost = (rows) => rows.reduce((sum, [, list]) => sum + bytes({ usedIn: list }) - 1, 0);
|
|
44
|
+
// What the field adds beyond its value: the comma, the quoted key and the colon.
|
|
45
|
+
const keyBytes = bytes({ contextUsageSkipped: 0 }) - 3 + 1;
|
|
46
|
+
const skippedCost = skipped === undefined ? 0 : keyBytes + bytes(skipped);
|
|
47
|
+
const kept = [...wanted];
|
|
48
|
+
while (kept.length > 0 && listCost(kept) + skippedCost > room) kept.pop();
|
|
49
|
+
let reported = skipped;
|
|
50
|
+
if (skipped !== undefined && listCost(kept) + skippedCost > room) {
|
|
51
|
+
const available = room - listCost(kept);
|
|
52
|
+
reported = boundSkippedLinks(skipped, available - keyBytes);
|
|
53
|
+
if (keyBytes + bytes(reported) > available) reported = undefined;
|
|
54
|
+
}
|
|
55
|
+
const lists = new Map(kept);
|
|
56
|
+
const seen = new Set();
|
|
57
|
+
return {
|
|
58
|
+
...result,
|
|
59
|
+
...(records === undefined ? {} : {
|
|
60
|
+
statusWarningPaints: records.map((record) => {
|
|
61
|
+
if (seen.has(record.warning)) return record;
|
|
62
|
+
seen.add(record.warning);
|
|
63
|
+
return lists.has(record.warning) ? { ...record, usedIn: lists.get(record.warning) } : record;
|
|
64
|
+
}),
|
|
65
|
+
}),
|
|
66
|
+
...(reported === undefined ? {} : { contextUsageSkipped: reported }),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Fits the skipped-link report and the status-paint records into what the rest of a result leaves, so a large
|
|
72
|
+
* valid workspace never turns into output.too_large because of them. Counts stay; the skipped list shrinks with
|
|
73
|
+
* `truncated: true`, and whole paint groups are dropped and counted in `statusWarningPaintsOmitted`.
|
|
74
|
+
*/
|
|
75
|
+
export function fitChromeAdditions(fields) {
|
|
76
|
+
const { skippedNavigationLinks, statusWarningPaints: listedPaints, statusWarningPaintsOmitted = 0, contextUsageSkipped, ...rest } = fields;
|
|
77
|
+
if (skippedNavigationLinks === undefined && listedPaints === undefined && contextUsageSkipped === undefined) return fields;
|
|
78
|
+
// The usage fields come last, from what the existing records leave, so they never change what those keep.
|
|
79
|
+
const usedIn = usedInOf(listedPaints);
|
|
80
|
+
const statusWarningPaints = withoutUsedIn(listedPaints);
|
|
81
|
+
let room = Math.min(MAXIMUM_ADDITION_BYTES, LIMITS.githubOutputBytes - bytes(rest) - ENVELOPE_RESERVE_BYTES);
|
|
82
|
+
const fitted = { ...rest };
|
|
83
|
+
if (statusWarningPaints !== undefined) {
|
|
84
|
+
const kept = [];
|
|
85
|
+
const groups = [];
|
|
86
|
+
for (const record of statusWarningPaints) {
|
|
87
|
+
if (groups.at(-1)?.[0].warning === record.warning) groups.at(-1).push(record);
|
|
88
|
+
else groups.push([record]);
|
|
89
|
+
}
|
|
90
|
+
let used = 0;
|
|
91
|
+
let omitted = statusWarningPaintsOmitted;
|
|
92
|
+
for (const group of groups) {
|
|
93
|
+
const size = bytes(group);
|
|
94
|
+
if (used + size > room / 2) omitted += 1;
|
|
95
|
+
else {
|
|
96
|
+
kept.push(...group);
|
|
97
|
+
used += size;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
room -= used;
|
|
101
|
+
if (kept.length > 0) fitted.statusWarningPaints = kept;
|
|
102
|
+
if (omitted > 0) fitted.statusWarningPaintsOmitted = omitted;
|
|
103
|
+
}
|
|
104
|
+
if (skippedNavigationLinks !== undefined) fitted.skippedNavigationLinks = boundSkippedLinks(skippedNavigationLinks, room);
|
|
105
|
+
return addUsageFields(fitted, { usedIn, skipped: contextUsageSkipped });
|
|
106
|
+
}
|
package/src/chrome-features.js
CHANGED
|
@@ -6,7 +6,7 @@ import { resolveHeaderChromePresentation } from "./header-presentation.js";
|
|
|
6
6
|
import { describeHeaderNavigationItem, MAX_NAVIGATION_DEPTH, prepareHeaderNavigation, SITE_NAVIGATION_KINDS, } from "./site-navigation-groups.js";
|
|
7
7
|
import { isRenderableSocialLink } from "./social-link-url.js";
|
|
8
8
|
/** Flags describe reachable paint across pages, viewport sizes and header scroll positions. */
|
|
9
|
-
export function chromeFeatures({ headerSettings, footerSettings, navItems, footerPagePaths, logoPairs, searchEnabled, hasIconSprite, nameReportEnabled, }) {
|
|
9
|
+
export function chromeFeatures({ headerSettings, footerSettings, navItems, footerPagePaths, logoPairs, searchEnabled, hasIconSprite, nameReportEnabled, themes, }) {
|
|
10
10
|
const features = {};
|
|
11
11
|
if (headerSettings) {
|
|
12
12
|
const header = resolveHeaderChromePresentation(headerSettings);
|
|
@@ -34,7 +34,7 @@ export function chromeFeatures({ headerSettings, footerSettings, navItems, foote
|
|
|
34
34
|
features.header = schemeFeatures(flags, navigation, header.showBrandText ? header.brandText : undefined, {
|
|
35
35
|
light: hasLogo,
|
|
36
36
|
dark: hasLogo,
|
|
37
|
-
});
|
|
37
|
+
}, themeFlags(themes, headerSettings.context));
|
|
38
38
|
}
|
|
39
39
|
if (footerSettings?.enabled === true) {
|
|
40
40
|
const flags = footerContentFlags(footerSettings, footerPagePaths);
|
|
@@ -47,10 +47,11 @@ export function chromeFeatures({ headerSettings, footerSettings, navItems, foote
|
|
|
47
47
|
// A one-scheme footer override must not become the opposite scheme's logo.
|
|
48
48
|
light: showBrand && Boolean(logoPairs?.footer?.light.url),
|
|
49
49
|
dark: showBrand && Boolean(logoPairs?.footer?.dark.url),
|
|
50
|
-
});
|
|
50
|
+
}, themeFlags(themes, footerSettings.context));
|
|
51
51
|
}
|
|
52
52
|
else if (nameReportEnabled === true) {
|
|
53
|
-
|
|
53
|
+
// The standalone action sits outside any footer context, so only root properties apply.
|
|
54
|
+
features.footer = schemeFeatures(["footerActionButton:standalone"], [], undefined, { light: false, dark: false }, themeFlags(themes, undefined));
|
|
54
55
|
}
|
|
55
56
|
return features;
|
|
56
57
|
}
|
|
@@ -62,14 +63,46 @@ export function standaloneFooterActionEntries(entries) {
|
|
|
62
63
|
background: entry.kind === "ring" ? "background" : entry.background,
|
|
63
64
|
}));
|
|
64
65
|
}
|
|
65
|
-
function schemeFeatures(flags, navigation, brandText, logos) {
|
|
66
|
+
function schemeFeatures(flags, navigation, brandText, logos, themed = { light: [], dark: [] }) {
|
|
66
67
|
const paintedText = hasText(brandText) ? ["brandText"] : [];
|
|
67
68
|
// Nonbreaking whitespace has no ink but still gives the brand link a focusable box.
|
|
68
|
-
const forScheme = (hasLogo) =>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
const forScheme = (hasLogo, themeEnabled) => {
|
|
70
|
+
// A filled heading is measured on its fill instead of layer 2, so the fill flag replaces the plain one.
|
|
71
|
+
const base = themeEnabled.includes("footerHeadingFill") ? flags.filter(flag => flag !== "footerHeadings") : flags;
|
|
72
|
+
const filled = themeEnabled.includes("footerHeadingFill") && flags.includes("footerHeadings");
|
|
73
|
+
return {
|
|
74
|
+
flags: [
|
|
75
|
+
...base,
|
|
76
|
+
...themeEnabled.filter(flag => flag !== "footerHeadingFill" || filled),
|
|
77
|
+
...paintedText,
|
|
78
|
+
...(brandText || hasLogo ? ["brandLink"] : []),
|
|
79
|
+
],
|
|
80
|
+
navigation,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
return { light: forScheme(logos.light, themed.light), dark: forScheme(logos.dark, themed.dark) };
|
|
84
|
+
}
|
|
85
|
+
const THEME_ENABLED_FLAGS = [
|
|
86
|
+
["buttonFocusOutline", "--esp-button-focus-color"],
|
|
87
|
+
["footerHeadingFill", "--esp-footer-heading-background"],
|
|
88
|
+
];
|
|
89
|
+
/** A color property is authored as a token or color string, or as a `{ source, lightness }` object. */
|
|
90
|
+
function isAuthoredColor(value) {
|
|
91
|
+
if (typeof value === "string")
|
|
92
|
+
return value.trim() !== "";
|
|
93
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
94
|
+
return false;
|
|
95
|
+
const { source } = value;
|
|
96
|
+
return typeof source === "string" && source.trim() !== "";
|
|
97
|
+
}
|
|
98
|
+
/** Espalier asks the consumer to set these flags when the theme authors the property, in the surface's own context. */
|
|
99
|
+
function themeFlags(themes, context) {
|
|
100
|
+
const forScheme = (theme) => {
|
|
101
|
+
const properties = { ...theme?.componentProperties, ...(context ? theme?.contexts?.[context]?.componentProperties : undefined) };
|
|
102
|
+
return THEME_ENABLED_FLAGS.filter(([, name]) => isAuthoredColor(properties[name]))
|
|
103
|
+
.map(([flag]) => flag);
|
|
104
|
+
};
|
|
105
|
+
return { light: forScheme(themes?.light), dark: forScheme(themes?.dark) };
|
|
73
106
|
}
|
|
74
107
|
// The slots match NavItemKind in Sites.proto.
|
|
75
108
|
const NAVIGATION_KIND_NAMES = ["", SITE_NAVIGATION_KINDS.page, SITE_NAVIGATION_KINDS.externalUrl, SITE_NAVIGATION_KINDS.groupHeader];
|
package/src/chrome-input.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NAV_ITEM_KIND_EXTERNAL_URL,
|
|
3
|
+
NAV_ITEM_KIND_GROUP_HEADER,
|
|
4
|
+
NAV_ITEM_KIND_PAGE,
|
|
5
|
+
PAGE_STATUS_APPROVED,
|
|
6
|
+
PAGE_STATUS_PUBLISHED,
|
|
7
|
+
} from "./api.js";
|
|
2
8
|
import { resolveBrandColors, resolveBrandColorSourceFields, resolveBrandColorToken, resolveFooterBrandColors } from "./brand-color.js";
|
|
3
9
|
import { chromeFeatures } from "./chrome-features.js";
|
|
4
|
-
import { isCanonicalUuid } from "./errors.js";
|
|
10
|
+
import { isCanonicalUuid, sanitizeDiagnostic } from "./errors.js";
|
|
5
11
|
import { validateFooterDocument } from "./footer-contract.js";
|
|
6
12
|
import { resolveFooterLogoPairs } from "./footer-branding.js";
|
|
7
13
|
import { resolveHeaderLogoPairs } from "./header-presentation.js";
|
|
8
14
|
import { logoInputsFromSettings } from "./logo-inputs.js";
|
|
15
|
+
import { resolveNavigationItems } from "./site-navigation-groups.js";
|
|
9
16
|
import { sharedDeclaredThemeContextNames } from "./theme-contexts.js";
|
|
10
17
|
import { validateNavigationWorkspaceDocument } from "./verbs/nav-push.js";
|
|
11
18
|
import { NAVIGATION_FILE_NAME, normalizePagePath, readWorkspaceJson, WORKSPACE_LIMITS } from "./workspace.js";
|
|
@@ -13,8 +20,20 @@ import { NAVIGATION_FILE_NAME, normalizePagePath, readWorkspaceJson, WORKSPACE_L
|
|
|
13
20
|
export const CHROME_NAVIGATION_UNAVAILABLE_MESSAGE =
|
|
14
21
|
"Navigation contrast was not checked because navigation information was unavailable.";
|
|
15
22
|
|
|
23
|
+
// Staging links approved pages as well as published ones, so the check does too.
|
|
16
24
|
export const CHROME_OFFLINE_PAGE_LIMITATION =
|
|
17
|
-
"navigation or footer page-link contrast for destinations
|
|
25
|
+
"navigation or footer page-link contrast for destinations the page inventory cannot resolve to a path "
|
|
26
|
+
+ "(approved and published pages count as links; draft pages are reported in skippedNavigationLinks)";
|
|
27
|
+
|
|
28
|
+
export const SKIPPED_LINK_REASONS = Object.freeze(["draft_page", "missing_page", "unknown_path"]);
|
|
29
|
+
const MAXIMUM_SKIPPED_ITEMS = 50;
|
|
30
|
+
const MAXIMUM_SKIPPED_LABEL = 80;
|
|
31
|
+
const LINKED_PAGE_STATUSES = new Set([PAGE_STATUS_PUBLISHED, PAGE_STATUS_APPROVED]);
|
|
32
|
+
const NAVIGATION_KINDS = {
|
|
33
|
+
page: NAV_ITEM_KIND_PAGE,
|
|
34
|
+
externalUrl: NAV_ITEM_KIND_EXTERNAL_URL,
|
|
35
|
+
groupHeader: NAV_ITEM_KIND_GROUP_HEADER,
|
|
36
|
+
};
|
|
18
37
|
|
|
19
38
|
export const CHROME_REPORT_NAME_RULE = "theme.chrome_report_name";
|
|
20
39
|
|
|
@@ -30,40 +49,127 @@ function isSettingsOnly(resources) {
|
|
|
30
49
|
/** Take optional workspace evidence while the caller still owns its read snapshot. */
|
|
31
50
|
export async function captureChromeResources(resources) {
|
|
32
51
|
if (resources.workspaceDir === undefined || isSettingsOnly(resources) || Object.hasOwn(resources, "navigation")) return resources;
|
|
33
|
-
const {
|
|
52
|
+
const { siteId, workspaceDir } = resources;
|
|
34
53
|
try {
|
|
35
54
|
const parsed = await readWorkspaceJson(workspaceDir, NAVIGATION_FILE_NAME, WORKSPACE_LIMITS.navigationBytes);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
resourceIds: knownPageResourceIds,
|
|
39
|
-
};
|
|
40
|
-
const navigation = validateNavigationWorkspaceDocument(parsed, siteId, knownPages);
|
|
55
|
+
// Shape only: a page target the manifest lacks is reported as a skipped link, not as missing navigation.
|
|
56
|
+
const navigation = validateNavigationWorkspaceDocument(parsed, siteId);
|
|
41
57
|
return { ...resources, navigation };
|
|
42
58
|
} catch {
|
|
43
59
|
return { ...resources, navigation: undefined };
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The entries a published site links: a canonical page and resource id and a linked status. `path` is the
|
|
65
|
+
* normalized path without slashes ("" for the home page). Chrome checks and delivery routes both read this list
|
|
66
|
+
* (TR01420), so a never-saved entry is neither a link target nor a route to fetch.
|
|
67
|
+
*/
|
|
68
|
+
export function linkedPageEntries(pages) {
|
|
69
|
+
const linked = [];
|
|
70
|
+
for (const page of pages ?? []) {
|
|
71
|
+
if (!isCanonicalUuid(page?.resourceId) || !isCanonicalUuid(page?.pageId) || !LINKED_PAGE_STATUSES.has(page.status)) continue;
|
|
72
|
+
const path = normalizePagePath(page.path);
|
|
73
|
+
if (path !== undefined) linked.push({ resourceId: page.resourceId, path, templateType: page.templateType });
|
|
74
|
+
}
|
|
75
|
+
return linked;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Saved entries a published site does not link: a canonical page and resource id, but a status other than published
|
|
80
|
+
* or approved (a draft or other unapproved page). Entries with no saved page id are not pages yet and are left out.
|
|
81
|
+
*/
|
|
82
|
+
export function unlinkedSavedPageEntries(pages) {
|
|
83
|
+
const unlinked = [];
|
|
84
|
+
for (const page of pages ?? []) {
|
|
85
|
+
if (!isCanonicalUuid(page?.resourceId) || !isCanonicalUuid(page?.pageId) || LINKED_PAGE_STATUSES.has(page.status)) continue;
|
|
86
|
+
const path = normalizePagePath(page.path);
|
|
87
|
+
if (path !== undefined) unlinked.push({ path: sanitizeDiagnostic(path === "" ? "/" : `/${path}/`, "(unprintable path)"), status: page.status });
|
|
88
|
+
}
|
|
89
|
+
return unlinked;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* What the pages known to the caller can link to. `pages` are manifest entries or site summaries;
|
|
94
|
+
* `complete` says no page is missing from the list. `knownPaths` covers every entry, drafts included,
|
|
95
|
+
* so a skipped link can say where its page lives.
|
|
96
|
+
*/
|
|
97
|
+
export function pageLinkInventory(pages, complete) {
|
|
98
|
+
const statuses = new Map();
|
|
99
|
+
const knownPaths = new Map();
|
|
100
|
+
for (const page of pages ?? []) {
|
|
101
|
+
if (!isCanonicalUuid(page?.resourceId)) continue;
|
|
51
102
|
const path = normalizePagePath(page.path);
|
|
52
|
-
if (path !== undefined)
|
|
103
|
+
if (path !== undefined) knownPaths.set(page.resourceId, `/${path}`);
|
|
104
|
+
// A pending entry that kept a resourceId after losing its pageId is not a page the site has.
|
|
105
|
+
if (isCanonicalUuid(page.pageId)) statuses.set(page.resourceId, page.status);
|
|
106
|
+
}
|
|
107
|
+
const paths = new Map(linkedPageEntries(pages).map(({ resourceId, path }) => [resourceId, `/${path}`]));
|
|
108
|
+
return { paths, statuses, knownPaths, complete };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function skippedReason(inventory, resourceId) {
|
|
112
|
+
const status = inventory.statuses.get(resourceId);
|
|
113
|
+
const [draft, missing, unknown] = SKIPPED_LINK_REASONS;
|
|
114
|
+
if (status === undefined) return inventory.complete ? missing : unknown;
|
|
115
|
+
return LINKED_PAGE_STATUSES.has(status) ? unknown : draft;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function* navigationPageItems(items) {
|
|
119
|
+
for (const item of items ?? []) {
|
|
120
|
+
if (item.kind === NAV_ITEM_KIND_PAGE) yield { label: item.title, resourceId: item.resourceId, url: item.url };
|
|
121
|
+
yield* navigationPageItems(item.children);
|
|
53
122
|
}
|
|
54
|
-
return paths;
|
|
55
123
|
}
|
|
56
124
|
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
125
|
+
function* footerPageTargets(node) {
|
|
126
|
+
if (node === null || typeof node !== "object") return;
|
|
127
|
+
if (typeof node.pageResourceId === "string") yield { label: node.label, resourceId: node.pageResourceId };
|
|
128
|
+
for (const value of Object.values(node)) yield* footerPageTargets(value);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** A path safe to print and to put in a result: control and bidirectional characters removed, null when none is left. */
|
|
132
|
+
function sanitizedPath(path) {
|
|
133
|
+
return typeof path === "string" ? sanitizeDiagnostic(path, "") || null : null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The page links the check could not resolve, with the full count and a bounded list. */
|
|
137
|
+
function skippedLinks(inventory, navItems, footerSettings) {
|
|
138
|
+
const skipped = [];
|
|
139
|
+
const note = ({ label, resourceId }, location) => skipped.push({
|
|
140
|
+
label: [...sanitizeDiagnostic(String(label || ""), "(unlabeled link)")].slice(0, MAXIMUM_SKIPPED_LABEL).join(""),
|
|
141
|
+
reason: skippedReason(inventory, resourceId),
|
|
142
|
+
location,
|
|
143
|
+
resourceId: isCanonicalUuid(resourceId) ? resourceId : null,
|
|
144
|
+
path: sanitizedPath(inventory.knownPaths.get(resourceId)),
|
|
145
|
+
});
|
|
146
|
+
for (const item of navigationPageItems(navItems)) if (item.url === "") note(item, "header");
|
|
147
|
+
if (footerSettings?.enabled === true) {
|
|
148
|
+
for (const target of footerPageTargets(footerSettings)) {
|
|
149
|
+
if (!inventory.paths.has(target.resourceId)) note({ ...target, label: target.label || "footer link" }, "footer");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
count: skipped.length,
|
|
154
|
+
items: skipped.slice(0, MAXIMUM_SKIPPED_ITEMS),
|
|
155
|
+
...(skipped.length > MAXIMUM_SKIPPED_ITEMS ? { truncated: true } : {}),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Text for the verbs that print a chrome report; empty when nothing was skipped. */
|
|
160
|
+
export function describeSkippedLinks(skipped) {
|
|
161
|
+
if (skipped === undefined || skipped.count === 0) return "";
|
|
162
|
+
const shown = skipped.items.map(({ label, reason, location, path }) =>
|
|
163
|
+
`${label} (${reason}, ${location}${path === null || path === undefined ? "" : `, ${sanitizeDiagnostic(String(path), "(unprintable path)")}`})`).join(", ");
|
|
164
|
+
return `${skipped.count} navigation or footer page link(s) were not measured: ${shown}${skipped.truncated ? ", and more" : ""}.`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function pageInventoryFor(resources) {
|
|
168
|
+
if (resources.source === "site") {
|
|
169
|
+
// An unavailable listing is an incomplete inventory: page targets are unknown, not assumed linked.
|
|
170
|
+
return pageLinkInventory(resources.pageInventory?.pages, resources.pageInventory !== undefined && resources.pageInventory.truncated !== true);
|
|
171
|
+
}
|
|
172
|
+
return pageLinkInventory(resources.manifest?.pages, resources.manifest !== undefined && resources.manifest.pagesTruncated !== true);
|
|
67
173
|
}
|
|
68
174
|
|
|
69
175
|
function resolveLogoPairs(style, header, footer, media, delivery) {
|
|
@@ -95,7 +201,6 @@ function checkedFooterSettings(publishing, resources) {
|
|
|
95
201
|
if (publishing?.footerSettings === undefined) return undefined;
|
|
96
202
|
try {
|
|
97
203
|
return validateFooterDocument(publishing.footerSettings, {
|
|
98
|
-
knownPageResourceIds: resources.knownPageResourceIds,
|
|
99
204
|
knownImageIds: resources.knownImageIds,
|
|
100
205
|
});
|
|
101
206
|
} catch {
|
|
@@ -112,10 +217,10 @@ export function buildChromeInput({ appearance, resources, nameReportEnabled }) {
|
|
|
112
217
|
const footer = checkedFooterSettings(publishing, resources);
|
|
113
218
|
const footerSettings = footer === undefined ? undefined : { ...footer, ...footerPresentation };
|
|
114
219
|
const settingsOnly = isSettingsOnly(resources);
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
220
|
+
const inventory = settingsOnly ? undefined : pageInventoryFor(resources);
|
|
221
|
+
const footerPagePaths = settingsOnly ? new Map() : inventory?.paths;
|
|
222
|
+
const navItems = settingsOnly || resources.navigation === undefined ? undefined
|
|
223
|
+
: resolveNavigationItems(resources.navigation.navItems, footerPagePaths, NAVIGATION_KINDS);
|
|
119
224
|
const logoPairs = resolveLogoPairs(style, header, footerSettings, resources.mediaManifest?.media, resources.presentation);
|
|
120
225
|
const headerBrandColors = resolveBrandColors(header, resolveBrandColorToken);
|
|
121
226
|
const features = chromeFeatures({
|
|
@@ -127,6 +232,7 @@ export function buildChromeInput({ appearance, resources, nameReportEnabled }) {
|
|
|
127
232
|
searchEnabled: publishing?.allowSearch === true,
|
|
128
233
|
hasIconSprite: true,
|
|
129
234
|
nameReportEnabled: footerSettings === undefined ? undefined : nameReportEnabled,
|
|
235
|
+
themes: { light: style?.lightTheme, dark: style?.darkTheme },
|
|
130
236
|
});
|
|
131
237
|
const contexts = new Set(sharedDeclaredThemeContextNames(style?.lightTheme, style?.darkTheme));
|
|
132
238
|
const surfaces = [
|
|
@@ -143,5 +249,6 @@ export function buildChromeInput({ appearance, resources, nameReportEnabled }) {
|
|
|
143
249
|
brandColorSourceFields: resolveBrandColorSourceFields(header),
|
|
144
250
|
badgeSettings: settingsOnly ? undefined : resources.badgeSettings ?? publishing,
|
|
145
251
|
navigationUnavailable: navItems === undefined,
|
|
252
|
+
skippedNavigationLinks: inventory === undefined || settingsOnly ? undefined : skippedLinks(inventory, navItems, footerSettings),
|
|
146
253
|
};
|
|
147
254
|
}
|
package/src/chrome-report.js
CHANGED
|
@@ -106,10 +106,11 @@ async function extraPaintEntries(nameReportEnabled) {
|
|
|
106
106
|
/** Measure optional chrome without changing the command that accepted the appearance. */
|
|
107
107
|
export async function completeChromeReport(inputs, { loadFit = loadFitReport } = {}) {
|
|
108
108
|
let navigationUnavailable = true;
|
|
109
|
+
let skippedNavigationLinks;
|
|
109
110
|
try {
|
|
110
111
|
const { themes, appearance, resources, nameReportEnabled } = inputs;
|
|
111
112
|
const input = buildChromeInput({ appearance, resources, nameReportEnabled });
|
|
112
|
-
({ navigationUnavailable } = input);
|
|
113
|
+
({ navigationUnavailable, skippedNavigationLinks } = input);
|
|
113
114
|
const light = parseTheme(themes.light);
|
|
114
115
|
const dark = parseTheme(themes.dark);
|
|
115
116
|
if (!light || !dark) throw new Error("Missing accepted theme pair.");
|
|
@@ -158,7 +159,7 @@ export async function completeChromeReport(inputs, { loadFit = loadFitReport } =
|
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
|
-
return { entries, badges, flags, warnings, contrast: { pairs, belowAa: flags.filter(({ code }) => code === CONTRAST_TEXT_BELOW_AA).length }, navigationUnavailable, unavailable: false };
|
|
162
|
+
return { entries, badges, flags, warnings, contrast: { pairs, belowAa: flags.filter(({ code }) => code === CONTRAST_TEXT_BELOW_AA).length }, navigationUnavailable, skippedNavigationLinks, unavailable: false };
|
|
162
163
|
} catch {
|
|
163
164
|
return {
|
|
164
165
|
entries: { light: [], dark: [] },
|
|
@@ -167,6 +168,7 @@ export async function completeChromeReport(inputs, { loadFit = loadFitReport } =
|
|
|
167
168
|
warnings: [CHROME_UNAVAILABLE_MESSAGE],
|
|
168
169
|
contrast: { pairs: 0, belowAa: 0 },
|
|
169
170
|
navigationUnavailable,
|
|
171
|
+
skippedNavigationLinks,
|
|
170
172
|
unavailable: true,
|
|
171
173
|
};
|
|
172
174
|
}
|