cook-ssg 2.7.0 → 2.9.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 +8 -2
- package/scripts/layouts.js +13 -0
- package/scripts/plugins/apply-template.js +32 -35
- package/scripts/plugins/conditional-sections.js +34 -0
- package/scripts/plugins/process-markdown.js +39 -13
- package/scripts/plugins/repeat-collection.js +68 -6
- package/scripts/plugins/replace-include.js +18 -1
- package/scripts/utils/layouts/check.js +669 -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/serialize.js +155 -0
- package/scripts/utils/layouts/tree.js +522 -0
- package/scripts/utils/layouts/usage.js +140 -0
- package/scripts/utils/layouts/vocabulary.js +87 -0
|
@@ -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
|
+
}
|