cook-ssg 2.6.0 → 2.8.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/bin/cook.js +27 -0
- package/package.json +3 -2
- package/scripts/build.js +26 -3
- package/scripts/dev.js +21 -0
- package/scripts/layouts.js +9 -0
- package/scripts/plugins/apply-base-path.js +2 -1
- package/scripts/plugins/apply-template.js +32 -35
- package/scripts/plugins/conditional-sections.js +34 -0
- package/scripts/plugins/copy-src.js +3 -0
- package/scripts/plugins/create-dir-from-file.js +4 -0
- package/scripts/plugins/fingerprint-assets.js +3 -1
- package/scripts/plugins/generate-sitemap-xml.js +3 -0
- package/scripts/plugins/html-collections.js +2 -0
- package/scripts/plugins/optimize-images.js +2 -0
- package/scripts/plugins/process-markdown.js +41 -14
- package/scripts/plugins/programs.js +214 -0
- package/scripts/plugins/repeat-collection.js +68 -6
- package/scripts/plugins/replace-include.js +18 -1
- package/scripts/utils/config/config.js +15 -1
- package/scripts/utils/get-src/get-src.js +6 -2
- package/scripts/utils/layouts/check.js +667 -0
- package/scripts/utils/layouts/conditionals.js +357 -0
- package/scripts/utils/layouts/list.js +182 -0
- package/scripts/utils/layouts/parse.js +133 -0
- package/scripts/utils/layouts/render.js +309 -0
- package/scripts/utils/layouts/vocabulary.js +87 -0
- package/scripts/utils/site-pages/site-pages.js +2 -1
- package/scripts/utils/util/util.js +1 -1
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file render.js
|
|
3
|
+
* @description Render a page through a layout and, for a child layout
|
|
4
|
+
* (`data-template="parent"` on its `<html>` or `<body>`), through each
|
|
5
|
+
* parent in turn.
|
|
6
|
+
*
|
|
7
|
+
* Everything here works on source strings, never on a re-serialized DOM,
|
|
8
|
+
* so a layout's markup reaches the output exactly as the author wrote it.
|
|
9
|
+
* Each layer's pieces are split from the RAW layout source and then filled;
|
|
10
|
+
* filled output is never re-scanned. Page content that contains `<main>`,
|
|
11
|
+
* `<template>`, `<template slot>` or `${...}` is therefore only ever a
|
|
12
|
+
* value, never layout structure (the interpolator never rescans inserted
|
|
13
|
+
* values).
|
|
14
|
+
*
|
|
15
|
+
* A layout with no `data-template` and no info block takes an early exit
|
|
16
|
+
* and renders exactly as before.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import chalk from 'chalk';
|
|
20
|
+
import { renderTemplate } from '../interpolate/interpolate.js';
|
|
21
|
+
|
|
22
|
+
export const MAX_DEPTH = 5;
|
|
23
|
+
|
|
24
|
+
// The exact opening form the old slot regex accepted
|
|
25
|
+
const SLOT_OPEN = /<template\s+slot="([^"]+)">/gi;
|
|
26
|
+
// Any template open or close tag, for depth counting
|
|
27
|
+
const TEMPLATE_TAG = /<(\/?)template(?=[\s>/])[^>]*>/gi;
|
|
28
|
+
|
|
29
|
+
// A child layout: data-template on <html> or <body> (same test as
|
|
30
|
+
// apply-template), its value double-quoted, single-quoted or unquoted.
|
|
31
|
+
// Groups: 1 tag, 2 attributes, 3/4/5 the value in each quoting.
|
|
32
|
+
const TEMPLATED_TAG = /<(html|body)(\s(?:[^>]*?\s)?data-template\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s"'>]+))[^>]*)>/i;
|
|
33
|
+
|
|
34
|
+
// One attribute in a start tag's attribute string, any quoting
|
|
35
|
+
const ATTR = /([^\s"'>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Find the `<html>` or `<body>` start tag carrying data-template.
|
|
39
|
+
* @param {string} src
|
|
40
|
+
* @returns {{ index: number, length: number, name: string, attrs: string }|null}
|
|
41
|
+
* `name` is the template name, `attrs` the tag's attribute string
|
|
42
|
+
*/
|
|
43
|
+
export function findTemplatedTag(src) {
|
|
44
|
+
const m = src.match(TEMPLATED_TAG);
|
|
45
|
+
if (!m) return null;
|
|
46
|
+
return { index: m.index, length: m[0].length, name: m[3] ?? m[4] ?? m[5], attrs: m[2] };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The data-* attributes (data-template excepted) of an attribute string,
|
|
51
|
+
* keyed by camelCase name, values in any quoting.
|
|
52
|
+
* @param {string} attrs
|
|
53
|
+
* @returns {Record<string, string>}
|
|
54
|
+
*/
|
|
55
|
+
export function templateDataAttrs(attrs) {
|
|
56
|
+
const out = {};
|
|
57
|
+
ATTR.lastIndex = 0;
|
|
58
|
+
let m;
|
|
59
|
+
while ((m = ATTR.exec(attrs)) !== null) {
|
|
60
|
+
const attr = m[1].toLowerCase();
|
|
61
|
+
if (!/^data-[a-z][a-z0-9-]*$/.test(attr) || attr === 'data-template') continue;
|
|
62
|
+
const key = attr.slice('data-'.length).replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
63
|
+
out[key] = m[2] ?? m[3] ?? m[4] ?? '';
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The info block element: its body never crosses a `</script`, so the
|
|
69
|
+
// match ends at the info script's own close tag. Leading indent and the
|
|
70
|
+
// trailing line break are captured so a line holding only the block can
|
|
71
|
+
// go whole.
|
|
72
|
+
const INFO = /([ \t]*)<script\b[^>]*\bdata-layout-info\b[^>]*>(?:(?!<\/script)[\s\S])*<\/script\s*>([ \t]*(?:\r?\n|$))?/gi;
|
|
73
|
+
const HAS_INFO = /<script\b[^>]*\bdata-layout-info\b/i;
|
|
74
|
+
|
|
75
|
+
// A `slot` attribute inside a start tag's attributes, any quoting
|
|
76
|
+
const SLOT_ATTR = /(?:^|\s)slot\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/i;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Thrown for a layout cycle or a chain deeper than MAX_DEPTH. Always a
|
|
80
|
+
* build error, whatever kind of page hit it.
|
|
81
|
+
*/
|
|
82
|
+
export class LayoutChainError extends Error {
|
|
83
|
+
constructor(message) {
|
|
84
|
+
super(message);
|
|
85
|
+
this.name = 'LayoutChainError';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Index just past the `</template>` that closes a template opened before
|
|
91
|
+
* `from`, counting nested templates. -1 when it never closes.
|
|
92
|
+
* @param {string} html
|
|
93
|
+
* @param {number} from - Index just after the opening tag
|
|
94
|
+
* @returns {{ innerEnd: number, end: number }|null}
|
|
95
|
+
*/
|
|
96
|
+
function findClose(html, from) {
|
|
97
|
+
let depth = 1;
|
|
98
|
+
TEMPLATE_TAG.lastIndex = from;
|
|
99
|
+
let m;
|
|
100
|
+
while ((m = TEMPLATE_TAG.exec(html))) {
|
|
101
|
+
if (m[1]) depth--;
|
|
102
|
+
else depth++;
|
|
103
|
+
if (depth === 0) return { innerEnd: m.index, end: TEMPLATE_TAG.lastIndex };
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Split top-level `<template slot="x">…</template>` elements out of HTML.
|
|
110
|
+
* Nested `<template>`s inside a slot are kept whole. Without nesting the
|
|
111
|
+
* result is byte-identical to the old non-greedy regex: each slot's inner
|
|
112
|
+
* HTML trimmed, a later slot of the same name winning, and the remaining
|
|
113
|
+
* content trimmed.
|
|
114
|
+
* @param {string} html
|
|
115
|
+
* @returns {{ content: string, slots: Record<string, string> }}
|
|
116
|
+
*/
|
|
117
|
+
export function extractSlots(html) {
|
|
118
|
+
const slots = {};
|
|
119
|
+
let content = '';
|
|
120
|
+
let pos = 0;
|
|
121
|
+
|
|
122
|
+
SLOT_OPEN.lastIndex = 0;
|
|
123
|
+
let open;
|
|
124
|
+
while ((open = SLOT_OPEN.exec(html))) {
|
|
125
|
+
const close = findClose(html, SLOT_OPEN.lastIndex);
|
|
126
|
+
if (!close) continue; // never closed: not a slot, leave it in place
|
|
127
|
+
slots[open[1]] = html.slice(SLOT_OPEN.lastIndex, close.innerEnd).trim();
|
|
128
|
+
content += html.slice(pos, open.index);
|
|
129
|
+
pos = close.end;
|
|
130
|
+
SLOT_OPEN.lastIndex = close.end;
|
|
131
|
+
}
|
|
132
|
+
content += html.slice(pos);
|
|
133
|
+
|
|
134
|
+
return { content: content.trim(), slots };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Remove the info block from layout source.
|
|
139
|
+
* @param {string} html
|
|
140
|
+
* @returns {string}
|
|
141
|
+
*/
|
|
142
|
+
export function stripInfo(html) {
|
|
143
|
+
if (!HAS_INFO.test(html)) return html;
|
|
144
|
+
return html.replace(INFO, (match, lead, trail, offset) => {
|
|
145
|
+
const atLineStart = offset === 0 || html[offset - 1] === '\n';
|
|
146
|
+
// Alone on its line: the whole line goes
|
|
147
|
+
if (atLineStart && trail !== undefined) return '';
|
|
148
|
+
// Shares the line: only the element goes
|
|
149
|
+
return lead + (trail || '');
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Split a child layout's body into its top-level slot templates and the
|
|
155
|
+
* rest. Any top-level `<template …>` with a `slot` attribute counts, in any
|
|
156
|
+
* attribute order and quoting. Each piece is the WHOLE element (opening tag
|
|
157
|
+
* included) so the conditionals hook can see attributes such as `data-if`.
|
|
158
|
+
* @param {string} html
|
|
159
|
+
* @returns {{ body: string, pieces: Array<{ name: string, element: string }> }}
|
|
160
|
+
*/
|
|
161
|
+
export function splitChildSlots(html) {
|
|
162
|
+
const pieces = [];
|
|
163
|
+
let body = '';
|
|
164
|
+
let pos = 0;
|
|
165
|
+
|
|
166
|
+
TEMPLATE_TAG.lastIndex = 0;
|
|
167
|
+
let m;
|
|
168
|
+
while ((m = TEMPLATE_TAG.exec(html))) {
|
|
169
|
+
if (m[1]) continue; // a stray close tag at top level
|
|
170
|
+
const openEnd = TEMPLATE_TAG.lastIndex;
|
|
171
|
+
const close = findClose(html, openEnd);
|
|
172
|
+
if (!close) break; // never closed: leave the rest as body
|
|
173
|
+
const attrs = m[0].slice('<template'.length, -1);
|
|
174
|
+
const slot = attrs.match(SLOT_ATTR);
|
|
175
|
+
if (slot) {
|
|
176
|
+
const name = (slot[1] ?? slot[2] ?? slot[3]).trim();
|
|
177
|
+
if (name) {
|
|
178
|
+
pieces.push({ name, element: html.slice(m.index, close.end) });
|
|
179
|
+
body += html.slice(pos, m.index);
|
|
180
|
+
pos = close.end;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Skip the whole element: templates inside it are not top level
|
|
184
|
+
TEMPLATE_TAG.lastIndex = close.end;
|
|
185
|
+
}
|
|
186
|
+
body += html.slice(pos);
|
|
187
|
+
|
|
188
|
+
return { body: body.trim(), pieces };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The inner HTML of a slot template element, after the conditionals hook
|
|
193
|
+
* has run on it. A hook that removed the element leaves nothing.
|
|
194
|
+
* @param {string} element
|
|
195
|
+
* @returns {string}
|
|
196
|
+
*/
|
|
197
|
+
function innerOf(element) {
|
|
198
|
+
const open = element.match(/^\s*<template\b[^>]*>/i);
|
|
199
|
+
if (!open) return element;
|
|
200
|
+
const close = element.match(/<\/template\s*>\s*$/i);
|
|
201
|
+
return element.slice(open[0].length, close ? close.index : element.length);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Split a child layout's raw source into its parts.
|
|
206
|
+
* @param {string} src
|
|
207
|
+
* @returns {{ parent: string, attrs: Record<string,string>, body: string }|null}
|
|
208
|
+
*/
|
|
209
|
+
function splitChild(src) {
|
|
210
|
+
const tag = findTemplatedTag(src);
|
|
211
|
+
if (!tag) return null;
|
|
212
|
+
|
|
213
|
+
// data-* attributes on the templated element, data-template excepted
|
|
214
|
+
const attrs = templateDataAttrs(tag.attrs);
|
|
215
|
+
|
|
216
|
+
// The body: inside <body> when there is one, else inside <html>
|
|
217
|
+
let body;
|
|
218
|
+
const bodyOpen = src.match(/<body(?:\s[^>]*)?>/i);
|
|
219
|
+
if (bodyOpen) {
|
|
220
|
+
const start = bodyOpen.index + bodyOpen[0].length;
|
|
221
|
+
const end = src.toLowerCase().lastIndexOf('</body');
|
|
222
|
+
body = src.slice(start, end === -1 || end < start ? src.length : end);
|
|
223
|
+
} else {
|
|
224
|
+
const start = tag.index + tag.length;
|
|
225
|
+
const end = src.toLowerCase().lastIndexOf('</html');
|
|
226
|
+
body = src.slice(start, end === -1 || end < start ? src.length : end)
|
|
227
|
+
.replace(/<head(?:\s[^>]*)?>[\s\S]*?<\/head\s*>/i, '');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return { parent: tag.name.trim(), attrs, body: stripInfo(body) };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Render a page through a layout and its parents.
|
|
235
|
+
* @param {string} name - Layout name
|
|
236
|
+
* @param {Object} pageData - Variables, including `content` and `slot:x` keys
|
|
237
|
+
* @param {Object} opts
|
|
238
|
+
* @property {(name: string) => Promise<string|null>} opts.loadLayout
|
|
239
|
+
* @property {Object} [opts.data] - Site data, passed to `conditionals`
|
|
240
|
+
* @property {(html: string, pageData: Object, data: Object) => string} [opts.conditionals]
|
|
241
|
+
* @property {(message: string) => void} [opts.onMissingParent] - Told when a
|
|
242
|
+
* child layout's parent isn't found (the render still returns null).
|
|
243
|
+
* Defaults to a yellow console warning.
|
|
244
|
+
* @property {boolean} [opts.removeUnmatchedSlots=true] - For a plain layout
|
|
245
|
+
* only (no info block, no parent): remove unfilled `${slot:x}`. Layouts in
|
|
246
|
+
* the new format always remove them.
|
|
247
|
+
* @returns {Promise<string|null>} null when `name` (or a parent) is not found
|
|
248
|
+
*/
|
|
249
|
+
export async function renderLayout(name, pageData, opts) {
|
|
250
|
+
return renderChain(name, pageData, opts, []);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function renderChain(name, pageData, opts, chain) {
|
|
254
|
+
const { loadLayout, data = {}, conditionals = (html) => html, removeUnmatchedSlots = true } = opts;
|
|
255
|
+
|
|
256
|
+
if (chain.includes(name)) {
|
|
257
|
+
throw new LayoutChainError(`Layout cycle: ${[...chain, name].join(' → ')}`);
|
|
258
|
+
}
|
|
259
|
+
if (chain.length >= MAX_DEPTH) {
|
|
260
|
+
throw new LayoutChainError(`Layout chain too deep (more than ${MAX_DEPTH}): ${[...chain, name].join(' → ')}`);
|
|
261
|
+
}
|
|
262
|
+
chain = [...chain, name];
|
|
263
|
+
|
|
264
|
+
// Missing (or empty, as callers have always treated it): not found
|
|
265
|
+
const src = await loadLayout(name);
|
|
266
|
+
if (!src) {
|
|
267
|
+
if (chain.length > 1) {
|
|
268
|
+
const child = chain[chain.length - 2];
|
|
269
|
+
let message = `Layout "${child}" extends "${name}", which wasn't found`;
|
|
270
|
+
if (chain.length > 2) message += ` (${chain.join(' → ')})`;
|
|
271
|
+
const warn = opts.onMissingParent || ((m) => console.log(chalk.yellow(` ${m}`)));
|
|
272
|
+
warn(message);
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const child = TEMPLATED_TAG.test(src) ? splitChild(src) : null;
|
|
278
|
+
|
|
279
|
+
// Base (or plain) layout
|
|
280
|
+
if (!child) {
|
|
281
|
+
// Early exit: a plain layout reached directly renders exactly as before
|
|
282
|
+
const plain = chain.length === 1 && !HAS_INFO.test(src);
|
|
283
|
+
const layout = conditionals(stripInfo(src), pageData, data);
|
|
284
|
+
return renderTemplate(layout, pageData, {
|
|
285
|
+
removeUnmatchedSlots: plain ? removeUnmatchedSlots : true,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Child layout: fill each piece of the raw child source, then the parent
|
|
290
|
+
const { body, pieces } = splitChildSlots(child.body);
|
|
291
|
+
const fill = (piece) => renderTemplate(piece, pageData, { removeUnmatchedSlots: true });
|
|
292
|
+
|
|
293
|
+
const parentData = {};
|
|
294
|
+
for (const [key, value] of Object.entries(pageData)) {
|
|
295
|
+
if (!key.startsWith('slot:')) parentData[key] = value;
|
|
296
|
+
}
|
|
297
|
+
for (const [key, value] of Object.entries(child.attrs)) {
|
|
298
|
+
parentData[key] = renderTemplate(value, pageData);
|
|
299
|
+
}
|
|
300
|
+
parentData.content = fill(conditionals(body, pageData, data));
|
|
301
|
+
for (const { name: slot, element } of pieces) {
|
|
302
|
+
// The hook sees the whole <template slot …> element, attributes included
|
|
303
|
+
const rendered = fill(innerOf(conditionals(element, pageData, data)).trim());
|
|
304
|
+
if (rendered.trim()) parentData[`slot:${slot}`] = rendered;
|
|
305
|
+
else delete parentData[`slot:${slot}`];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return renderChain(child.parent, parentData, opts, chain);
|
|
309
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file vocabulary.js
|
|
3
|
+
* @description The fixed vocabulary of format-1 layouts: the format
|
|
4
|
+
* number, the VB page layouts, the document fields, and the element and
|
|
5
|
+
* attribute sets of the block table.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The layout format this Cook reads and checks. */
|
|
9
|
+
export const FORMAT = 1;
|
|
10
|
+
|
|
11
|
+
/** Values VB accepts for `data-page-layout` on `<body>`. */
|
|
12
|
+
export const PAGE_LAYOUTS = [
|
|
13
|
+
'', 'stack', 'sidebar-left', 'sidebar-right', 'holy-grail',
|
|
14
|
+
'app-shell', 'dashboard', 'article', 'landing',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
/** Front-matter keys a document may carry, plus derived fields. */
|
|
18
|
+
export const DOCUMENT_FIELDS = [
|
|
19
|
+
'title', 'description', 'date', 'published', 'updated', 'author', 'tags',
|
|
20
|
+
'image', 'imageAlt', 'theme', 'themeScope', 'layout', 'slug', 'vp_id',
|
|
21
|
+
'url', 'pageLayout',
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/** Elements allowed in a base layout's `<head>`. */
|
|
25
|
+
export const HEAD_ELEMENTS = ['meta', 'link', 'title', 'script', 'style', 'base'];
|
|
26
|
+
|
|
27
|
+
/** Elements allowed in a child's `<template slot="head">`. */
|
|
28
|
+
export const HEAD_SLOT_ELEMENTS = ['meta', 'link', 'script', 'style'];
|
|
29
|
+
|
|
30
|
+
/** Text blocks: static text, fields and inline elements. */
|
|
31
|
+
export const TEXT_ELEMENTS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'small', 'figcaption', 'blockquote'];
|
|
32
|
+
|
|
33
|
+
/** Inline elements allowed inside text blocks. */
|
|
34
|
+
export const INLINE_ELEMENTS = ['a', 'strong', 'em', 'span', 'time', 'br', 'img', 'abbr', 'code'];
|
|
35
|
+
|
|
36
|
+
/** Sectioning elements: containers without needing `data-layout`. */
|
|
37
|
+
export const SECTIONING = ['article', 'aside', 'nav', 'section'];
|
|
38
|
+
|
|
39
|
+
/** Containers that never need `data-layout`: sectioning plus header and footer. */
|
|
40
|
+
export const CONTAINER_ELEMENTS = [...SECTIONING, 'header', 'footer'];
|
|
41
|
+
|
|
42
|
+
/** Elements that may wrap other blocks when they carry `data-layout`. */
|
|
43
|
+
export const LAYOUT_WRAPPERS = ['div', ...CONTAINER_ELEMENTS];
|
|
44
|
+
|
|
45
|
+
/** Menu elements: their children are `li`. */
|
|
46
|
+
export const MENU_ELEMENTS = ['ul', 'ol', 'menu'];
|
|
47
|
+
|
|
48
|
+
/** Image blocks. */
|
|
49
|
+
export const IMAGE_ELEMENTS = ['img', 'picture', 'figure'];
|
|
50
|
+
|
|
51
|
+
/** VB layout custom elements: containers that hold blocks. */
|
|
52
|
+
export const LAYOUT_ELEMENTS = [
|
|
53
|
+
'layout-stack', 'layout-grid', 'layout-cluster', 'layout-sidebar',
|
|
54
|
+
'layout-center', 'layout-cover', 'layout-columns', 'layout-switcher',
|
|
55
|
+
'layout-reel', 'layout-imposter', 'layout-card', 'layout-text',
|
|
56
|
+
'layout-canvas', 'layout-badge',
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
/** Body children of a base layout (besides includes). */
|
|
60
|
+
export const BODY_REGIONS = ['header', 'nav', 'main', 'aside', 'footer'];
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Attributes any block may carry. `aria-*` and `data-*` are allowed by
|
|
64
|
+
* prefix (see `isGlobalAttr`).
|
|
65
|
+
*/
|
|
66
|
+
export const GLOBAL_ATTRS = ['id', 'class', 'role', 'lang', 'dir', 'title', 'hidden'];
|
|
67
|
+
|
|
68
|
+
/** Extra attributes per element, beyond GLOBAL_ATTRS. */
|
|
69
|
+
export const ELEMENT_ATTRS = {
|
|
70
|
+
a: ['href', 'rel', 'target', 'hreflang', 'download', 'type'],
|
|
71
|
+
img: ['src', 'alt', 'width', 'height', 'loading', 'decoding', 'srcset', 'sizes', 'fetchpriority'],
|
|
72
|
+
source: ['src', 'srcset', 'sizes', 'media', 'type', 'width', 'height'],
|
|
73
|
+
time: ['datetime'],
|
|
74
|
+
blockquote: ['cite'],
|
|
75
|
+
ol: ['start', 'reversed', 'type'],
|
|
76
|
+
li: ['value'],
|
|
77
|
+
template: ['slot'],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Is `name` an attribute any block may carry?
|
|
82
|
+
* @param {string} name - lower-case attribute name
|
|
83
|
+
* @returns {boolean}
|
|
84
|
+
*/
|
|
85
|
+
export function isGlobalAttr(name) {
|
|
86
|
+
return GLOBAL_ATTRS.includes(name) || name.startsWith('aria-') || name.startsWith('data-');
|
|
87
|
+
}
|
|
@@ -13,6 +13,7 @@ import { promises as fs } from 'node:fs';
|
|
|
13
13
|
import Util from '../util/util.js';
|
|
14
14
|
import { distPath as defaultDistPath, siteRoot as defaultSiteRoot } from '../config/config.js';
|
|
15
15
|
import { siteRootDir, fileToUrlPath } from '../site-root/site-root.js';
|
|
16
|
+
import { isProgramFile } from '../../plugins/programs.js';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Collect all built index pages with their source and parsed document.
|
|
@@ -25,7 +26,7 @@ export async function collectSitePages(distPathArg = defaultDistPath, siteRootAr
|
|
|
25
26
|
const rootDir = siteRootDir(distPathArg, siteRootArg);
|
|
26
27
|
const htmlFiles = Util.getPaths(rootDir, rootDir, []) || [];
|
|
27
28
|
const indexFiles = htmlFiles.filter(
|
|
28
|
-
f => f.endsWith('/index.html') || f === `${rootDir}/index.html`
|
|
29
|
+
f => (f.endsWith('/index.html') || f === `${rootDir}/index.html`) && !isProgramFile(f, rootDir)
|
|
29
30
|
);
|
|
30
31
|
|
|
31
32
|
const pages = [];
|
|
@@ -746,7 +746,7 @@ function validatePageChange() {
|
|
|
746
746
|
// dependent page stale. Match whole directory segments only: a PAGE
|
|
747
747
|
// named template-strings-demo.html is still a fast-path page change.
|
|
748
748
|
const isBuildOnly = changedDevPage && (/\/(includes?|templates?|components?|layouts?)\//.test(changedDevPage)
|
|
749
|
-
|| /\/config\/theme\.json$/.test(changedDevPage));
|
|
749
|
+
|| /\/config\/(theme|programs)\.json$/.test(changedDevPage));
|
|
750
750
|
// Return true (valid) if it was a page change AND it wasn't a build-only file
|
|
751
751
|
return changedDevPage && !isBuildOnly;
|
|
752
752
|
}
|