@janga/norna 0.7.23 → 0.7.24
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 +14 -18
- package/astro.config.mjs +12 -0
- package/bin/norna-cli.mjs +6 -0
- package/package.json +13 -2
- package/schemas/category.schema.json +2 -2
- package/schemas/config.schema.json +45 -15
- package/schemas/content-frontmatter.schema.json +7 -7
- package/schemas/page-theme.schema.json +26 -26
- package/schemas/sitewide-content.schema.json +18 -18
- package/schemas/theme.schema.json +246 -246
- package/scripts/build-site.mjs +1 -0
- package/scripts/check-config.mjs +12 -1
- package/scripts/generate-search-index.mjs +57 -0
- package/scripts/init-site.mjs +1 -0
- package/scripts/lib/code-fence-metadata.mjs +223 -0
- package/scripts/lib/edit-source-link.mjs +49 -0
- package/scripts/lib/editor-language-service.mjs +32 -12
- package/scripts/lib/image-presentation.mjs +4 -0
- package/scripts/lib/navigation-model.mjs +34 -13
- package/scripts/lib/navigation-review.mjs +396 -0
- package/scripts/lib/norna-markdown-blocks.mjs +73 -26
- package/scripts/lib/norna-markdown-render-plugin.mjs +64 -1
- package/scripts/lib/page-aliases.mjs +21 -1
- package/scripts/lib/page-markdown.mjs +32 -1
- package/scripts/lib/page-move-plan.mjs +659 -0
- package/scripts/lib/presentation-palette-metadata.mjs +1 -1
- package/scripts/lib/presentation.mjs +1 -10
- package/scripts/lib/project-config.mjs +111 -5
- package/scripts/lib/public-asset-conventions.mjs +36 -2
- package/scripts/lib/schema-definitions.mjs +22 -5
- package/scripts/lib/schema-editor-metadata.mjs +19 -4
- package/scripts/lib/schema-value-definitions.mjs +1 -1
- package/scripts/lib/semantic-callouts.mjs +128 -0
- package/scripts/lib/site-content.mjs +2 -1
- package/scripts/lib/site-link-graph.mjs +33 -2
- package/scripts/lib/site-navigation-tree.mjs +85 -0
- package/scripts/lib/social-image-assets.mjs +30 -0
- package/scripts/lib/theme-presets.mjs +2 -2
- package/scripts/lib/theme-profiles.mjs +0 -4
- package/scripts/move-site-page.mjs +256 -0
- package/scripts/review-navigation.mjs +32 -0
- package/scripts/sync-content-sections.mjs +67 -4
- package/scripts/sync-site-public.mjs +24 -5
- package/src/components/CodeBlockCopyScript.astro +9 -4
- package/src/components/EditSourceLink.astro +17 -0
- package/src/components/ImageCarousel.astro +5 -6
- package/src/components/NavigationPageTree.astro +66 -55
- package/src/components/NavigationTreeControls.astro +77 -0
- package/src/components/PageAliasRedirect.astro +1 -1
- package/src/components/PageList.astro +33 -0
- package/src/components/PageSequenceNavigation.astro +37 -0
- package/src/components/SearchPage.astro +151 -0
- package/src/components/SiteNavigation.astro +35 -8
- package/src/components/SitePage.astro +79 -26
- package/src/components/SiteSection.astro +11 -3
- package/src/components/SiteTreeNavigation.astro +8 -1
- package/src/components/TreeNavigationScript.astro +207 -26
- package/src/layouts/BaseLayout.astro +57 -2
- package/src/lib/sectionContent.ts +32 -3
- package/src/lib/siteNavigation.ts +31 -52
- package/src/lib/sitePublicAssets.ts +1 -0
- package/src/pages/404.astro +110 -0
- package/src/pages/[...slug].astro +15 -5
- package/src/styles/content.css +242 -18
- package/src/styles/media.css +0 -5
- package/src/styles/navigation.css +31 -0
- package/src/styles/page-layout.css +438 -89
- package/src/styles/responsive.css +77 -8
- package/starters/basic/README.md +6 -19
- package/starters/basic/package.json +1 -0
- package/starters/basic/site/pages/000-home/content.md +13 -50
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { resolveNavigationModel } from './navigation-model.mjs';
|
|
2
|
+
import { getSiteLinkGraph } from './site-link-graph.mjs';
|
|
3
|
+
import { getSiteNodePathname } from './site-page-urls.mjs';
|
|
4
|
+
import {
|
|
5
|
+
flattenSiteNavigationTree,
|
|
6
|
+
getListedSiteNavigationTree,
|
|
7
|
+
getSiteNavigationTree,
|
|
8
|
+
} from './site-navigation-tree.mjs';
|
|
9
|
+
import { getSiteStructure } from './site-structure.mjs';
|
|
10
|
+
|
|
11
|
+
export const navigationReviewFormatNames = Object.freeze(['text', 'json']);
|
|
12
|
+
|
|
13
|
+
export const navigationReviewThresholds = Object.freeze({
|
|
14
|
+
deepBranchLevels: 4,
|
|
15
|
+
sectionCount: 8,
|
|
16
|
+
wideSiblingCount: 10,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const plural = (count, singular, pluralForm = `${singular}s`) => (
|
|
20
|
+
`${count} ${count === 1 ? singular : pluralForm}`
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const logicalPathname = (node) => getSiteNodePathname(node);
|
|
24
|
+
|
|
25
|
+
const getTreeMetrics = (root) => {
|
|
26
|
+
const nodes = flattenSiteNavigationTree([root]);
|
|
27
|
+
const rootDepth = root.node.depth;
|
|
28
|
+
return {
|
|
29
|
+
categoryCount: nodes.filter(({ node }) => node.kind === 'category').length,
|
|
30
|
+
maximumLevels: nodes.reduce((maximum, { node }) => (
|
|
31
|
+
Math.max(maximum, node.depth - rootDepth + 1)
|
|
32
|
+
), 1),
|
|
33
|
+
nodeCount: nodes.length,
|
|
34
|
+
pageCount: nodes.filter(({ node }) => node.kind === 'page').length,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getSiblingGroups = (roots) => {
|
|
39
|
+
const groups = [];
|
|
40
|
+
const collect = (nodes, parent = null) => {
|
|
41
|
+
if (nodes.length > 0) {
|
|
42
|
+
groups.push({
|
|
43
|
+
count: nodes.length,
|
|
44
|
+
entries: nodes.map(({ node }) => ({
|
|
45
|
+
kind: node.kind,
|
|
46
|
+
path: logicalPathname(node),
|
|
47
|
+
title: node.title,
|
|
48
|
+
})),
|
|
49
|
+
parentPath: parent ? logicalPathname(parent.node) : null,
|
|
50
|
+
parentTitle: parent?.node.title ?? 'Site root',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
for (const node of nodes) collect(node.children, node);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
collect(roots);
|
|
58
|
+
return groups;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const toGraphError = (diagnostic) => ({
|
|
62
|
+
code: diagnostic.code,
|
|
63
|
+
...(diagnostic.fix ? { fix: diagnostic.fix } : {}),
|
|
64
|
+
...(diagnostic.reference?.line ? { line: diagnostic.reference.line } : {}),
|
|
65
|
+
message: diagnostic.message,
|
|
66
|
+
...(diagnostic.reference?.sourceContentFile?.contentLabel
|
|
67
|
+
? { source: diagnostic.reference.sourceContentFile.contentLabel }
|
|
68
|
+
: {}),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const toStructureObservation = (warning) => ({
|
|
72
|
+
code: warning.code,
|
|
73
|
+
message: warning.message,
|
|
74
|
+
...(warning.label ? { source: warning.label } : {}),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const getResolvedPageReferences = (linkGraph) => linkGraph.references.filter(({ resolution }) => (
|
|
78
|
+
resolution?.kind === 'page' || resolution?.kind === 'page-alias'
|
|
79
|
+
));
|
|
80
|
+
|
|
81
|
+
const getNavigationEntries = (siteStructure, linkGraph) => {
|
|
82
|
+
const pagesByDirectory = new Map(linkGraph.pages.map((page) => [
|
|
83
|
+
page.contentFile.pageDirectory,
|
|
84
|
+
page,
|
|
85
|
+
]));
|
|
86
|
+
|
|
87
|
+
return siteStructure.nodes.map((siteNode) => {
|
|
88
|
+
const page = siteNode.kind === 'page'
|
|
89
|
+
? pagesByDirectory.get(siteNode.pageDirectory)
|
|
90
|
+
: null;
|
|
91
|
+
if (siteNode.kind === 'page' && !page) {
|
|
92
|
+
throw new Error(`Navigation review could not find parsed content for ${siteNode.contentLabel}.`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
headings: page?.document.headings.filter(({ depth }) => depth === 2 || depth === 3) ?? [],
|
|
97
|
+
node: {
|
|
98
|
+
...siteNode,
|
|
99
|
+
navigation: {
|
|
100
|
+
listed: siteNode.isHome || (page?.navigation.listed ?? true),
|
|
101
|
+
},
|
|
102
|
+
pathname: siteNode.kind === 'page' ? page.pathname : null,
|
|
103
|
+
title: siteNode.kind === 'page' ? page.title : siteNode.label,
|
|
104
|
+
},
|
|
105
|
+
page,
|
|
106
|
+
sections: [],
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const getNavigationModes = ({ entries, listedEntries, requestedNavigationMode }) => {
|
|
112
|
+
const modelNodes = listedEntries.map(({ headings, node }) => ({
|
|
113
|
+
depth: node.depth,
|
|
114
|
+
headings,
|
|
115
|
+
isHome: node.isHome,
|
|
116
|
+
kind: node.kind,
|
|
117
|
+
listed: true,
|
|
118
|
+
pagePath: node.pagePath,
|
|
119
|
+
}));
|
|
120
|
+
const errors = [];
|
|
121
|
+
const modes = new Map();
|
|
122
|
+
const seenErrors = new Set();
|
|
123
|
+
|
|
124
|
+
for (const entry of entries.filter(({ node }) => node.kind === 'page')) {
|
|
125
|
+
try {
|
|
126
|
+
const model = resolveNavigationModel({
|
|
127
|
+
currentPage: {
|
|
128
|
+
depth: entry.node.depth,
|
|
129
|
+
headings: entry.headings,
|
|
130
|
+
isHome: entry.node.isHome,
|
|
131
|
+
kind: 'page',
|
|
132
|
+
listed: entry.node.navigation.listed,
|
|
133
|
+
pagePath: entry.node.pagePath,
|
|
134
|
+
},
|
|
135
|
+
mode: requestedNavigationMode,
|
|
136
|
+
nodes: modelNodes,
|
|
137
|
+
});
|
|
138
|
+
modes.set(entry.node.pagePath, model.mode);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
141
|
+
if (!seenErrors.has(message)) {
|
|
142
|
+
seenErrors.add(message);
|
|
143
|
+
errors.push({
|
|
144
|
+
code: 'invalid-navigation-model',
|
|
145
|
+
message,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
modes.set(entry.node.pagePath, null);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return { errors, modes };
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const sortUnique = (values) => [...new Set(values)].sort((left, right) => left.localeCompare(right, 'en'));
|
|
156
|
+
|
|
157
|
+
export const createNavigationReview = ({
|
|
158
|
+
linkGraph,
|
|
159
|
+
requestedNavigationMode = 'automatic',
|
|
160
|
+
siteStructure,
|
|
161
|
+
thresholds = navigationReviewThresholds,
|
|
162
|
+
}) => {
|
|
163
|
+
const entries = getNavigationEntries(siteStructure, linkGraph);
|
|
164
|
+
const completeTree = getSiteNavigationTree(entries);
|
|
165
|
+
const listedTree = getListedSiteNavigationTree(entries);
|
|
166
|
+
const completeEntries = flattenSiteNavigationTree(completeTree);
|
|
167
|
+
const listedEntries = flattenSiteNavigationTree(listedTree);
|
|
168
|
+
const listedPaths = new Set(listedEntries.map(({ node }) => node.pagePath));
|
|
169
|
+
const resolvedPageReferences = getResolvedPageReferences(linkGraph);
|
|
170
|
+
const { errors: navigationErrors, modes } = getNavigationModes({
|
|
171
|
+
entries: completeEntries,
|
|
172
|
+
listedEntries,
|
|
173
|
+
requestedNavigationMode,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const pages = completeEntries
|
|
177
|
+
.filter(({ node }) => node.kind === 'page')
|
|
178
|
+
.map(({ headings, node, page }) => {
|
|
179
|
+
const incomingPageLinkCount = resolvedPageReferences.filter(({ resolution }) => (
|
|
180
|
+
resolution.page.pathname === page.pathname
|
|
181
|
+
)).length;
|
|
182
|
+
const outgoingReferences = linkGraph.references.filter(({ sourcePage }) => sourcePage.pathname === page.pathname);
|
|
183
|
+
const outgoingPageLinkCount = outgoingReferences.filter(({ resolution }) => (
|
|
184
|
+
resolution?.kind === 'page' || resolution?.kind === 'page-alias'
|
|
185
|
+
)).length;
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
contentFile: node.contentLabel,
|
|
189
|
+
depth: node.depth,
|
|
190
|
+
h2Count: headings.filter(({ depth }) => depth === 2).length,
|
|
191
|
+
h3Count: headings.filter(({ depth }) => depth === 3).length,
|
|
192
|
+
incomingPageLinkCount,
|
|
193
|
+
listed: listedPaths.has(node.pagePath),
|
|
194
|
+
navigationMode: modes.get(node.pagePath) ?? null,
|
|
195
|
+
outgoingInternalReferenceCount: outgoingReferences.length,
|
|
196
|
+
outgoingPageLinkCount,
|
|
197
|
+
parentPath: node.parentPagePath === null ? null : `/${node.parentPagePath}/`,
|
|
198
|
+
pathname: page.pathname,
|
|
199
|
+
title: node.title,
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const categories = completeEntries
|
|
204
|
+
.filter(({ node }) => node.kind === 'category')
|
|
205
|
+
.map(({ children, node }) => ({
|
|
206
|
+
childCount: children.length,
|
|
207
|
+
depth: node.depth,
|
|
208
|
+
listed: listedPaths.has(node.pagePath),
|
|
209
|
+
listedChildCount: listedPaths.has(node.pagePath)
|
|
210
|
+
? (listedEntries.find(({ node: listedNode }) => listedNode.pagePath === node.pagePath)?.children.length ?? 0)
|
|
211
|
+
: 0,
|
|
212
|
+
parentPath: node.parentPagePath === null ? null : `/${node.parentPagePath}/`,
|
|
213
|
+
path: logicalPathname(node),
|
|
214
|
+
source: node.categorySourceLabel,
|
|
215
|
+
title: node.title,
|
|
216
|
+
}));
|
|
217
|
+
|
|
218
|
+
const branches = listedTree.map((root) => {
|
|
219
|
+
const metrics = getTreeMetrics(root);
|
|
220
|
+
const branchPaths = new Set(flattenSiteNavigationTree([root]).map(({ node }) => node.pagePath));
|
|
221
|
+
const navigationModes = sortUnique(pages
|
|
222
|
+
.filter((page) => branchPaths.has(page.pathname === '/' ? '' : page.pathname.slice(1, -1)))
|
|
223
|
+
.map(({ navigationMode }) => navigationMode)
|
|
224
|
+
.filter(Boolean));
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
...metrics,
|
|
228
|
+
kind: root.node.kind,
|
|
229
|
+
navigationModes,
|
|
230
|
+
path: logicalPathname(root.node),
|
|
231
|
+
title: root.node.title,
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const siblingGroups = getSiblingGroups(listedTree);
|
|
236
|
+
const widestSiblingCount = siblingGroups.reduce((maximum, group) => Math.max(maximum, group.count), 0);
|
|
237
|
+
const observations = [
|
|
238
|
+
...siteStructure.warnings.map(toStructureObservation),
|
|
239
|
+
];
|
|
240
|
+
const unlistedPages = pages.filter(({ listed }) => !listed);
|
|
241
|
+
if (unlistedPages.length > 0) {
|
|
242
|
+
observations.push({
|
|
243
|
+
code: 'unlisted-pages',
|
|
244
|
+
message: `${plural(unlistedPages.length, 'page')} and any descendants are outside generated navigation: ${unlistedPages.map(({ pathname }) => pathname).join(', ')}.`,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const recommendations = [];
|
|
249
|
+
for (const category of categories.filter(({ listed, listedChildCount }) => listed && listedChildCount === 1)) {
|
|
250
|
+
recommendations.push({
|
|
251
|
+
code: 'single-child-category',
|
|
252
|
+
message: `${category.title} (${category.path}) has one listed child. Keep the category when its label adds useful orientation; otherwise consider moving the child to the category's parent.`,
|
|
253
|
+
path: category.path,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
for (const branch of branches.filter(({ maximumLevels }) => maximumLevels >= thresholds.deepBranchLevels)) {
|
|
257
|
+
recommendations.push({
|
|
258
|
+
code: 'deep-branch',
|
|
259
|
+
message: `${branch.title} (${branch.path}) has ${branch.maximumLevels} visible levels. Review representative navigation tasks before adding another level.`,
|
|
260
|
+
path: branch.path,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
for (const group of siblingGroups.filter(({ count }) => count >= thresholds.wideSiblingCount)) {
|
|
264
|
+
recommendations.push({
|
|
265
|
+
code: 'wide-sibling-group',
|
|
266
|
+
message: `${group.parentTitle} has ${group.count} listed child entries. Review whether stable, meaningful groups would make scanning easier.`,
|
|
267
|
+
...(group.parentPath ? { path: group.parentPath } : {}),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
for (const page of pages.filter(({ h2Count }) => h2Count >= thresholds.sectionCount)) {
|
|
271
|
+
recommendations.push({
|
|
272
|
+
code: 'section-heavy-page',
|
|
273
|
+
message: `${page.title} (${page.pathname}) has ${page.h2Count} H2 sections. Confirm that they still support one coherent reading task; otherwise consider child pages.`,
|
|
274
|
+
path: page.pathname,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const effectiveNavigationModes = sortUnique(pages.map(({ navigationMode }) => navigationMode).filter(Boolean));
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
command: 'navigation:review',
|
|
282
|
+
schemaVersion: 1,
|
|
283
|
+
thresholds: {
|
|
284
|
+
deepBranchLevels: thresholds.deepBranchLevels,
|
|
285
|
+
sectionCount: thresholds.sectionCount,
|
|
286
|
+
wideSiblingCount: thresholds.wideSiblingCount,
|
|
287
|
+
},
|
|
288
|
+
site: {
|
|
289
|
+
branchCount: branches.length,
|
|
290
|
+
categoryCount: categories.length,
|
|
291
|
+
effectiveNavigationModes,
|
|
292
|
+
internalReferenceCount: linkGraph.references.length,
|
|
293
|
+
listedCategoryCount: categories.filter(({ listed }) => listed).length,
|
|
294
|
+
listedPageCount: pages.filter(({ listed }) => listed).length,
|
|
295
|
+
maximumDepth: listedEntries.reduce((maximum, { node }) => Math.max(maximum, node.depth), 0),
|
|
296
|
+
pageCount: pages.length,
|
|
297
|
+
requestedNavigationMode,
|
|
298
|
+
resolvedPageLinkCount: resolvedPageReferences.length,
|
|
299
|
+
widestSiblingCount,
|
|
300
|
+
},
|
|
301
|
+
branches,
|
|
302
|
+
siblingGroups,
|
|
303
|
+
pages,
|
|
304
|
+
categories,
|
|
305
|
+
errors: [
|
|
306
|
+
...linkGraph.diagnostics.map(toGraphError),
|
|
307
|
+
...navigationErrors,
|
|
308
|
+
],
|
|
309
|
+
observations,
|
|
310
|
+
recommendations,
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export const getNavigationReview = async ({ requestedNavigationMode = 'automatic' } = {}) => {
|
|
315
|
+
const siteStructure = await getSiteStructure();
|
|
316
|
+
const linkGraph = await getSiteLinkGraph({ siteStructure });
|
|
317
|
+
return createNavigationReview({ linkGraph, requestedNavigationMode, siteStructure });
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const formatFindingSection = (title, findings) => [
|
|
321
|
+
title,
|
|
322
|
+
...(findings.length === 0
|
|
323
|
+
? ['- None.']
|
|
324
|
+
: findings.map((finding) => `- [${finding.code}] ${finding.message}${finding.source ? ` (${finding.source}${finding.line ? `:${finding.line}` : ''})` : ''}${finding.fix ? ` Fix: ${finding.fix}` : ''}`)),
|
|
325
|
+
];
|
|
326
|
+
|
|
327
|
+
export const formatNavigationReviewText = (review) => {
|
|
328
|
+
const lines = [
|
|
329
|
+
'Navigation Review',
|
|
330
|
+
'',
|
|
331
|
+
'Site',
|
|
332
|
+
`- Navigation: ${review.site.requestedNavigationMode} configured; ${review.site.effectiveNavigationModes.join(', ') || 'unresolved'} effective`,
|
|
333
|
+
`- Content: ${plural(review.site.pageCount, 'page')} (${review.site.listedPageCount} listed), ${plural(review.site.categoryCount, 'category', 'categories')} (${review.site.listedCategoryCount} listed)`,
|
|
334
|
+
`- Structure: ${plural(review.site.branchCount, 'top-level branch', 'top-level branches')}, ${review.site.maximumDepth} listed ${review.site.maximumDepth === 1 ? 'level' : 'levels'}, widest sibling group ${review.site.widestSiblingCount}`,
|
|
335
|
+
`- Links: ${plural(review.site.internalReferenceCount, 'internal reference')}, ${review.site.resolvedPageLinkCount} resolved to pages`,
|
|
336
|
+
'',
|
|
337
|
+
'Branches',
|
|
338
|
+
...review.branches.map((branch) => (
|
|
339
|
+
`- ${branch.title} (${branch.path}; ${branch.kind}): ${plural(branch.pageCount, 'page')}, ${plural(branch.categoryCount, 'category', 'categories')}, ${plural(branch.maximumLevels, 'visible level')}; navigation ${branch.navigationModes.join(', ') || 'unresolved'}`
|
|
340
|
+
)),
|
|
341
|
+
'',
|
|
342
|
+
'Pages',
|
|
343
|
+
...review.pages.map((page) => (
|
|
344
|
+
`- ${page.title} (${page.pathname}; ${page.listed ? 'listed' : 'not listed'}): H2 ${page.h2Count}, H3 ${page.h3Count}; page links ${page.outgoingPageLinkCount} out / ${page.incomingPageLinkCount} in; navigation ${page.navigationMode ?? 'unresolved'}`
|
|
345
|
+
)),
|
|
346
|
+
'',
|
|
347
|
+
'Categories',
|
|
348
|
+
...(review.categories.length === 0
|
|
349
|
+
? ['- None.']
|
|
350
|
+
: review.categories.map((category) => (
|
|
351
|
+
`- ${category.title} (${category.path}; ${category.listed ? 'listed' : 'not listed'}): ${category.listedChildCount} listed of ${plural(category.childCount, 'direct child', 'direct children')}`
|
|
352
|
+
))),
|
|
353
|
+
'',
|
|
354
|
+
...formatFindingSection('Errors', review.errors),
|
|
355
|
+
'',
|
|
356
|
+
...formatFindingSection('Observations', review.observations),
|
|
357
|
+
'',
|
|
358
|
+
...formatFindingSection('Recommendations', review.recommendations),
|
|
359
|
+
];
|
|
360
|
+
|
|
361
|
+
return `${lines.join('\n')}\n`;
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
export const parseNavigationReviewArgs = (args) => {
|
|
365
|
+
let format = 'text';
|
|
366
|
+
let formatSeen = false;
|
|
367
|
+
let help = false;
|
|
368
|
+
|
|
369
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
370
|
+
const arg = args[index];
|
|
371
|
+
if (arg === '-h' || arg === '--help') {
|
|
372
|
+
help = true;
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
let value = null;
|
|
377
|
+
if (arg === '--format') {
|
|
378
|
+
value = args[index + 1];
|
|
379
|
+
if (!value || value.startsWith('-')) throw new Error('--format requires text or json.');
|
|
380
|
+
index += 1;
|
|
381
|
+
} else if (arg.startsWith('--format=')) {
|
|
382
|
+
value = arg.slice('--format='.length);
|
|
383
|
+
} else {
|
|
384
|
+
throw new Error(`Unknown navigation:review option "${arg}". Use --format text or --format json.`);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (formatSeen) throw new Error('Specify --format only once.');
|
|
388
|
+
if (!navigationReviewFormatNames.includes(value)) {
|
|
389
|
+
throw new Error(`Unknown navigation:review format "${value}". Use one of: ${navigationReviewFormatNames.join(', ')}.`);
|
|
390
|
+
}
|
|
391
|
+
format = value;
|
|
392
|
+
formatSeen = true;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return { format, help };
|
|
396
|
+
};
|
|
@@ -4,7 +4,7 @@ const field = (description, options = {}) => Object.freeze({ description, ...opt
|
|
|
4
4
|
const value = (title, description) => Object.freeze({ title, description });
|
|
5
5
|
|
|
6
6
|
export const nornaMarkdownBlockDefinitions = Object.freeze({
|
|
7
|
-
'
|
|
7
|
+
'image-stack': Object.freeze({
|
|
8
8
|
description: 'Display one or more managed images in a vertical stack.',
|
|
9
9
|
documentation: documentationLink('Image stack reference', 'content.md', 'image-stack'),
|
|
10
10
|
item: Object.freeze({
|
|
@@ -15,7 +15,7 @@ export const nornaMarkdownBlockDefinitions = Object.freeze({
|
|
|
15
15
|
}),
|
|
16
16
|
}),
|
|
17
17
|
}),
|
|
18
|
-
'
|
|
18
|
+
'image-carousel': Object.freeze({
|
|
19
19
|
description: 'Display two or more managed images in an interactive carousel.',
|
|
20
20
|
documentation: documentationLink('Image carousel reference', 'content.md', 'image-carousel'),
|
|
21
21
|
item: Object.freeze({
|
|
@@ -26,7 +26,7 @@ export const nornaMarkdownBlockDefinitions = Object.freeze({
|
|
|
26
26
|
}),
|
|
27
27
|
}),
|
|
28
28
|
}),
|
|
29
|
-
'
|
|
29
|
+
'card-list': Object.freeze({
|
|
30
30
|
description: 'Display a structured list of cards.',
|
|
31
31
|
documentation: documentationLink('Card list reference', 'content.md', 'card-list'),
|
|
32
32
|
options: Object.freeze({
|
|
@@ -73,25 +73,45 @@ export const nornaMarkdownBlockDefinitions = Object.freeze({
|
|
|
73
73
|
}),
|
|
74
74
|
}),
|
|
75
75
|
}),
|
|
76
|
+
'page-list': Object.freeze({
|
|
77
|
+
description: 'Display the current page\'s listed direct child pages in navigation order.',
|
|
78
|
+
documentation: documentationLink('Child page list reference', 'content.md', 'child-page-list'),
|
|
79
|
+
}),
|
|
76
80
|
});
|
|
77
81
|
|
|
78
82
|
export const nornaBlockTypes = new Set(Object.keys(nornaMarkdownBlockDefinitions));
|
|
79
83
|
|
|
84
|
+
const renamedNornaBlockTypes = Object.freeze({
|
|
85
|
+
'norna-image-stack': 'image-stack',
|
|
86
|
+
'norna-image-carousel': 'image-carousel',
|
|
87
|
+
'norna-carousel': 'image-carousel',
|
|
88
|
+
carousel: 'image-carousel',
|
|
89
|
+
'norna-card-list': 'card-list',
|
|
90
|
+
'norna-page-list': 'page-list',
|
|
91
|
+
});
|
|
92
|
+
|
|
80
93
|
const blockTypeLabels = {
|
|
81
|
-
'
|
|
82
|
-
'
|
|
83
|
-
'
|
|
94
|
+
'image-stack': 'image-stack',
|
|
95
|
+
'image-carousel': 'image-carousel',
|
|
96
|
+
'card-list': 'card-list',
|
|
97
|
+
'page-list': 'page-list',
|
|
84
98
|
};
|
|
85
99
|
|
|
86
100
|
const knownBlockTypeList = Array.from(nornaBlockTypes).join(', ');
|
|
87
101
|
const imageNameRegex = /^[a-z0-9][a-z0-9.-]*\.(jpe?g|png|svg)$/i;
|
|
88
102
|
const imageStackExample = [
|
|
89
|
-
'```
|
|
103
|
+
'```image-stack',
|
|
90
104
|
'- image: filename.jpg',
|
|
91
105
|
'```',
|
|
92
106
|
].join('\n');
|
|
107
|
+
const carouselExample = [
|
|
108
|
+
'```image-carousel',
|
|
109
|
+
'- image: first.jpg',
|
|
110
|
+
'- image: second.jpg',
|
|
111
|
+
'```',
|
|
112
|
+
].join('\n');
|
|
93
113
|
const cardListExample = [
|
|
94
|
-
'```
|
|
114
|
+
'```card-list',
|
|
95
115
|
'layout: image-top',
|
|
96
116
|
'flow: grid',
|
|
97
117
|
'size: m',
|
|
@@ -103,7 +123,17 @@ const cardListExample = [
|
|
|
103
123
|
' badge-text: Recommended',
|
|
104
124
|
'```',
|
|
105
125
|
].join('\n');
|
|
106
|
-
const
|
|
126
|
+
const pageListExample = [
|
|
127
|
+
'```page-list',
|
|
128
|
+
'```',
|
|
129
|
+
].join('\n');
|
|
130
|
+
const blockExamples = Object.freeze({
|
|
131
|
+
'image-stack': imageStackExample,
|
|
132
|
+
'image-carousel': carouselExample,
|
|
133
|
+
'card-list': cardListExample,
|
|
134
|
+
'page-list': pageListExample,
|
|
135
|
+
});
|
|
136
|
+
const cardListDefinition = nornaMarkdownBlockDefinitions['card-list'];
|
|
107
137
|
const cardListLayouts = new Set(Object.keys(cardListDefinition.options.layout.values));
|
|
108
138
|
const cardListFlows = new Set(Object.keys(cardListDefinition.options.flow.values));
|
|
109
139
|
const cardListSizes = new Set(Object.keys(cardListDefinition.options.size.values));
|
|
@@ -120,18 +150,20 @@ const fail = (message, options) => {
|
|
|
120
150
|
};
|
|
121
151
|
|
|
122
152
|
const getUnknownNornaBlockMessage = (type) => [
|
|
123
|
-
|
|
153
|
+
renamedNornaBlockTypes[type]
|
|
154
|
+
? `Norna block "${type}" was renamed to "${renamedNornaBlockTypes[type]}".`
|
|
155
|
+
: `Unknown Norna block "${type}". Use one of: ${knownBlockTypeList}.`,
|
|
124
156
|
type === 'norna-gallery-stack'
|
|
125
|
-
? 'Use
|
|
157
|
+
? 'Use image-stack for one or more stacked images.'
|
|
126
158
|
: null,
|
|
127
|
-
type === 'norna-carousel'
|
|
128
|
-
? 'Use
|
|
159
|
+
type === 'norna-image-carousel' || type === 'norna-carousel' || type === 'carousel'
|
|
160
|
+
? 'Use image-carousel for an image carousel.'
|
|
129
161
|
: null,
|
|
130
162
|
type === 'norna-image'
|
|
131
|
-
? 'Use
|
|
163
|
+
? 'Use image-stack for a single image or a stacked list of images.'
|
|
132
164
|
: null,
|
|
133
165
|
'Example:',
|
|
134
|
-
imageStackExample,
|
|
166
|
+
blockExamples[renamedNornaBlockTypes[type] ?? type] ?? imageStackExample,
|
|
135
167
|
].filter(Boolean).join(' ');
|
|
136
168
|
|
|
137
169
|
const decodeScalar = (value) => {
|
|
@@ -229,17 +261,23 @@ export const getOpenMarkdownFenceAtLine = (markdown, lineIndex) => {
|
|
|
229
261
|
};
|
|
230
262
|
|
|
231
263
|
const getNornaLineAttempt = (line) => {
|
|
232
|
-
const match = line.match(/^ {0,3}([`~]{0,2})(
|
|
264
|
+
const match = line.match(/^ {0,3}([`~]{0,2})([a-z][a-z0-9-]+)\s*$/);
|
|
233
265
|
if (!match) return null;
|
|
266
|
+
const marker = match[1];
|
|
267
|
+
const type = match[2];
|
|
268
|
+
const isNamespacedAttempt = type.startsWith('norna-');
|
|
269
|
+
if (!isNamespacedAttempt && !nornaBlockTypes.has(type) && !renamedNornaBlockTypes[type]) return null;
|
|
270
|
+
if (!marker && type === 'carousel') return null;
|
|
234
271
|
|
|
235
272
|
return {
|
|
236
|
-
marker
|
|
237
|
-
type
|
|
273
|
+
marker,
|
|
274
|
+
type,
|
|
238
275
|
};
|
|
239
276
|
};
|
|
240
277
|
|
|
241
278
|
const getNornaFenceStartMessage = (type, marker = '') => {
|
|
242
|
-
const
|
|
279
|
+
const supportedType = renamedNornaBlockTypes[type] ?? type;
|
|
280
|
+
const example = blockExamples[supportedType] ?? imageStackExample;
|
|
243
281
|
if (marker) {
|
|
244
282
|
return `Invalid Norna block start for "${type}". Use three backticks or three tildes. Example:\n${example}`;
|
|
245
283
|
}
|
|
@@ -317,7 +355,7 @@ const scanMarkdownFencedBlocks = (markdown, options = {}) => {
|
|
|
317
355
|
}
|
|
318
356
|
}
|
|
319
357
|
|
|
320
|
-
const isNornaLike = type.startsWith('norna-');
|
|
358
|
+
const isNornaLike = type.startsWith('norna-') || nornaBlockTypes.has(type) || Boolean(renamedNornaBlockTypes[type]);
|
|
321
359
|
if (closingIndex === -1) {
|
|
322
360
|
if (isNornaLike) {
|
|
323
361
|
errors.push({
|
|
@@ -350,7 +388,7 @@ const scanMarkdownFencedBlocks = (markdown, options = {}) => {
|
|
|
350
388
|
} else {
|
|
351
389
|
errors.push({
|
|
352
390
|
blockType: type,
|
|
353
|
-
code: 'unknown-norna-block',
|
|
391
|
+
code: renamedNornaBlockTypes[type] ? 'renamed-norna-block' : 'unknown-norna-block',
|
|
354
392
|
line: lineNumber,
|
|
355
393
|
source,
|
|
356
394
|
message: failMessage(getUnknownNornaBlockMessage(type), { ...options, line: lineNumber }),
|
|
@@ -406,10 +444,10 @@ const parseImageListBlock = (source, options = {}) => {
|
|
|
406
444
|
}
|
|
407
445
|
|
|
408
446
|
if (images.length === 0) {
|
|
409
|
-
fail(`${options.type} must contain at least one image. Example:\n${
|
|
447
|
+
fail(`${options.type} must contain at least one image. Example:\n${blockExamples[options.type]}`, options);
|
|
410
448
|
}
|
|
411
449
|
|
|
412
|
-
return { type: options.type === '
|
|
450
|
+
return { type: options.type === 'image-carousel' ? 'image-carousel' : 'image-stack', images };
|
|
413
451
|
};
|
|
414
452
|
|
|
415
453
|
const parseCardListBlock = (source, options = {}) => {
|
|
@@ -517,15 +555,23 @@ const parseCardListBlock = (source, options = {}) => {
|
|
|
517
555
|
return { type: 'card-list', layout, flow, size, width, cards };
|
|
518
556
|
};
|
|
519
557
|
|
|
558
|
+
const parsePageListBlock = (source, options = {}) => {
|
|
559
|
+
if (source.trim()) {
|
|
560
|
+
fail(`${options.type} does not accept options or items. Leave the block empty. Example:\n${pageListExample}`, options);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return { type: 'page-list' };
|
|
564
|
+
};
|
|
565
|
+
|
|
520
566
|
export const parseNornaMarkdownBlock = (type, source, options = {}) => {
|
|
521
567
|
if (!nornaBlockTypes.has(type)) {
|
|
522
568
|
fail(getUnknownNornaBlockMessage(type), options);
|
|
523
569
|
}
|
|
524
570
|
|
|
525
571
|
const parseOptions = { ...options, type: blockTypeLabels[type] };
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
572
|
+
if (type === 'card-list') return parseCardListBlock(source, parseOptions);
|
|
573
|
+
if (type === 'page-list') return parsePageListBlock(source, parseOptions);
|
|
574
|
+
return parseImageListBlock(source, parseOptions);
|
|
529
575
|
};
|
|
530
576
|
|
|
531
577
|
const getLineNumber = (source, index) => source.slice(0, index).split(/\r?\n/).length;
|
|
@@ -631,6 +677,7 @@ export const getNornaBlockImageReferences = (blocks) =>
|
|
|
631
677
|
line: card.line ?? block.line,
|
|
632
678
|
}));
|
|
633
679
|
}
|
|
680
|
+
if (block.type === 'page-list') return [];
|
|
634
681
|
|
|
635
682
|
return block.images.map((image) => ({
|
|
636
683
|
...image,
|
|
@@ -1,17 +1,80 @@
|
|
|
1
1
|
import { defineMdastPlugin } from 'satteri';
|
|
2
2
|
import { nornaBlockTypes } from './norna-markdown-blocks.mjs';
|
|
3
|
+
import projectConfig from './project-config.mjs';
|
|
4
|
+
import { getSemanticCalloutMarker } from './semantic-callouts.mjs';
|
|
3
5
|
|
|
4
6
|
const stateKey = 'nornaMarkdownRender';
|
|
5
7
|
|
|
6
8
|
const getState = (context) => {
|
|
7
9
|
if (!context.data[stateKey]) {
|
|
8
|
-
context.data[stateKey] = { blockIndex: 0, regionIndex: 0 };
|
|
10
|
+
context.data[stateKey] = { blockIndex: 0, calloutIndex: 0, regionIndex: 0 };
|
|
9
11
|
}
|
|
10
12
|
return context.data[stateKey];
|
|
11
13
|
};
|
|
12
14
|
|
|
15
|
+
const calloutLabelKeys = Object.freeze({
|
|
16
|
+
CAUTION: 'calloutCaution',
|
|
17
|
+
DANGER: 'calloutDanger',
|
|
18
|
+
IMPORTANT: 'calloutImportant',
|
|
19
|
+
NOTE: 'calloutNote',
|
|
20
|
+
TIP: 'calloutTip',
|
|
21
|
+
WARNING: 'calloutWarning',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const hasBlockquoteAncestor = (node, context) => {
|
|
25
|
+
let parent = context.parent(node);
|
|
26
|
+
while (parent) {
|
|
27
|
+
if (parent.type === 'blockquote') return true;
|
|
28
|
+
parent = context.parent(parent);
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
|
|
13
33
|
export const nornaMarkdownRenderPlugin = defineMdastPlugin({
|
|
14
34
|
name: 'norna-markdown-render',
|
|
35
|
+
blockquote(node, context) {
|
|
36
|
+
const marker = getSemanticCalloutMarker(node);
|
|
37
|
+
if (
|
|
38
|
+
!marker
|
|
39
|
+
|| marker.malformed
|
|
40
|
+
|| !marker.supported
|
|
41
|
+
|| marker.rawType !== marker.type
|
|
42
|
+
|| marker.title
|
|
43
|
+
|| !marker.hasBody
|
|
44
|
+
|| hasBlockquoteAncestor(node, context)
|
|
45
|
+
) return;
|
|
46
|
+
|
|
47
|
+
const state = getState(context);
|
|
48
|
+
const labelKey = calloutLabelKeys[marker.type];
|
|
49
|
+
const label = projectConfig.locale.labels[labelKey];
|
|
50
|
+
const labelId = `norna-callout-label-${state.calloutIndex}`;
|
|
51
|
+
state.calloutIndex += 1;
|
|
52
|
+
|
|
53
|
+
context.setProperty(node, 'data', {
|
|
54
|
+
hName: 'aside',
|
|
55
|
+
hProperties: {
|
|
56
|
+
'aria-labelledby': labelId,
|
|
57
|
+
className: ['norna-callout', `norna-callout-${marker.type.toLowerCase()}`],
|
|
58
|
+
role: 'note',
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!marker.firstTextRemainder && marker.firstParagraph.children.length === 1) {
|
|
63
|
+
context.removeChildAt(node, 0);
|
|
64
|
+
} else {
|
|
65
|
+
context.setProperty(marker.firstText, 'value', marker.firstTextRemainder);
|
|
66
|
+
}
|
|
67
|
+
context.prependChild(node, {
|
|
68
|
+
type: 'paragraph',
|
|
69
|
+
data: {
|
|
70
|
+
hProperties: {
|
|
71
|
+
className: ['norna-callout-label'],
|
|
72
|
+
id: labelId,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
children: [{ type: 'text', value: label }],
|
|
76
|
+
});
|
|
77
|
+
},
|
|
15
78
|
code(node, context) {
|
|
16
79
|
if (!nornaBlockTypes.has(node.lang)) return;
|
|
17
80
|
|