@janga/norna 0.7.22 → 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.
Files changed (88) hide show
  1. package/README.md +14 -18
  2. package/astro.config.mjs +15 -0
  3. package/bin/norna-cli.mjs +8 -2
  4. package/package.json +28 -3
  5. package/schemas/category.schema.json +2 -2
  6. package/schemas/config.schema.json +52 -24
  7. package/schemas/content-frontmatter.schema.json +25 -5
  8. package/schemas/page-theme.schema.json +53 -25
  9. package/schemas/sitewide-content.schema.json +19 -18
  10. package/schemas/theme.schema.json +385 -252
  11. package/scripts/build-site.mjs +1 -0
  12. package/scripts/check-config.mjs +36 -5
  13. package/scripts/deploy-site.mjs +0 -1
  14. package/scripts/dev-local.mjs +175 -112
  15. package/scripts/generate-search-index.mjs +57 -0
  16. package/scripts/init-site.mjs +1 -0
  17. package/scripts/lib/code-fence-metadata.mjs +223 -0
  18. package/scripts/lib/content-sync-apply.mjs +34 -0
  19. package/scripts/lib/content-sync-plan.mjs +179 -0
  20. package/scripts/lib/edit-source-link.mjs +49 -0
  21. package/scripts/lib/editor-language-service.mjs +160 -12
  22. package/scripts/lib/heading-ids.mjs +1 -1
  23. package/scripts/lib/image-presentation.mjs +6 -0
  24. package/scripts/lib/markdown-links.mjs +182 -0
  25. package/scripts/lib/navigation-model.mjs +44 -12
  26. package/scripts/lib/navigation-review.mjs +396 -0
  27. package/scripts/lib/norna-markdown-blocks.mjs +74 -26
  28. package/scripts/lib/norna-markdown-render-plugin.mjs +64 -1
  29. package/scripts/lib/page-aliases.mjs +184 -0
  30. package/scripts/lib/page-markdown.mjs +88 -7
  31. package/scripts/lib/page-move-plan.mjs +659 -0
  32. package/scripts/lib/presentation-palette-metadata.mjs +1 -1
  33. package/scripts/lib/presentation.mjs +10 -37
  34. package/scripts/lib/project-config.mjs +146 -19
  35. package/scripts/lib/public-asset-conventions.mjs +36 -2
  36. package/scripts/lib/schema-definitions.mjs +43 -15
  37. package/scripts/lib/schema-editor-metadata.mjs +60 -32
  38. package/scripts/lib/schema-value-definitions.mjs +6 -2
  39. package/scripts/lib/semantic-callouts.mjs +128 -0
  40. package/scripts/lib/site-content.mjs +28 -5
  41. package/scripts/lib/site-link-graph.mjs +357 -0
  42. package/scripts/lib/site-navigation-tree.mjs +85 -0
  43. package/scripts/lib/site-page-urls.mjs +10 -0
  44. package/scripts/lib/sitemap.mjs +34 -0
  45. package/scripts/lib/social-image-assets.mjs +30 -0
  46. package/scripts/lib/theme-presets.mjs +53 -25
  47. package/scripts/lib/theme-profiles.mjs +6 -8
  48. package/scripts/lib/yaml-config.mjs +6 -2
  49. package/scripts/move-site-page.mjs +256 -0
  50. package/scripts/review-navigation.mjs +32 -0
  51. package/scripts/sync-content-sections.mjs +182 -216
  52. package/scripts/sync-site-public.mjs +43 -3
  53. package/src/components/CodeBlockCopyScript.astro +97 -0
  54. package/src/components/DisplaySettings.astro +4 -4
  55. package/src/components/EditSourceLink.astro +17 -0
  56. package/src/components/ImageCarousel.astro +6 -3
  57. package/src/components/NavigationPageTree.astro +81 -86
  58. package/src/components/NavigationTreeControls.astro +77 -0
  59. package/src/components/PageAliasRedirect.astro +49 -0
  60. package/src/components/PageContentsNavigation.astro +21 -0
  61. package/src/components/PageList.astro +33 -0
  62. package/src/components/PageSequenceNavigation.astro +37 -0
  63. package/src/components/SearchPage.astro +151 -0
  64. package/src/components/SectionNavigationScript.astro +62 -6
  65. package/src/components/SiteNavigation.astro +50 -11
  66. package/src/components/SitePage.astro +113 -20
  67. package/src/components/SiteSection.astro +16 -3
  68. package/src/components/SiteTreeNavigation.astro +8 -2
  69. package/src/components/TreeNavigationScript.astro +207 -26
  70. package/src/content.config.ts +5 -2
  71. package/src/layouts/BaseLayout.astro +71 -10
  72. package/src/lib/readerPreferencesScript.mjs +2 -2
  73. package/src/lib/sectionContent.ts +32 -3
  74. package/src/lib/siteNavigation.ts +31 -52
  75. package/src/lib/sitePages.ts +3 -2
  76. package/src/lib/sitePublicAssets.ts +1 -0
  77. package/src/pages/404.astro +110 -0
  78. package/src/pages/[...slug].astro +45 -8
  79. package/src/styles/content.css +718 -0
  80. package/src/styles/foundations.css +284 -0
  81. package/src/styles/global.css +6 -2510
  82. package/src/styles/media.css +518 -0
  83. package/src/styles/navigation.css +526 -0
  84. package/src/styles/page-layout.css +786 -0
  85. package/src/styles/responsive.css +594 -0
  86. package/starters/basic/README.md +6 -19
  87. package/starters/basic/package.json +1 -0
  88. package/starters/basic/site/pages/000-home/content.md +13 -50
@@ -0,0 +1,357 @@
1
+ import { readdir, readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import {
4
+ createPageAliasModel,
5
+ generatedSiteRoutes,
6
+ } from './page-aliases.mjs';
7
+ import { parsePageMarkdownSource } from './page-markdown.mjs';
8
+ import {
9
+ parseContentFrontmatter,
10
+ splitSiteFile,
11
+ toPosixPath,
12
+ } from './site-content.mjs';
13
+ import {
14
+ sitePagesLabel,
15
+ sitePublicDir,
16
+ sitePublicLabel,
17
+ } from './site-paths.mjs';
18
+ import { getSiteNodePathname } from './site-page-urls.mjs';
19
+ import { getSiteStructure } from './site-structure.mjs';
20
+
21
+ const internalUrlOrigin = 'https://norna.invalid';
22
+ const externalSchemePattern = /^[a-z][a-z0-9+.-]*:/i;
23
+
24
+ const readPublicFiles = async (directory, relativeDirectory = '') => {
25
+ const entries = await readdir(directory, { withFileTypes: true }).catch((error) => {
26
+ if (error?.code === 'ENOENT') return [];
27
+ throw error;
28
+ });
29
+ const files = [];
30
+
31
+ for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name, 'en'))) {
32
+ const relativePath = relativeDirectory
33
+ ? path.join(relativeDirectory, entry.name)
34
+ : entry.name;
35
+ const entryPath = path.join(directory, entry.name);
36
+ if (entry.isDirectory()) {
37
+ files.push(...await readPublicFiles(entryPath, relativePath));
38
+ } else if (entry.isFile()) {
39
+ files.push({
40
+ filePath: entryPath,
41
+ label: `${sitePublicLabel}/${toPosixPath(relativePath)}`,
42
+ pathname: `/${toPosixPath(relativePath)}`,
43
+ });
44
+ }
45
+ }
46
+
47
+ return files;
48
+ };
49
+
50
+ const decodePathname = (pathname) => {
51
+ const decodedSegments = pathname.split('/').map((segment) => decodeURIComponent(segment));
52
+ if (decodedSegments.some((segment) => segment.includes('/') || segment.includes('\\') || segment.includes('\0'))) {
53
+ throw new Error('Encoded slashes, backslashes, and null bytes are not valid internal paths.');
54
+ }
55
+ return decodedSegments.join('/');
56
+ };
57
+
58
+ const decodeFragment = (fragment) => decodeURIComponent(fragment);
59
+
60
+ const getPageLookupPathname = (pathname) => {
61
+ if (pathname === '/' || pathname === '/index.html') return '/';
62
+ if (pathname.endsWith('/index.html')) return pathname.slice(0, -'index.html'.length);
63
+ if (pathname.endsWith('/')) return pathname;
64
+ const finalSegment = pathname.split('/').at(-1) ?? '';
65
+ return finalSegment.includes('.') ? null : `${pathname}/`;
66
+ };
67
+
68
+ const isExternalTarget = (target) => target.startsWith('//') || externalSchemePattern.test(target);
69
+
70
+ export const resolveInternalTarget = (target, sourcePathname) => {
71
+ if (isExternalTarget(target)) return { kind: 'external' };
72
+
73
+ let url;
74
+ try {
75
+ url = new URL(target, `${internalUrlOrigin}${sourcePathname}`);
76
+ } catch {
77
+ return {
78
+ kind: 'invalid',
79
+ reason: 'The target is not a valid relative or site-relative URL.',
80
+ };
81
+ }
82
+
83
+ if (url.origin !== internalUrlOrigin) return { kind: 'external' };
84
+
85
+ try {
86
+ const pathname = decodePathname(url.pathname);
87
+ const fragment = url.hash.length > 1 ? decodeFragment(url.hash.slice(1)) : '';
88
+ return {
89
+ kind: 'internal',
90
+ fragment,
91
+ pageLookupPathname: getPageLookupPathname(pathname),
92
+ pathname,
93
+ query: url.search,
94
+ };
95
+ } catch (error) {
96
+ return {
97
+ kind: 'invalid',
98
+ reason: error instanceof Error ? error.message : String(error),
99
+ };
100
+ }
101
+ };
102
+
103
+ const createPageRecord = ({ contentFile, data = {}, document }) => {
104
+ const pathname = getSiteNodePathname(contentFile);
105
+ const anchors = new Map([['page-title', {
106
+ id: 'page-title',
107
+ line: document.pageTitle?.line ?? 1,
108
+ title: document.pageTitle?.title ?? 'Page title',
109
+ }]]);
110
+
111
+ for (const heading of document.headings) {
112
+ if ((heading.depth !== 2 && heading.depth !== 3) || !heading.id || anchors.has(heading.id)) continue;
113
+ anchors.set(heading.id, heading);
114
+ }
115
+
116
+ return {
117
+ aliases: data.page?.aliases ?? [],
118
+ anchors,
119
+ contentFile,
120
+ document,
121
+ navigation: {
122
+ listed: data.navigation?.listed ?? true,
123
+ },
124
+ pathname,
125
+ title: document.pageTitle?.title ?? contentFile.pageId,
126
+ };
127
+ };
128
+
129
+ const createIssue = (reference, code, message, fix) => ({
130
+ code,
131
+ fix,
132
+ message,
133
+ reference,
134
+ severity: 'error',
135
+ });
136
+
137
+ const getTargetKey = ({ fragment, pageLookupPathname, pathname }) => {
138
+ const identityPathname = pageLookupPathname ?? pathname;
139
+ return `${identityPathname}${fragment ? `#${fragment}` : ''}`;
140
+ };
141
+
142
+ const looksLikePublicFile = (pathname) => {
143
+ if (pathname.endsWith('/')) return false;
144
+ return (pathname.split('/').at(-1) ?? '').includes('.');
145
+ };
146
+
147
+ export const createSiteLinkGraph = ({
148
+ siteStructure,
149
+ pageDocuments,
150
+ publicFiles = [],
151
+ generatedRoutes,
152
+ }) => {
153
+ const activeGeneratedRoutes = generatedRoutes ?? generatedSiteRoutes;
154
+ const documentsByDirectory = new Map(pageDocuments.map(({ contentFile, data, document }) => [
155
+ contentFile.pageDirectory,
156
+ { contentFile, data, document },
157
+ ]));
158
+ const pages = siteStructure.contentFiles.map((contentFile) => {
159
+ const pageDocument = documentsByDirectory.get(contentFile.pageDirectory);
160
+ if (!pageDocument) throw new Error(`No parsed Markdown document was provided for ${contentFile.contentLabel}.`);
161
+ return createPageRecord(pageDocument);
162
+ });
163
+ const pagesByPathname = new Map(pages.map((page) => [page.pathname, page]));
164
+ const categoriesByPathname = new Map(siteStructure.categories.map((category) => [
165
+ getSiteNodePathname(category),
166
+ { ...category, pathname: getSiteNodePathname(category) },
167
+ ]));
168
+ const publicFilesByPathname = new Map();
169
+ for (const file of publicFiles) {
170
+ publicFilesByPathname.set(file.pathname, file);
171
+ if (file.pathname === '/index.html') publicFilesByPathname.set('/', file);
172
+ if (file.pathname.endsWith('/index.html')) {
173
+ publicFilesByPathname.set(file.pathname.slice(0, -'index.html'.length), file);
174
+ }
175
+ }
176
+ const aliasModel = createPageAliasModel({
177
+ categories: siteStructure.categories,
178
+ pages,
179
+ publicFiles,
180
+ generatedRoutes: activeGeneratedRoutes,
181
+ });
182
+ const generatedRoutesByPathname = new Map(
183
+ activeGeneratedRoutes.map((route) => [route.pathname, route]),
184
+ );
185
+
186
+ const references = [];
187
+ const referencesByTarget = new Map();
188
+ const diagnostics = [...aliasModel.diagnostics];
189
+
190
+ for (const page of pages) {
191
+ for (const sourceReference of page.document.links) {
192
+ const target = resolveInternalTarget(sourceReference.target, page.pathname);
193
+ if (target.kind === 'external') continue;
194
+
195
+ const reference = {
196
+ ...sourceReference,
197
+ sourceContentFile: page.contentFile,
198
+ sourcePage: page,
199
+ target,
200
+ };
201
+ references.push(reference);
202
+
203
+ if (target.kind === 'invalid') {
204
+ diagnostics.push(createIssue(
205
+ reference,
206
+ 'invalid-internal-url',
207
+ `Internal link "${sourceReference.target}" on line ${sourceReference.line} is invalid. ${target.reason}`,
208
+ 'Use a valid fragment, relative URL, site-relative URL, or external URL.',
209
+ ));
210
+ continue;
211
+ }
212
+
213
+ const targetKey = getTargetKey(target);
214
+ if (!referencesByTarget.has(targetKey)) referencesByTarget.set(targetKey, []);
215
+ referencesByTarget.get(targetKey).push(reference);
216
+
217
+ const targetPage = target.pageLookupPathname
218
+ ? pagesByPathname.get(target.pageLookupPathname)
219
+ : null;
220
+ if (targetPage) {
221
+ reference.resolution = { kind: 'page', page: targetPage, pathname: targetPage.pathname };
222
+ if (target.fragment && !targetPage.anchors.has(target.fragment)) {
223
+ const availableAnchors = Array.from(targetPage.anchors.keys());
224
+ const displayedAnchors = availableAnchors.slice(0, 8).map((anchor) => `#${anchor}`);
225
+ const omittedCount = availableAnchors.length - displayedAnchors.length;
226
+ diagnostics.push(createIssue(
227
+ reference,
228
+ 'missing-internal-anchor',
229
+ `Internal link "${sourceReference.target}" on line ${sourceReference.line} points to missing heading anchor "#${target.fragment}" on ${targetPage.pathname}.`,
230
+ availableAnchors.length > 0
231
+ ? `Use an existing anchor: ${displayedAnchors.join(', ')}${omittedCount > 0 ? `, and ${omittedCount} more` : ''}.`
232
+ : 'Add the intended H2 or H3 heading, or remove the fragment from the link.',
233
+ ));
234
+ }
235
+ continue;
236
+ }
237
+
238
+ const targetAlias = target.pageLookupPathname
239
+ ? aliasModel.aliasesByPathname.get(target.pageLookupPathname)
240
+ : null;
241
+ if (targetAlias) {
242
+ const aliasTargetPage = pagesByPathname.get(targetAlias.targetPathname);
243
+ if (!aliasTargetPage) {
244
+ throw new Error(`Page alias "${targetAlias.pathname}" has no target page ${targetAlias.targetPathname}.`);
245
+ }
246
+ reference.resolution = {
247
+ alias: targetAlias,
248
+ kind: 'page-alias',
249
+ page: aliasTargetPage,
250
+ pathname: aliasTargetPage.pathname,
251
+ };
252
+ if (target.fragment && !aliasTargetPage.anchors.has(target.fragment)) {
253
+ const availableAnchors = Array.from(aliasTargetPage.anchors.keys());
254
+ diagnostics.push(createIssue(
255
+ reference,
256
+ 'missing-internal-anchor',
257
+ `Internal link "${sourceReference.target}" on line ${sourceReference.line} points through alias ${targetAlias.pathname} to missing heading anchor "#${target.fragment}" on ${aliasTargetPage.pathname}.`,
258
+ availableAnchors.length > 0
259
+ ? `Use an existing anchor: ${availableAnchors.slice(0, 8).map((anchor) => `#${anchor}`).join(', ')}.`
260
+ : 'Add the intended H2 or H3 heading, or remove the fragment from the link.',
261
+ ));
262
+ }
263
+ continue;
264
+ }
265
+
266
+ const generatedRoute = generatedRoutesByPathname.get(
267
+ target.pageLookupPathname ?? target.pathname,
268
+ );
269
+ if (generatedRoute && !target.fragment) {
270
+ reference.resolution = {
271
+ kind: 'generated-route',
272
+ pathname: generatedRoute.pathname,
273
+ route: generatedRoute,
274
+ };
275
+ continue;
276
+ }
277
+
278
+ const targetCategory = target.pageLookupPathname
279
+ ? categoriesByPathname.get(target.pageLookupPathname)
280
+ : null;
281
+ if (targetCategory) {
282
+ reference.resolution = { category: targetCategory, kind: 'category', pathname: targetCategory.pathname };
283
+ diagnostics.push(createIssue(
284
+ reference,
285
+ 'category-has-no-url',
286
+ `Internal link "${sourceReference.target}" on line ${sourceReference.line} points to navigation category ${targetCategory.pathname}, which does not have its own page.`,
287
+ 'Link to one of the category pages, or replace category.yaml with content.md when the collection needs its own page.',
288
+ ));
289
+ continue;
290
+ }
291
+
292
+ const publicFile = publicFilesByPathname.get(target.pathname);
293
+ if (publicFile) {
294
+ reference.resolution = { file: publicFile, kind: 'public-file', pathname: target.pathname };
295
+ continue;
296
+ }
297
+
298
+ if (looksLikePublicFile(target.pathname)) {
299
+ reference.resolution = { kind: 'missing-public-file', pathname: target.pathname };
300
+ diagnostics.push(createIssue(
301
+ reference,
302
+ 'missing-public-file',
303
+ `Internal link "${sourceReference.target}" on line ${sourceReference.line} points to public file "${target.pathname}", but no matching file exists under ${sitePublicLabel}/.`,
304
+ `Add the file under ${sitePublicLabel}/ with the same relative path, or correct the link.`,
305
+ ));
306
+ continue;
307
+ }
308
+
309
+ const missingPathname = target.pageLookupPathname ?? target.pathname;
310
+ reference.resolution = { kind: 'missing-page', pathname: missingPathname };
311
+ diagnostics.push(createIssue(
312
+ reference,
313
+ 'missing-internal-page',
314
+ `Internal link "${sourceReference.target}" on line ${sourceReference.line} points to page "${missingPathname}", but that page does not exist.`,
315
+ `Correct the link or create the page at the intended position under ${sitePagesLabel}/.`,
316
+ ));
317
+ }
318
+ }
319
+
320
+ return {
321
+ aliasModel,
322
+ aliases: aliasModel.aliases,
323
+ aliasesByPathname: aliasModel.aliasesByPathname,
324
+ categoriesByPathname,
325
+ diagnostics,
326
+ pages,
327
+ pagesByPathname,
328
+ publicFilesByPathname,
329
+ references,
330
+ referencesByTarget,
331
+ };
332
+ };
333
+
334
+ export const getSiteLinkGraph = async (options = {}) => {
335
+ const siteStructure = options.siteStructure ?? await getSiteStructure();
336
+ const [pageDocuments, publicFiles] = await Promise.all([
337
+ Promise.all(siteStructure.contentFiles.map(async (contentFile) => {
338
+ const source = await readFile(contentFile.contentPath, 'utf8');
339
+ const { frontmatterBody } = splitSiteFile(source, contentFile.contentLabel);
340
+ return {
341
+ contentFile,
342
+ data: parseContentFrontmatter(frontmatterBody, contentFile.contentLabel),
343
+ document: await parsePageMarkdownSource(source, { label: contentFile.contentLabel }),
344
+ };
345
+ })),
346
+ readPublicFiles(options.publicDir ?? sitePublicDir),
347
+ ]);
348
+
349
+ return createSiteLinkGraph({
350
+ pageDocuments,
351
+ publicFiles,
352
+ siteStructure,
353
+ generatedRoutes: options.generatedRoutes,
354
+ });
355
+ };
356
+
357
+ export const getSitePublicFiles = async (publicDir = sitePublicDir) => readPublicFiles(publicDir);
@@ -0,0 +1,85 @@
1
+ export const getSiteNavigationTree = (entries) => {
2
+ const nodes = new Map();
3
+ const roots = [];
4
+
5
+ for (const entry of entries) {
6
+ nodes.set(entry.node.pagePath, { ...entry, children: [] });
7
+ }
8
+
9
+ for (const entry of entries) {
10
+ const node = nodes.get(entry.node.pagePath);
11
+ if (!node) continue;
12
+
13
+ if (entry.node.isHome || entry.node.parentPagePath === null) {
14
+ roots.push(node);
15
+ continue;
16
+ }
17
+
18
+ const parent = nodes.get(entry.node.parentPagePath);
19
+ if (!parent) {
20
+ throw new Error(`Site node "${entry.node.pagePath}" has no parent node "${entry.node.parentPagePath}".`);
21
+ }
22
+
23
+ parent.children.push(node);
24
+ }
25
+
26
+ return roots;
27
+ };
28
+
29
+ export const getListedSiteNavigationTree = (entries) => {
30
+ const filterListed = (nodes) => nodes.flatMap((node) => {
31
+ if (!node.node.isHome && !node.node.navigation.listed) return [];
32
+ const children = filterListed(node.children);
33
+ if (node.node.kind === 'category' && children.length === 0) return [];
34
+ return [{ ...node, children }];
35
+ });
36
+
37
+ return filterListed(getSiteNavigationTree(entries));
38
+ };
39
+
40
+ export const getFirstPageInNavigationNode = (node) => {
41
+ if (node.node.kind === 'page') return node.node;
42
+
43
+ for (const child of node.children) {
44
+ const page = getFirstPageInNavigationNode(child);
45
+ if (page) return page;
46
+ }
47
+
48
+ return null;
49
+ };
50
+
51
+ export const flattenSiteNavigationTree = (nodes) => nodes.flatMap((node) => [
52
+ node,
53
+ ...flattenSiteNavigationTree(node.children),
54
+ ]);
55
+
56
+ export const getSequentialPageNavigation = (nodes, currentPagePath) => {
57
+ const activeRoot = nodes.find((root) => (
58
+ flattenSiteNavigationTree([root]).some(({ node }) => node.pagePath === currentPagePath)
59
+ ));
60
+ if (!activeRoot) return { previous: null, next: null };
61
+
62
+ const pages = flattenSiteNavigationTree([activeRoot])
63
+ .filter(({ node }) => node.kind === 'page')
64
+ .map(({ node }) => node);
65
+ const currentIndex = pages.findIndex(({ pagePath }) => pagePath === currentPagePath);
66
+ if (currentIndex < 0) return { previous: null, next: null };
67
+
68
+ return {
69
+ previous: pages[currentIndex - 1] ?? null,
70
+ next: pages[currentIndex + 1] ?? null,
71
+ };
72
+ };
73
+
74
+ export const getDirectChildPages = (nodes, currentPagePath) => {
75
+ const current = flattenSiteNavigationTree(nodes)
76
+ .find(({ node }) => node.pagePath === currentPagePath);
77
+ if (!current) return [];
78
+ const children = current.node.isHome
79
+ ? nodes.filter(({ node }) => !node.isHome)
80
+ : current.children;
81
+
82
+ return children
83
+ .filter(({ node }) => node.kind === 'page')
84
+ .map(({ node }) => node);
85
+ };
@@ -0,0 +1,10 @@
1
+ export const getSiteNodePathname = (node) => node.isHome || !node.pagePath
2
+ ? '/'
3
+ : `/${node.pagePath}/`;
4
+
5
+ export const getAbsolutePageUrl = (siteUrl, pathname) => {
6
+ const baseUrl = new URL(siteUrl);
7
+ if (!baseUrl.pathname.endsWith('/')) baseUrl.pathname = `${baseUrl.pathname}/`;
8
+
9
+ return new URL(pathname === '/' ? '' : pathname.replace(/^\//, ''), baseUrl).href;
10
+ };
@@ -0,0 +1,34 @@
1
+ import { getAbsolutePageUrl, getSiteNodePathname } from './site-page-urls.mjs';
2
+
3
+ export const sitemapFilename = 'sitemap.xml';
4
+
5
+ const escapeXml = (value) => String(value)
6
+ .replaceAll('&', '&amp;')
7
+ .replaceAll('<', '&lt;')
8
+ .replaceAll('>', '&gt;')
9
+ .replaceAll('"', '&quot;')
10
+ .replaceAll("'", '&apos;');
11
+
12
+ const compareStrings = (left, right) => left < right ? -1 : left > right ? 1 : 0;
13
+
14
+ export const getSitemapUrls = ({ siteStructure, siteUrl }) => (
15
+ siteStructure.contentFiles
16
+ .map((page) => getSiteNodePathname(page))
17
+ .sort(compareStrings)
18
+ .map((pathname) => getAbsolutePageUrl(siteUrl, pathname))
19
+ );
20
+
21
+ export const createSitemapXml = (options) => {
22
+ const urls = getSitemapUrls(options);
23
+ const lines = [
24
+ '<?xml version="1.0" encoding="UTF-8"?>',
25
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
26
+ ];
27
+
28
+ for (const url of urls) {
29
+ lines.push(' <url>', ` <loc>${escapeXml(url)}</loc>`, ' </url>');
30
+ }
31
+
32
+ lines.push('</urlset>');
33
+ return `${lines.join('\n')}\n`;
34
+ };
@@ -0,0 +1,30 @@
1
+ import { getPublicAssetInspection } from './logo-assets.mjs';
2
+ import {
3
+ socialImageAssetDefinitions,
4
+ socialImageAssetFilenames,
5
+ } from './public-asset-conventions.mjs';
6
+ import { sitePublicLabel } from './site-paths.mjs';
7
+
8
+ const definitionsByFilename = new Map(
9
+ socialImageAssetDefinitions.map((definition) => [definition.filename, definition]),
10
+ );
11
+
12
+ export const getSocialImageAssets = () => getPublicAssetInspection().socialImages
13
+ .map((filename) => ({
14
+ ...definitionsByFilename.get(filename),
15
+ filename,
16
+ href: `/${filename}`,
17
+ }));
18
+
19
+ export const getSocialImageAsset = () => {
20
+ const assets = getSocialImageAssets();
21
+
22
+ if (assets.length > 1) {
23
+ throw new Error([
24
+ `Found multiple social sharing images in ${sitePublicLabel}. Keep exactly one of ${socialImageAssetFilenames.join(', ')}.`,
25
+ ...assets.map(({ filename }) => `- ${sitePublicLabel}/${filename}`),
26
+ ].join('\n'));
27
+ }
28
+
29
+ return assets[0] ?? null;
30
+ };
@@ -4,7 +4,7 @@ import { resolveThemeProfileRecipe } from './theme-profiles.mjs';
4
4
 
5
5
  export const themePresetRecipes = Object.freeze({
6
6
  portfolio: Object.freeze({
7
- color: 'near-monochrome-dark',
7
+ color: 'near-monochrome-adaptive',
8
8
  typography: 'restrained-sans',
9
9
  rhythm: 'balanced',
10
10
  geometry: 'image-led',
@@ -50,25 +50,25 @@ export const themePresetDefinitions = Object.freeze({
50
50
  title: 'Portfolio',
51
51
  description: 'For portfolios and image-led sites, with restrained typography and generous space for images.',
52
52
  recipe: themePresetRecipes.portfolio,
53
- readerControls: Object.freeze({ colorMode: true }),
53
+ readerControls: Object.freeze({ appearance: true }),
54
54
  }),
55
55
  documentation: Object.freeze({
56
56
  title: 'Documentation',
57
57
  description: 'For guides and reference material, with reading-focused typography and compact spacing.',
58
58
  recipe: themePresetRecipes.documentation,
59
- readerControls: Object.freeze({ colorMode: true, focusReading: true }),
59
+ readerControls: Object.freeze({ appearance: true, focusReading: true }),
60
60
  }),
61
61
  project: Object.freeze({
62
62
  title: 'Project',
63
63
  description: 'For project and product sites that balance explanation, code, cards, and images.',
64
64
  recipe: themePresetRecipes.project,
65
- readerControls: Object.freeze({ colorMode: true, focusReading: true }),
65
+ readerControls: Object.freeze({ appearance: true, focusReading: true }),
66
66
  }),
67
67
  statement: Object.freeze({
68
68
  title: 'Statement',
69
69
  description: 'For short, expressive sites, with larger typography, airy spacing, and stronger section emphasis.',
70
70
  recipe: themePresetRecipes.statement,
71
- readerControls: Object.freeze({ colorMode: true }),
71
+ readerControls: Object.freeze({ appearance: true }),
72
72
  }),
73
73
  });
74
74
 
@@ -115,35 +115,56 @@ export const resolveThemeConfig = (theme = {}, sourceLabel = 'theme.yaml') => {
115
115
  const overrides = structuredClone(theme ?? {});
116
116
  delete overrides.preset;
117
117
 
118
- return {
118
+ const resolved = {
119
119
  preset: presetName,
120
120
  ...mergeDeep(getThemePreset(presetName, sourceLabel), overrides),
121
121
  };
122
+
123
+ if (
124
+ overrides.images?.presentation === 'prose-aligned'
125
+ && overrides.images.maxAvailableHeightPercent === undefined
126
+ ) {
127
+ delete resolved.images.maxAvailableHeightPercent;
128
+ }
129
+
130
+ return resolved;
122
131
  };
123
132
 
124
133
  const mergePageThemePart = (base, override, keys) => Object.fromEntries(keys
125
134
  .filter((key) => override?.[key] !== undefined || base?.[key] !== undefined)
126
135
  .map((key) => [key, override?.[key] ?? base?.[key]]));
127
136
 
128
- export const mergePageThemeConfig = (base = {}, override = {}) => ({
129
- ...base,
130
- layout: {
131
- ...(base.layout ?? {}),
132
- ...mergePageThemePart(base.layout, override.layout, ['contentSpacing', 'textWidth']),
133
- },
134
- images: {
137
+ export const mergePageThemeConfig = (base = {}, override = {}) => {
138
+ const images = {
135
139
  ...(base.images ?? {}),
136
140
  ...mergePageThemePart(base.images, override.images, [
141
+ 'presentation',
137
142
  'width',
138
143
  'maxAvailableWidthPercent',
139
144
  'maxAvailableHeightPercent',
140
145
  ]),
141
- },
142
- sections: {
143
- ...(base.sections ?? {}),
144
- ...mergePageThemePart(base.sections, override.sections, ['backgroundPattern']),
145
- },
146
- });
146
+ };
147
+
148
+ if (
149
+ override.images?.presentation === 'prose-aligned'
150
+ && override.images.maxAvailableHeightPercent === undefined
151
+ ) {
152
+ delete images.maxAvailableHeightPercent;
153
+ }
154
+
155
+ return {
156
+ ...base,
157
+ layout: {
158
+ ...(base.layout ?? {}),
159
+ ...mergePageThemePart(base.layout, override.layout, ['contentSpacing', 'textWidth']),
160
+ },
161
+ images,
162
+ sections: {
163
+ ...(base.sections ?? {}),
164
+ ...mergePageThemePart(base.sections, override.sections, ['backgroundPattern']),
165
+ },
166
+ };
167
+ };
147
168
 
148
169
  const quote = (value) => JSON.stringify(value);
149
170
  const responsiveValueLines = (label, value, indent = 2) => {
@@ -158,7 +179,7 @@ const responsiveValueLines = (label, value, indent = 2) => {
158
179
  export const renderThemePresetReference = (presetName, sourceLabel = 'theme.yaml') => {
159
180
  const preset = getThemePreset(presetName, sourceLabel);
160
181
  const metadata = getThemePresetMetadata(presetName);
161
- const { colorMode, readerControls, corners, layout, images, blocks, typography, palette, sections } = preset;
182
+ const { appearance, readerControls, corners, layout, images, blocks, typography, palette, sections } = preset;
162
183
 
163
184
  return [
164
185
  `# Original values for Norna's "${presetName}" theme preset.`,
@@ -169,12 +190,12 @@ export const renderThemePresetReference = (presetName, sourceLabel = 'theme.yaml
169
190
  `preset: ${presetName}`,
170
191
  '',
171
192
  '# Initial appearance. System follows the visitor\'s operating-system preference.',
172
- 'colorMode:',
173
- ` default: ${colorMode.default}`,
193
+ 'appearance:',
194
+ ` default: ${appearance.default}`,
174
195
  '',
175
196
  '# Optional reader controls shown with the always-available reading-width choice.',
176
197
  'readerControls:',
177
- ` colorMode: ${readerControls.colorMode === true}`,
198
+ ` appearance: ${readerControls.appearance === true}`,
178
199
  ` focusReading: ${readerControls.focusReading === true}`,
179
200
  '',
180
201
  '# Alternatives: square, rounded.',
@@ -194,16 +215,23 @@ export const renderThemePresetReference = (presetName, sourceLabel = 'theme.yaml
194
215
  ' # firstSectionTop, headingToBlock, imageGap, and sectionGap.',
195
216
  '',
196
217
  'images:',
218
+ ' # Alternatives: prose-aligned, centered-fit.',
219
+ ` presentation: ${images.presentation}`,
197
220
  ' # width accepts a positive CSS length.',
198
221
  ` width: ${images.width}`,
199
222
  ' # Percent values must be greater than 0 and at most 100.',
200
223
  ...responsiveValueLines('maxAvailableWidthPercent', images.maxAvailableWidthPercent),
201
- ...responsiveValueLines('maxAvailableHeightPercent', images.maxAvailableHeightPercent),
224
+ ...(images.maxAvailableHeightPercent
225
+ ? [
226
+ ' # Viewport-height limits apply only to centered-fit presentation.',
227
+ ...responsiveValueLines('maxAvailableHeightPercent', images.maxAvailableHeightPercent),
228
+ ]
229
+ : []),
202
230
  '',
203
231
  'blocks:',
204
232
  ' cardList:',
205
233
  ' # Alternatives: text, narrow, normal, wide.',
206
- ' # A width written in a norna-card-list block overrides this default.',
234
+ ' # A width written in a card-list block overrides this default.',
207
235
  ` width: ${blocks.cardList.width}`,
208
236
  '',
209
237
  'typography:',