vowel 0.6.4 → 0.7.0-beta.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.
Files changed (166) hide show
  1. package/README.md +1 -1
  2. package/bin.js +47 -27
  3. package/cli.js +15 -0
  4. package/config.js +93 -26
  5. package/extractDate.js +70 -6
  6. package/index.js +14 -5
  7. package/package.json +39 -8
  8. package/plugins/assets/index.js +65 -0
  9. package/plugins/atproto/index.js +132 -0
  10. package/plugins/atproto/password.js +71 -0
  11. package/plugins/atproto/publish.js +406 -0
  12. package/plugins/atproto/record.js +144 -0
  13. package/plugins/atproto/rkey.js +54 -0
  14. package/plugins/deploy-cloudflare/index.js +30 -16
  15. package/plugins/fonts/index.js +18 -21
  16. package/plugins/html/assets/bundle-BeK1Hptv.css +21 -0
  17. package/plugins/html/bundle/assets/index-BeK1Hptv.css +21 -0
  18. package/plugins/html/bundle/index.js +21145 -0
  19. package/plugins/html/editor/EditButton.svelte +152 -0
  20. package/plugins/html/editor/Editor.svelte +51 -0
  21. package/plugins/html/editor/Overlays.svelte +6 -0
  22. package/plugins/html/editor/SettingsPanel.svelte +397 -0
  23. package/plugins/html/editor/Toolbar.svelte +644 -0
  24. package/plugins/html/editor/create-session.js +250 -0
  25. package/plugins/html/editor/directives.js +128 -0
  26. package/plugins/html/editor/frontmatter.js +97 -0
  27. package/plugins/html/editor/ingest.js +339 -0
  28. package/plugins/html/editor/main.js +94 -0
  29. package/plugins/html/editor/nodes/Alert.svelte +21 -0
  30. package/plugins/html/editor/nodes/Blockquote.svelte +9 -0
  31. package/plugins/html/editor/nodes/CodeBlock.svelte +19 -0
  32. package/plugins/html/editor/nodes/Embed.svelte +19 -0
  33. package/plugins/html/editor/nodes/Emphasis.svelte +11 -0
  34. package/plugins/html/editor/nodes/Heading.svelte +15 -0
  35. package/plugins/html/editor/nodes/Highlight.svelte +11 -0
  36. package/plugins/html/editor/nodes/Image.svelte +18 -0
  37. package/plugins/html/editor/nodes/InlineCode.svelte +11 -0
  38. package/plugins/html/editor/nodes/Link.svelte +17 -0
  39. package/plugins/html/editor/nodes/List.svelte +15 -0
  40. package/plugins/html/editor/nodes/ListItem.svelte +9 -0
  41. package/plugins/html/editor/nodes/Page.svelte +21 -0
  42. package/plugins/html/editor/nodes/Paragraph.svelte +9 -0
  43. package/plugins/html/editor/nodes/Strikethrough.svelte +11 -0
  44. package/plugins/html/editor/nodes/Strong.svelte +11 -0
  45. package/plugins/html/editor/nodes/ThematicBreak.svelte +9 -0
  46. package/plugins/html/editor/nodes/index.js +18 -0
  47. package/plugins/html/editor/rollup.config.js +35 -0
  48. package/plugins/html/editor/serialize.js +157 -0
  49. package/plugins/html/editor/settings-file.js +83 -0
  50. package/plugins/html/editor/socket.js +202 -0
  51. package/plugins/html/editor/source.js +43 -0
  52. package/plugins/html/image.js +31 -5
  53. package/plugins/html/index.js +430 -458
  54. package/plugins/html/partials.js +299 -0
  55. package/plugins/html/socialLinks.js +67 -0
  56. package/plugins/html/writeRules.js +377 -0
  57. package/plugins/icons/index.js +2 -6
  58. package/plugins/images/index.js +78 -55
  59. package/plugins/markdown/brandColors.js +10 -0
  60. package/plugins/markdown/colorScheme.js +64 -0
  61. package/plugins/markdown/emoji.js +30 -0
  62. package/plugins/markdown/frontmatter.js +253 -0
  63. package/plugins/markdown/index.js +276 -334
  64. package/plugins/markdown/links.js +97 -0
  65. package/plugins/markdown/metadata.js +229 -68
  66. package/plugins/markdown/readRules.js +143 -0
  67. package/plugins/markdown/typography.js +109 -0
  68. package/plugins/markdown/visitor.js +143 -0
  69. package/plugins/publish/index.js +34 -0
  70. package/plugins/robots/agents.js +79 -0
  71. package/plugins/robots/index.js +30 -10
  72. package/plugins/robots/robots.js +48 -0
  73. package/plugins/styles/index.js +111 -18
  74. package/plugins/styles/theme.js +116 -0
  75. package/plugins/urls/index.js +49 -62
  76. package/plugins/urls/urlMetadata.js +246 -0
  77. package/plugins/vectors/index.js +5 -9
  78. package/plugins/xml/entryContent.js +103 -0
  79. package/plugins/xml/index.js +105 -43
  80. package/secretPaths.js +170 -0
  81. package/stylesheets/DefaultStyles.css +367 -437
  82. package/stylesheets/ResetStyles.css +2 -38
  83. package/stylesheets/SyntaxHighlightingStyles.css +36 -4
  84. package/stylesheets/TypographyStyles.css +386 -128
  85. package/systemPaths.js +48 -0
  86. package/utils.js +56 -5
  87. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -73
  88. package/.github/ISSUE_TEMPLATE/config.yml +0 -7
  89. package/docs-source/.cache.json +0 -9
  90. package/docs-source/.obsidian/app.json +0 -3
  91. package/docs-source/.obsidian/appearance.json +0 -3
  92. package/docs-source/.obsidian/core-plugins-migration.json +0 -30
  93. package/docs-source/.obsidian/core-plugins.json +0 -20
  94. package/docs-source/.obsidian/workspace.json +0 -168
  95. package/docs-source/.stackblitzrc +0 -3
  96. package/docs-source/.votive.db +0 -0
  97. package/docs-source/about.md +0 -3
  98. package/docs-source/blog/home.md +0 -5
  99. package/docs-source/blog/url-ui.md +0 -21
  100. package/docs-source/blog.md +0 -5
  101. package/docs-source/docs/.votive.db +0 -0
  102. package/docs-source/docs/deploy.md +0 -67
  103. package/docs-source/docs/file-structure.md +0 -31
  104. package/docs-source/docs/folder-settings.md +0 -23
  105. package/docs-source/docs/home.md +0 -55
  106. package/docs-source/docs/images.md +0 -10
  107. package/docs-source/docs/items.md +0 -13
  108. package/docs-source/docs/pages.md +0 -141
  109. package/docs-source/docs/settings.md +0 -4
  110. package/docs-source/docs/styling.md +0 -34
  111. package/docs-source/docs/taxonomies.md +0 -37
  112. package/docs-source/features/cards.md +0 -7
  113. package/docs-source/features/editing.md +0 -7
  114. package/docs-source/features/emoji.md +0 -7
  115. package/docs-source/features/frontmatter.md +0 -7
  116. package/docs-source/features/lists.md +0 -7
  117. package/docs-source/features/navigation.md +0 -7
  118. package/docs-source/features/rich-previews.md +0 -7
  119. package/docs-source/features/robots.md +0 -7
  120. package/docs-source/features/rss.md +0 -7
  121. package/docs-source/features/sitemap.md +0 -7
  122. package/docs-source/features/speed.md +0 -7
  123. package/docs-source/features/static.md +0 -7
  124. package/docs-source/features/taxonomies.md +0 -7
  125. package/docs-source/home.md +0 -42
  126. package/docs-source/output/about.html +0 -1
  127. package/docs-source/output/blog/url-ui.html +0 -8
  128. package/docs-source/output/blog.html +0 -1
  129. package/docs-source/output/default.css +0 -1
  130. package/docs-source/output/docs/deploy.html +0 -34
  131. package/docs-source/output/docs/file-structure.html +0 -24
  132. package/docs-source/output/docs/folder-settings.html +0 -20
  133. package/docs-source/output/docs/images.html +0 -2
  134. package/docs-source/output/docs/items.html +0 -6
  135. package/docs-source/output/docs/pages.html +0 -101
  136. package/docs-source/output/docs/styling.html +0 -18
  137. package/docs-source/output/docs/taxonomies.html +0 -20
  138. package/docs-source/output/docs.html +0 -28
  139. package/docs-source/output/features/cards.html +0 -1
  140. package/docs-source/output/features/editing.html +0 -1
  141. package/docs-source/output/features/emoji.html +0 -1
  142. package/docs-source/output/features/frontmatter.html +0 -1
  143. package/docs-source/output/features/lists.html +0 -1
  144. package/docs-source/output/features/navigation.html +0 -1
  145. package/docs-source/output/features/rich-previews.html +0 -1
  146. package/docs-source/output/features/robots.html +0 -1
  147. package/docs-source/output/features/rss.html +0 -1
  148. package/docs-source/output/features/sitemap.html +0 -1
  149. package/docs-source/output/features/speed.html +0 -1
  150. package/docs-source/output/features/static.html +0 -1
  151. package/docs-source/output/features/taxonomies.html +0 -1
  152. package/docs-source/output/features.html +0 -1
  153. package/docs-source/output/feed.xml +0 -1
  154. package/docs-source/output/index.html +0 -21
  155. package/docs-source/output/reset.css +0 -1
  156. package/docs-source/output/roadmap.html +0 -87
  157. package/docs-source/output/robots.txt +0 -14
  158. package/docs-source/output/sitemap.xml +0 -16
  159. package/docs-source/output/typography.css +0 -1
  160. package/docs-source/roadmap.md +0 -98
  161. package/docs-source/settings.md +0 -13
  162. package/getMetadata.js +0 -41
  163. package/jsconfig.json +0 -10
  164. package/plugins/markdown/robots.js +0 -18
  165. package/regex.js +0 -36
  166. package/stylesheets/brand-colors.css +0 -119
@@ -1,6 +1,5 @@
1
1
  import path from "node:path"
2
- import openSocket from "voot/client.js"
3
- import rehypeHighlight from "rehype-highlight"
2
+ import { hash } from "node:crypto"
4
3
  import rehypePresetMinify from "rehype-preset-minify"
5
4
  import rehypeStringify from "rehype-stringify"
6
5
  import { fromMarkdown } from 'mdast-util-from-markdown'
@@ -14,31 +13,60 @@ import { gfmTable } from 'micromark-extension-gfm-table'
14
13
  import { gfmTableFromMarkdown } from 'mdast-util-gfm-table'
15
14
  import { h } from 'hastscript'
16
15
  import { readFileSync } from "fs"
17
- import { remove } from "unist-util-remove"
18
16
  import { testURL, testHashtags, createHashtagPage, toTitleCase, hashtagRegexSingle, createImagePaths, imageSizes, imageExts } from "./../../utils.js"
17
+ import extractDate from "./../../extractDate.js"
18
+ import { reservedProperties, hiddenProperties } from "./../markdown/metadata.js"
19
19
  import { toString as hastToString } from 'hast-util-to-string'
20
20
  import { unified } from "unified"
21
- import { EXIT, SKIP, visit } from "unist-util-visit"
22
21
  import toc from "@jsdevtools/rehype-toc"
23
22
  import slug from "rehype-slug"
24
23
  import createDynamicImage from "./image.js"
25
- import { isExternalLinkParagraph } from "../urls/index.js"
24
+ import { listPages } from "./../../utils.js"
25
+ import { themeStylesheets, isVowelStylesheet } from "../styles/theme.js"
26
+ import { displayPath } from "../../secretPaths.js"
27
+ import { socialLinksNav } from "./socialLinks.js"
28
+ import { writeWalk } from "./writeRules.js"
29
+ import { ASIDE_PARTIAL, navPartialPath, backlinksPartialPath, createPartialStubs, expandPartial, withCurrent, partialsProcessor } from "./partials.js"
26
30
 
27
31
  /** @import * as Votive from "votive" */
28
32
  /** @import * as Vowel from "./../../index.js" */
29
33
 
30
34
  const VOWEL_DIR = path.normalize(path.join(import.meta.dirname, "../../"))
31
35
 
36
+ // Compiled from ./editor/main.js via rollup.config.js (`npm run
37
+ // build:editor` from vowel's root) - the Svedit editor and reload client
38
+ // for previewed pages, read once here and inlined into every previewed
39
+ // page. See tasks/desktop-app-architecture.md, Part 3.
40
+ const editorClientScript = readFileSync(path.join(import.meta.dirname, "bundle/index.js"), "utf-8")
41
+
32
42
  /**
33
43
  * @param {array} array
34
44
  * @param {number} num
35
45
  */
36
- function getLast(ancestorArrays, num = 1) {
37
- if (!ancestorArrays) return
38
- if (num > ancestorArrays.length) return
39
- const level = ancestorArrays.at(ancestorArrays.length - num)
40
- if (level && level.length) return level.at(-1)
41
- return getLast(ancestorArrays, num + 1)
46
+ /**
47
+ * The site's name: the root settings.md's `name:`, else the title of the
48
+ * index page - but only an index the author actually wrote. The
49
+ * synthesized one (source null) is a placeholder called "Home" and
50
+ * doesn't name a site. Both reads are tracked, so a page that shows
51
+ * the site title is rebuilt when either changes.
52
+ *
53
+ * Resolved here rather than written back as a setting by the folder
54
+ * pass: a folder hook that reads a label it also writes sees its own
55
+ * previous pass, and the row flipped on every build (see readFolder in
56
+ * plugins/markdown/index.js).
57
+ * @param {any} settings
58
+ * @param {any} api
59
+ * @returns {string | undefined}
60
+ */
61
+ function siteName(settings, api) {
62
+ // The root's own `name:` - index 0 of the cascade - not the nearest
63
+ // folder's: the header names the site, whatever section a page is
64
+ // in. Sections contribute to <title> instead (createTitle).
65
+ const configured = settings.raw("fm_name")?.[0]?.at(-1)
66
+ if (configured) return configured
67
+ const index = api.target("index.html")
68
+ if (!index?.source) return
69
+ return index.metadata.title
42
70
  }
43
71
 
44
72
 
@@ -58,19 +86,7 @@ function makeHeader(metadata, url, api, config) {
58
86
 
59
87
  if (metadata.date) {
60
88
  const date = new Date(metadata.date)
61
- treeMainHead.push(
62
- h("time",
63
- {
64
- datetime: date.toISOString(),
65
- itemprop: "date"
66
- },
67
- date.toLocaleDateString("en-US", {
68
- year: "numeric",
69
- month: "long",
70
- day: "numeric"
71
- })
72
- )
73
- )
89
+ treeMainHead.push(makeTime(date))
74
90
  }
75
91
 
76
92
  if (metadata.image || (metadata.first_image && url)) {
@@ -81,71 +97,142 @@ function makeHeader(metadata, url, api, config) {
81
97
  )
82
98
  }
83
99
 
84
- if (metadata.fm_description) treeMainHead.push(
100
+ if (metadata.description) treeMainHead.push(
85
101
  h("p",
86
102
  {
87
103
  itemprop: "description"
88
104
  },
89
- metadata.fm_description
105
+ metadata.description
90
106
  )
91
107
  )
92
108
 
93
- if (url) return h('a', { href: url }, treeMainHead)
109
+ if (url) return h('a', { href: url }, h('article', treeMainHead))
94
110
 
95
111
  return treeMainHead
96
112
  }
97
113
 
98
- /** @type {Votive.ProcessorWrite} */
99
- function writeFile(target, settings, api, config) {
100
-
101
- /** @param {string} relativePath */
102
- function resolvePath(relativePath) {
103
- if (relativePath.startsWith("./")) {
104
- const dir = path.dirname(target.source)
105
- const sourcePath = path.normalize(path.join(dir, relativePath))
106
- const targetFile = api.targetBySource(sourcePath)
107
- return targetFile.metadata.prettyURL
108
- }
114
+ /**
115
+ * The favicon's MIME type from its extension, for `<link rel=icon>`.
116
+ * @param {string} iconPath
117
+ */
118
+ function iconType(iconPath) {
119
+ const ext = path.extname(iconPath).toLowerCase()
120
+ const types = { ".svg": "image/svg+xml", ".png": "image/png", ".ico": "image/x-icon", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".webp": "image/webp" }
121
+ return types[ext]
122
+ }
123
+
124
+ /** @param {Date} date */
125
+ function makeTime(date) {
126
+ // Every date that reaches here was coerced to ISO at read
127
+ // (frontmatter.js) or produced by extractDate; an Invalid Date would
128
+ // throw in toISOString, so a null child (which hastscript drops) is
129
+ // the guard for a value that arrived some other way.
130
+ if (isNaN(Number(date))) return null
131
+ return h("time",
132
+ {
133
+ datetime: date.toISOString(),
134
+ itemprop: "date"
135
+ },
136
+ date.toLocaleDateString("en-US", {
137
+ year: "numeric",
138
+ month: "long",
139
+ day: "numeric"
140
+ })
141
+ )
142
+ }
143
+
144
+ /**
145
+ * Renders one frontmatter value by its type. Arrays become lists and
146
+ * objects nested description lists, so the shape survives into the HTML
147
+ * and the editor can read it back without being told what it was.
148
+ * @param {unknown} value
149
+ */
150
+ function makeValue(value) {
151
+ if (Array.isArray(value)) {
152
+ return h("ul", value.map(item => h("li", makeValue(item))))
109
153
  }
110
154
 
111
- visit(target.metadata.hastAbstract, { tagName: "a" }, (n, i, p) => {
112
- const resolvedPath = resolvePath(n.properties.href)
113
- if(resolvedPath) n.properties.href = resolvedPath
114
- })
155
+ if (value instanceof Date) return makeTime(value)
115
156
 
116
- const isRoot = target.path === "index.html"
157
+ if (value && typeof value === "object") {
158
+ const rows = Object.entries(value).flatMap(([key, nested]) => {
159
+ return [h("dt", key), h("dd", makeValue(nested))]
160
+ })
161
+ return h("dl", rows)
162
+ }
117
163
 
164
+ if (typeof value !== "string") return String(value)
118
165
 
119
- if (target.metadata.type === "tag") {
120
- if (!target.metadata.tag) return false
166
+ // extractDate returns an Invalid Date for things that merely look
167
+ // date-shaped (a version string, an ISBN), so the guard matters.
168
+ const date = extractDate(value)
169
+ if (date && !isNaN(date)) return makeTime(date)
121
170
 
122
- const pages = api.targets({
123
- recursive: true,
124
- query: {
125
- tags: target.metadata.tag
126
- }
127
- })
171
+ if (testURL(value)) return h("a", { href: value }, value)
172
+
173
+ return value
174
+ }
175
+
176
+ /**
177
+ * The page's own frontmatter, one single-item <dl> per property, rendered
178
+ * as children of <main> beside section#content. Properties vowel handles
179
+ * specially get their own element instead - a bare <time> or <picture>,
180
+ * identified by itemprop - since a description list adds nothing there.
181
+ *
182
+ * Only frontmatter is rendered. Data inferred from the content (a date the
183
+ * author wrote at the top of the page) stays where they put it, marked up
184
+ * in place by the markdown plugin.
185
+ *
186
+ * @param {object} metadata
187
+ * @param {import("votive").PluginAPI} api
188
+ * @param {Votive.VotiveConfig} config
189
+ */
190
+ function makeFrontmatter(metadata, api, config) {
191
+ const handled = ["title", "tagline", "date", "image", "description"]
128
192
 
129
- if (!pages.length) return false
193
+ // hiddenProperties never render: the editor takes frontmatter from
194
+ // the source file, so nothing is lost by leaving a key off the page.
195
+ const properties = (metadata.frontmatter_keys || []).filter(key => {
196
+ return !handled.includes(key) && !hiddenProperties.includes(key)
197
+ })
198
+
199
+ const known = []
200
+
201
+ if (metadata.fm_date) {
202
+ known.push(makeTime(new Date(metadata.fm_date)))
130
203
  }
131
204
 
132
- const { metadata, ...rest } = target
133
- const abstract = metadata.hastAbstract
205
+ if (metadata.fm_image) {
206
+ known.push(createDynamicImage(metadata.fm_image, api, null, true))
207
+ }
134
208
 
135
- // Highlights fenced code blocks in place (adds an `hljs` class plus
136
- // per-token spans to any <code class="language-x">) - run early, before
137
- // treeStyleSheets below, so the stylesheet link can be added only for
138
- // pages that actually end up with a highlighted block.
139
- unified().use(rehypeHighlight).runSync(abstract)
140
-
141
- let hasHighlightedCode = false
142
- visit(abstract, { tagName: "code" }, (node) => {
143
- if (node.properties?.className?.includes("hljs")) {
144
- hasHighlightedCode = true
145
- return EXIT
146
- }
209
+ if (metadata.fm_description) {
210
+ known.push(h("p", { itemprop: "description" }, metadata.fm_description))
211
+ }
212
+
213
+ const generic = properties.map(key => {
214
+ const name = reservedProperties.includes(key) ? key : "fm_" + key
215
+ return h("dl", [h("dt", key), h("dd", makeValue(metadata[name]))])
147
216
  })
148
217
 
218
+ return [...known, ...generic]
219
+ }
220
+
221
+ /** @type {Votive.ProcessorWrite} */
222
+ function writeFile(target, { settings, api, config }) {
223
+
224
+ const isRoot = target.path === "index.html"
225
+
226
+
227
+ // A tag page used to delete itself here when no page carried its tag
228
+ // any more, because nothing retracted a target its creator stopped
229
+ // creating. It is a stub now: it exists exactly while the markdown
230
+ // enumerator still lists that tag, and stops existing - row and file -
231
+ // the moment it does not. No self-deleting targets.
232
+
233
+ const { metadata, ...rest } = target
234
+ const abstract = metadata.hastAbstract
235
+
149
236
  /** @param {string} filePath */
150
237
  function listFolders(filePath) {
151
238
  if (!filePath) return []
@@ -167,86 +254,93 @@ function writeFile(target, settings, api, config) {
167
254
  const ancestorFolders = listFolders(rest.dir)
168
255
  ancestorFolders.unshift("")
169
256
 
170
- const family = [...ancestorFolders, targetAsDir].flatMap(folder => {
171
- // FIXME typing
172
- return api.targets({
173
- folder: Array.isArray(folder) ? path.join(...folder) : folder,
174
- recursive: false,
175
- query: {
176
- "!": {
177
- "|": {
178
- local_menu_item: 0, // FIXME: Change to boolean,
179
- html_file: 0
180
- }
181
- }
182
- }
183
- })
184
- }).filter(({ path, dir }) => {
185
- return path && path !== "tags.html" && dir !== "tags"
186
- })
187
-
188
257
  const treeStyleSheets = []
189
258
 
190
- Object.values(settings.stylesheets).forEach(file => {
191
- if (file) {
192
- file.forEach(sheet => {
193
- const cacheBuster = Math.random().toString(36).slice(2, 10);
259
+ // The theme's built-in sheets come from the settings cascade (the
260
+ // folder pass is their one writer). The project's own come from a
261
+ // listing: every .css target with a source - a file the author wrote,
262
+ // not one vowel generated - in this page's folder and each ancestor,
263
+ // root first so a subfolder's loads after, and overrides, the root's.
264
+ // The chain ends with the page's own name as a folder, because that
265
+ // is the chain its settings cascade uses (votive's pageSettingsFolder:
266
+ // shop.html is the index of shop/, and gets shop/'s sheets). A listing
267
+ // rather than a second writer to the same label: folder membership
268
+ // tracks a sheet appearing or disappearing, which is all a <link>
269
+ // needs. (Order among the two groups is cosmetic: every theme sheet
270
+ // is in an @layer, and an unlayered project sheet wins over any layer
271
+ // wherever it appears.)
272
+ // Vowel's own sheets sit at the root beside the project's, each with
273
+ // a source path (they are stubs), so they are excluded by name:
274
+ // another folder's colors-<key>.css, and syntax-highlighting.css,
275
+ // which is linked below only on pages with code - it used to be
276
+ // picked up here as a project sheet on every page.
277
+ // The nav partial carries this page's folder chain: the header nav's
278
+ // lists and the project stylesheets along it (see partials.js). One
279
+ // read for both; a page whose own name is a folder takes that chain.
280
+ const navPartial = api.target(navPartialPath(targetAsDir)) ?? api.target(navPartialPath(rest.dir))
281
+ const projectSheets = navPartial?.metadata.sheets ?? []
282
+
283
+ // The theme's sheets come from the same function the styles processor
284
+ // enumerates from, so a sheet that is linked is a sheet that exists.
285
+ // This page's theme is its folder's (a theme cascades like any
286
+ // setting); the root's decides which theme gets the plain file names.
287
+ const themeSheets = themeStylesheets(settings.lastNonNull("theme"), settings.raw("theme")?.[0]?.at(-1))
288
+
289
+ // A stub stylesheet has a source path like any other source, so the
290
+ // `sheet.source` test alone no longer separates vowel's sheets from the
291
+ // project's - exclude them by name instead, or every theme sheet would
292
+ // be linked twice.
293
+ const sheets = [...themeSheets, ...projectSheets.map(sheet => sheet.path).filter(sheet => !themeSheets.includes(sheet))]
294
+ const projectHash = new Map(projectSheets.map(sheet => [sheet.path, sheet.hash]))
295
+
296
+ sheets.forEach(sheet => {
297
+ // Content hash, not Math.random() - a random value here changed
298
+ // on every rebuild regardless of whether the CSS actually did,
299
+ // which meant this <link>'s href always differed from the
300
+ // previous build, which meant the live-reload client's head-diff always
301
+ // saw a "change" and always fell back to a full page reload
302
+ // instead of a selective DOM patch. See
303
+ // tasks/css-cache-buster-bug.md. Hashing the raw source (stored
304
+ // at read time, styles/index.js's readCSS) rather than the
305
+ // minified output - the processed CSS isn't persisted back into
306
+ // the database, only written to disk - and lightningcss's
307
+ // transform is deterministic for a fixed target-browser config,
308
+ // so identical raw source always produces identical output.
309
+ // Bonus over Math.random(): api.target() registers a real
310
+ // dependency from this page to the stylesheet it references.
311
+ // A project sheet's hash rode in with the nav partial (one read for
312
+ // the whole chain); a theme sheet's is read here, tracked.
313
+ const cacheBuster = projectHash.has(sheet) ? projectHash.get(sheet) : (api.target(sheet)?.metadata?.hash ?? "")
194
314
  treeStyleSheets.push(
195
315
  h('link', {
196
316
  rel: "stylesheet",
197
317
  href: `/${sheet}?${cacheBuster}`
198
318
  })
199
319
  )
200
- })
201
- }
202
320
  })
203
321
 
204
- if (hasHighlightedCode) {
205
- if (!api.target("syntax-highlighting.css")) {
206
- const syntaxHighlightingStylesPath = path.join(VOWEL_DIR, "stylesheets", "SyntaxHighlightingStyles.css")
207
- const syntaxHighlightingStyles = readFileSync(syntaxHighlightingStylesPath, "utf-8")
208
-
209
- api.createTarget({
210
- path: "syntax-highlighting.css",
211
- abstract: { css: syntaxHighlightingStyles },
212
- metadata: {},
213
- extension: "css"
214
- })
215
- }
216
-
217
- treeStyleSheets.push(
218
- h('link', {
219
- rel: "stylesheet",
220
- href: "/syntax-highlighting.css"
221
- })
222
- )
223
- }
224
-
322
+ // The document title: the page's own title, then every `name:` from
323
+ // the page's folder up to the root, then the page's own tagline,
324
+ // hyphen-delimited - "Hats - Shop - Site - Warm heads". The homepage is
325
+ // the site's front door and shows the site's name and its tagline.
225
326
  function createTitle() {
226
327
  if (isRoot) {
227
- const title = [settings?.title?.[0]?.at(-1) || metadata?.title, settings?.fm_tagline?.[0]?.at(-1)]
328
+ return [site || metadata?.title, metadata?.fm_tagline]
228
329
  .filter(a => a)
229
330
  .join(" - ")
230
-
231
- return title
232
331
  }
233
332
 
234
- // FIXME Check that this works properly
235
- if (metadata.title && settings.title) {
236
- const titles = [metadata.title, ...Object.values(settings.title).flatMap(a => a).reverse()]
237
- return titles.join(" - ")
238
- }
239
-
240
- if (metadata.title || settings.title) {
241
- return metadata.title || getLast(settings.title)
242
- }
243
-
244
- return "Website"
333
+ const names = settings.flat("fm_name").reverse()
334
+ const chain = names.length ? names : (site ? [site] : [])
335
+ const parts = [metadata.title, ...chain, metadata.fm_tagline].filter(a => a)
336
+ return parts.length ? parts.join(" - ") : "Website"
245
337
  }
246
338
 
247
339
 
340
+ const site = siteName(settings, api)
248
341
  const title = createTitle()
249
342
 
343
+
250
344
  const treeHead = h('head', [
251
345
  h('meta', {
252
346
  charset: "UTF-8",
@@ -271,8 +365,8 @@ function writeFile(target, settings, api, config) {
271
365
  ...treeStyleSheets,
272
366
  ])
273
367
 
274
- if (settings.fm_domain?.[0]?.length) {
275
- const settingsDomain = settings.fm_domain[0].at(-1)
368
+ const settingsDomain = settings.lastNonNull("fm_domain")
369
+ if (settingsDomain) {
276
370
  const domain = settingsDomain.startsWith("http")
277
371
  ? settingsDomain
278
372
  : "https://" + settingsDomain
@@ -291,6 +385,16 @@ function writeFile(target, settings, api, config) {
291
385
  )
292
386
  }
293
387
 
388
+ // The page's AT Protocol record, for readers that verify a document
389
+ // against its site (site.standard). Set by the atproto plugin's
390
+ // transform only when the page has a record to point at.
391
+ if (metadata.atUri) {
392
+ treeHead.children.push(h("link", {
393
+ rel: "site.standard.document",
394
+ href: metadata.atUri
395
+ }))
396
+ }
397
+
294
398
  if (metadata.image) {
295
399
  treeHead.children.push(h("meta", {
296
400
  property: "og:image",
@@ -300,73 +404,81 @@ function writeFile(target, settings, api, config) {
300
404
 
301
405
 
302
406
  /* FIXME this could be a section title */
303
- if (settings.title) {
407
+ if (site) {
304
408
  treeHead.children.push(h("meta", {
305
409
  property: "og:site_name",
306
- content: getLast(settings.fm_title)
410
+ content: site
307
411
  }))
308
412
  }
309
413
 
310
- /* FIXME Properly handle this image */
311
- if (settings.icon) {
414
+ // `icon` is a path, everywhere (Sam, Sept 19) - a URL path from the
415
+ // root, resolved at read like `logo` (frontmatter.js). The type is
416
+ // taken from its extension; a browser ignores a wrong one, but a
417
+ // right one lets it pick between several.
418
+ const icon = settings.lastNonNull("fm_icon")
419
+ if (icon) {
312
420
  treeHead.children.push(h("link", {
313
- href: "/" + getLast(settings.icon),
421
+ href: icon,
314
422
  rel: "icon",
315
- type: "image/png"
423
+ type: iconType(icon)
316
424
  }))
317
425
  }
318
426
 
319
- function treeNavItems(navItem) {
320
- return h('li', h('a', {
321
- href: navItem.metadata.prettyURL,
322
- "aria-current": metadata.prettyURL === navItem.metadata.prettyURL ? 'page' : null
323
- }, navItem.metadata.breadcrumb))
324
- }
325
-
326
- function navItemFilter(nav_item) {
327
- return !nav_item.metadata.date
328
- && nav_item.path !== "index.html"
329
- && nav_item.path !== "404.html"
330
- && nav_item.extension === ".html"
331
- && nav_item.path
332
- }
427
+ // The header nav is a partial: the lists for this page's folder chain,
428
+ // computed once per pass by createPartialStubs and rendered once by
429
+ // the partials processor. A page whose own name is a folder (shop.html
430
+ // beside shop/) takes that folder's chain, which ends in its own
431
+ // list; otherwise its folder's. The first lookup may miss - votive
432
+ // tracks the miss, so the page is rebuilt if that folder appears.
433
+ const treeNav = navPartial ? withCurrent(navPartial.metadata.hast, metadata.prettyURL) : h("nav")
333
434
 
334
- function sort_items(a, b) {
335
- if (typeof a === "number" && typeof b === "number") return a - b
336
- if (typeof b === "number") return -1
337
- if (typeof a === "number") return 1
338
- if (a.metadata.breadcrumb && b.metadata.breadcrumb) return String(a.metadata.breadcrumb).localeCompare(String(b.metadata.breadcrumb))
339
- }
435
+ let treeBreadcrumbs = []
340
436
 
341
- function treeNavFolder(navFolder) {
342
- const sorted = navFolder
343
- .filter(navItemFilter)
344
- .toSorted(sort_items)
437
+ /**
438
+ * A folder's crumb, deduced from the path at render time rather than
439
+ * read from a `breadcrumbs` setting the folder pass used to write.
440
+ *
441
+ * The folder pass is gone, and this is a better place for it anyway:
442
+ * the lookup is tracked, so renaming a section's index page restales
443
+ * every page whose breadcrumb names it - which the setting never did.
444
+ *
445
+ * A folder with an index page is a link and takes that page's own
446
+ * breadcrumb. A folder without one is just a label: vowel no longer
447
+ * generates a page per folder, so linking there would 404.
448
+ */
449
+ // A secret folder's target segment is a hash, so its readable name has
450
+ // to come from the page's own *source* path - de-salted, because the
451
+ // source keeps the salt and the salt must never reach the page. The
452
+ // page has one ancestor per target segment and one per source segment,
453
+ // aligned by depth, which is what lets the two be zipped.
454
+ const sourceFolderNames = target.source
455
+ ? displayPath(target.source).split(path.sep).slice(0, -1)
456
+ : []
457
+
458
+ function folderCrumb(folderPath, index) {
459
+ if (!folderPath) {
460
+ const home = api.target("index.html")
461
+ return { label: home?.metadata?.breadcrumb || "Home", href: "/" }
462
+ }
345
463
 
346
- return h('ul', sorted.map(treeNavItems))
464
+ // A folder's index is `<folder>.html`, from an authored `<folder>.md`
465
+ // beside it or the generated stub.
466
+ const indexTarget = api.target(`${folderPath}.html`)
467
+ // index 0 is the root, so ancestor i is source segment i - 1.
468
+ const sourceName = sourceFolderNames[index - 1]
469
+ const label = indexTarget?.metadata?.breadcrumb
470
+ || toTitleCase(sourceName ?? folderPath.split(path.sep).at(-1))
471
+ // folderPath is a stored folder (path.sep); an href is a url.
472
+ return { label, href: indexTarget ? "/" + folderPath.split(path.sep).join("/") : null }
347
473
  }
348
474
 
349
-
350
- const groupedNavs = Object.groupBy(family, ({ dir }) => dir)
351
-
352
- const treeNav = h('nav', Object.entries(groupedNavs)
353
- .sort(([a], [b]) => a.length - b.length)
354
- .map(([k, v]) => treeNavFolder(v))
355
- .filter(folder => folder.children.length)
356
- )
357
-
358
- let treeBreadcrumbs = []
359
-
360
- const breadcrumbs = ancestorFolders
361
- .map((folderPath, index) => [folderPath, settings.breadcrumbs?.[index]?.at(-1)])
362
- .filter(([, label]) => label != null)
363
-
364
475
  treeBreadcrumbs.push(
365
- ...breadcrumbs.map(([folderPath, label]) => {
366
- return h('a', {
367
- href: folderPath ? "/" + folderPath : "/"
368
- }, label)
369
- })
476
+ ...ancestorFolders
477
+ .map(folderCrumb)
478
+ .filter(crumb => crumb.label)
479
+ .map(crumb => crumb.href
480
+ ? h('a', { href: crumb.href }, crumb.label)
481
+ : h('span', crumb.label))
370
482
  )
371
483
 
372
484
  if (!isRoot) {
@@ -378,59 +490,59 @@ function writeFile(target, settings, api, config) {
378
490
  )
379
491
  }
380
492
 
381
- const headerElements = []
382
493
 
383
494
  const homeLink = []
384
495
 
385
- if (settings.fm_logo?.[0]?.length) {
386
- headerElements.push(
387
- h('a#logo', {
388
- href: "/",
389
- "aria-label": "logo",
390
- rel: "home",
391
- "style": `--logo-url: url("/${getLast(settings.fm_logo)}")`
392
- }, h("img", {
393
- src: "/" + getLast(settings.fm_logo),
394
- alt: ""
395
- }))
396
- )
397
- }
398
496
 
399
- if (settings.fm_wordmark && getLast(settings.fm_wordmark)) {
400
- headerElements.push(h("a#wordmark", {
401
- href: "/",
402
- rel: "home"
403
- }, h("img", {
404
- src: "/" + getLast(settings.fm_wordmark)
405
- })))
406
- }
497
+ const logo = settings.lastNonNull("logo")
498
+ const wordmark = settings.lastNonNull("fm_wordmark")
407
499
 
408
- if (settings.title?.[0]?.length) {
409
- headerElements.push(h('a#title', { href: "/", rel: "home" }, getLast(settings.title)))
500
+ const identityElements = []
501
+
502
+ if(logo) {
503
+ identityElements.push(h("img#logo", {
504
+ src: logo,
505
+ "aria-label": "Logo",
506
+ style: `--logo-url: url("${logo}")`,
507
+ alt: ""
508
+ }))
410
509
  }
411
510
 
412
- if (settings.fm_tagline && getLast(settings.fm_tagline)) {
413
- headerElements.push(h('p#tagline', getLast(settings.fm_tagline)))
511
+ if(wordmark) {
512
+ identityElements.push(h("img#wordmark", {
513
+ src: wordmark,
514
+ "aria-label": "Wordmark",
515
+ alt: ""
516
+ }))
414
517
  }
415
518
 
519
+ const identity = h("a", {
520
+ href: "/",
521
+ rel: "home"
522
+ }, [...identityElements, h(null, site)])
523
+
524
+
525
+ // if (site) {
526
+ // headerElements.push(h('a#title', { href: "/", rel: "home" }, site))
527
+ // }
528
+
529
+ // Same list in the header and the footer; a theme shows whichever it
530
+ // wants. Built twice rather than shared: a hast node in two parents
531
+ // would be visited twice by every rehype pass below.
416
532
  const treeHeader = h('header', [
417
- ...headerElements,
418
- treeNav
533
+ identity,
534
+ treeNav,
535
+ socialLinksNav(settings)
419
536
  ])
420
537
 
421
538
 
422
- function testPaths(node, i, p) {
423
- if (node.type !== 'element') return
424
- if (node.tagName !== 'p') return
425
- if (node.children.length !== 1) return
426
- if (!node.children[0]) return
427
- if (!node.children[0].value) return
428
- return Boolean(node.children[0].value.match(/^\/\S*$/))
429
- }
430
-
431
539
  const slugger = unified()
432
540
  .use(slug)
433
541
  .use(toc, {
542
+ // No class per level, item and link: the nesting is the <ol>
543
+ // structure, and `nav[aria-label=Contents]` is the hook. An empty
544
+ // string is how rehype-toc turns each one off.
545
+ cssClasses: { toc: "", list: "", listItem: "", link: "" },
434
546
  customizeTOC: (toc) => {
435
547
  toc.properties = {
436
548
  "aria-label": "Contents"
@@ -442,262 +554,55 @@ function writeFile(target, settings, api, config) {
442
554
 
443
555
  const treeTableOfContents = treeContentSlugged.children.shift()
444
556
 
445
- const treeMainHead = makeHeader(metadata, null, api, config)
557
+ const treeMainHead = makeFrontmatter(metadata, api, config)
446
558
 
447
559
  treeMainHead.push(treeTableOfContents)
448
560
 
449
- visit(abstract, { tagName: "img" }, (node, index, parent) => {
450
- const { src, alt } = node.properties
451
- const image = createDynamicImage(src, api, alt)
452
- if (!image) return
453
- if (index === 0 && parent.children.length > 1) {
454
- const [_, ...caption] = parent.children
455
- parent.children = [
456
- h("figure", [image, h("figcaption", caption)])
457
- ]
458
- } else {
459
- parent.children.splice(index, 1, image)
460
- }
461
- })
462
-
463
- try {
464
- visit(abstract, testPaths, ({ children: [child] }, i, p) => {
465
-
466
- // const recursive = child.value.endsWith("**")
467
- // const many = child.value.endsWith("*")
468
-
469
- const url = new URL(child.value, "thismessage://")
470
- const { dir, base } = path.parse(url.pathname)
471
- const recursive = base === "**"
472
- const many = base === "*" || base === "**"
473
-
474
- if (!many) {
475
- const targetFilePathInfo = path.parse(child.value)
476
- targetFilePathInfo.ext ||= ".html"
477
- delete targetFilePathInfo.base
478
- const targetFilePath = path.relative("/", path.format(targetFilePathInfo))
479
- const target = api.target(targetFilePath)
480
-
481
- if (target) {
482
- const article = h('article', makeHeader(target.metadata, target.metadata.prettyURL, api, config))
483
-
484
- p.children.splice(i, 1, article)
485
-
486
- return SKIP
487
- }
488
-
489
- }
490
-
491
- if (many) {
492
- const folder = path.relative("/", dir)
493
- // const url = new URL(child.value, "thismessage://")
494
- const count = url.searchParams.get("count")
495
- const tag = url.searchParams.get("tag")
496
- const query = tag
497
- ? { tags: tag }
498
- : {}
499
-
500
- const targets = api.targets({
501
- folder,
502
- recursive,
503
- query,
504
- orderBy: { property: "date", direction: "desc" },
505
- limit: count ? Number(count) : undefined
506
- })
507
-
508
- const escapedDir = folder.replace("_", "--").replace(path.sep, "_")
509
- const escapedDirs = escapedDir.split("_").filter(a => a).map((segment, index, array) => {
510
- return "_" + array.slice(0, index + 1).join("_")
511
- })
512
- escapedDirs.unshift("_")
513
- const dirClasses = escapedDirs.join(".")
514
-
515
- const list = h(`ul.${dirClasses}`,
516
- targets.map(target => {
517
- return h('li',
518
- h('article', makeHeader(target.metadata, target.metadata.prettyURL, api, config))
519
- )
520
- })
521
- )
522
-
523
- p.children.splice(i, 1, list)
524
-
525
- return SKIP
526
- }
527
-
528
- })
529
- } catch (e) {
530
- // console.log(JSON.stringify(abstract, null, 2))
531
- }
532
-
533
- try {
534
- visit(abstract, isExternalLinkParagraph, ({ children: [child] }, i, p) => {
535
- const url = child.value
536
- const preview = api.url.get(url)
537
- if (!preview) return
538
-
539
- const card = h('a.link-preview', { href: url, target: "_blank", rel: "noopener noreferrer" }, [
540
- preview.image ? h('img.link-preview-image', { src: preview.image, alt: "" }) : null,
541
- h('span.link-preview-body', [
542
- h('span.link-preview-title', preview.title || url),
543
- preview.description ? h('span.link-preview-description', preview.description) : null
544
- ].filter(Boolean))
545
- ].filter(Boolean))
546
-
547
- p.children.splice(i, 1, card)
548
-
549
- return SKIP
550
- })
551
- } catch (e) {
552
- // console.log(JSON.stringify(abstract, null, 2))
553
- }
554
-
555
- try {
556
- remove(abstract, (n, i, p) => p.type === "root" && n.tagName === "h1")
557
- } catch (e) {
558
- // console.log(JSON.stringify(abstract, null, 2))
561
+ // One walk for everything that renders against other targets, settings
562
+ // or the url store: relative links, wikilinks, icons, code highlighting,
563
+ // images, directives, link previews and alerts. See writeRules.js.
564
+ // After the slugger, so a listing's headings stay out of the contents.
565
+ const walked = { target, api, config, settings, makeHeader, makeTable, highlighted: false }
566
+ writeWalk(abstract, walked)
567
+
568
+ if (walked.highlighted) {
569
+ // syntax-highlighting.css is always declared by the styles processor
570
+ // (a stub); a page only decides whether to link it.
571
+ treeHead.children.push(h('link', { rel: "stylesheet", href: "/syntax-highlighting.css" }))
559
572
  }
560
573
 
561
- // function copyTreeWithoutArticles(tree) {
562
- // if (tree.tagName !== 'article') {
563
- // return {
564
- // type: tree.type,
565
- // tagName: tree.tagName,
566
- // properties: tree.properties,
567
- // children: tree.children?.map(copyTreeWithoutArticles)
568
- // }
569
- // }
570
- // }
571
-
572
-
573
-
574
+ // Who links here: a partial, declared only for a page something links
575
+ // to (see partials.js). Outside section#content, beside the breadcrumbs
576
+ // and the contents, because it is generated: the editor ingests
577
+ // #content and must not see it. A page with no linkers reads a miss,
578
+ // which votive tracks, so the first linker rebuilds it.
579
+ const backlinksPartial = target.source ? api.target(backlinksPartialPath(target.path)) : undefined
580
+ const treeBacklinks = backlinksPartial ? backlinksPartial.metadata.hast : null
574
581
 
575
582
  const treeMain = h('main',
576
583
  {
577
584
  itemscope: true
578
585
  },
579
586
  [
587
+ // The title is main's first child: the one piece of data hoisted out
588
+ // of the content regardless of where the author placed it.
589
+ ...(metadata.title ? [h("h1", metadata.title)] : []),
590
+ // A tagline is the page's, not the site's: under its title.
591
+ ...(metadata.fm_tagline ? [h("p#tagline", metadata.fm_tagline)] : []),
580
592
  h('nav', {
581
593
  'aria-label': 'Breadcrumbs'
582
594
  }, treeBreadcrumbs),
583
595
  treeMainHead,
584
- h('section#content', abstract)
585
- ])
596
+ h('section#content', abstract),
597
+ treeBacklinks
598
+ ].filter(Boolean))
586
599
 
587
- visit(treeMain, (node, index, parent) => {
588
- /* URLs */ if (node.type === "text" && parent.tagName === 'p' && parent.children.length === 1) {
589
- const validURL = testURL(node.value)
590
- if (validURL) {
591
- const metadata = api.url.get(node.value)
592
- if (metadata) {
593
- parent.tagName = "article"
594
- parent.children = [
595
- h("a", { href: node.value },
596
- h("h2", metadata.title)
597
- )
598
- ]
599
- }
600
- }
601
- } /* GFM Alerts */ else if (node.tagName === "blockquote") {
602
- if (node.children[1]
603
- && node.children[1].tagName === "p"
604
- && node.children[1].children.length === 1
605
- && node.children[1].children[0].type === "text"
606
- ) {
607
- const matches = node.children[1].children[0].value.match(/^\[!(\w+)\]$/)
608
-
609
- if (matches) {
610
- const [_, alertLabel] = matches
611
-
612
- node.tagName = "aside"
613
- node.properties = {
614
- class: `alert ${alertLabel.toLowerCase()}`
615
- }
616
-
617
- node.children.splice(0, 2, {
618
- type: "element",
619
- tagName: "h2",
620
- children: [
621
- {
622
- value: toTitleCase(alertLabel),
623
- type: "text"
624
- }
625
- ]
626
- })
627
- }
628
-
629
- }
630
- }
631
- })
632
-
633
- const everything = api.targets({
634
- folder: "",
635
- recursive: true,
636
- }).filter(target => target.path
637
- && target.path.endsWith(".html")
638
- && !target.metadata.date
639
- )
640
-
641
- const homeFile = everything.find(item => item.path === "index.html" && item.dir === "")
642
-
643
- const globalNavItems = everything.filter(item => {
644
- return item.dir === ""
645
- && item.path !== "index.html"
646
- && item.path !== "404.html"
647
- && item.path !== "tags.html"
648
- && item.metadata.global_menu_item !== 0 // FIXME: This data should come back as a boolean, not binary
649
- && item.metadata.html_file !== 0
650
- })
651
- .map(getChildren)
652
-
653
- globalNavItems.unshift(homeFile)
654
-
655
- function getChildren(item) {
656
- const children = everything.filter(child => {
657
- return "/" + child.dir === item.metadata.prettyURL
658
- && child.path !== "index.html"
659
- })
660
-
661
- const populatedChildren = children.length > 0 && children.map(child => {
662
- return getChildren(child)
663
- })
664
-
665
- const node = {
666
- path: "/" + item.path,
667
- metadata: item.metadata
668
- }
669
-
670
- if (populatedChildren) node.children = populatedChildren
671
-
672
- return node
673
- }
674
-
675
- function treeNavItem(item) {
676
- if (item.children) {
677
- return h('li', [
678
- h('a', { href: item.path }, item.metadata.breadcrumb),
679
- treeNavList(item.children)
680
- ])
681
- }
682
-
683
- return h('li',
684
- h('a', { href: item.path }, item.metadata.breadcrumb)
685
- )
686
- }
687
-
688
- function treeNavList(items) {
689
- return h('ul',
690
- items.filter(a => a).map(treeNavItem)
691
- )
692
- }
693
-
694
- const treeGlobalNav = h('nav',
695
- treeNavList(globalNavItems)
696
- )
697
-
698
- const treeAside = h('aside', treeGlobalNav)
600
+ // The aside tree is one partial, the same on every page.
601
+ const asidePartial = api.target(ASIDE_PARTIAL)
602
+ const treeAside = h("aside", asidePartial ? asidePartial.metadata.hast : h("nav", h("ul")))
699
603
 
700
604
  const treeFooter = h('footer', [
605
+ socialLinksNav(settings),
701
606
  h('section#copyright', `© ${new Date().getFullYear()}`),
702
607
  h('section#shoutout', [
703
608
  "Made with ",
@@ -740,6 +645,8 @@ function writeFile(target, settings, api, config) {
740
645
  ]
741
646
  )
742
647
 
648
+ try {
649
+
743
650
  const data = unified()
744
651
  .use(rehypePresetMinify)
745
652
  .use(rehypeStringify)
@@ -749,17 +656,78 @@ function writeFile(target, settings, api, config) {
749
656
  data
750
657
  }
751
658
 
659
+ } catch(e) {
660
+ console.log({ tree, target, e })
661
+ }
752
662
  }
753
663
 
754
664
  /**
755
- * Injects voot's live-reload client into a served HTML page - dev-server
756
- * only, never touches what's written to disk.
665
+ * The table view of a glob directive: one row per page, one column per
666
+ * named property. `title` links to the page, `image` renders it, `date`
667
+ * is a <time>, an array is joined, anything else is text. A property
668
+ * no page has still gets its column - the author asked for it.
669
+ * @param {string[]} classes
670
+ * @param {string[]} properties
671
+ * @param {any[]} targets
672
+ * @param {import("votive").PluginAPI} api
673
+ */
674
+ function makeTable(classes, properties, targets, api) {
675
+ const valueOf = (metadata, name) => metadata[name] ?? metadata["fm_" + name]
676
+
677
+ const cell = (target, name) => {
678
+ const value = valueOf(target.metadata, name)
679
+ if (name === "title") return h("td", h("a", { href: target.metadata.prettyURL }, value ?? target.metadata.prettyURL))
680
+ if (value === undefined || value === null) return h("td")
681
+ if (name === "image") return h("td", createDynamicImage(String(value), api, "") ?? String(value))
682
+ if (name === "date") return h("td", makeTime(new Date(value)))
683
+ if (Array.isArray(value)) return h("td", value.join(", "))
684
+ return h("td", String(value))
685
+ }
686
+
687
+ return h("table", { class: classes }, [
688
+ h("thead", h("tr", properties.map(name => h("th", name)))),
689
+ h("tbody", targets.map(target => h("tr", properties.map(name => cell(target, name)))))
690
+ ])
691
+ }
692
+
693
+ /**
694
+ * Injects votive's live-reload client and the dev-preview save widget into
695
+ * a served HTML page - dev-server only, never touches what's written to
696
+ * disk. This is the one place the CLI's own browser tab and an embedder
697
+ * pointing a native window at the same server (vowel-desktop) actually
698
+ * share UI - it's the same served HTML either way, so there's nothing
699
+ * per-host to build. See tasks/desktop-app-architecture.md, Part 3.
757
700
  * @param {Buffer} body
758
701
  */
759
- function handlePreviewRequest(body) {
702
+ /**
703
+ * What the in-page editor and the settings panel need to save: the
704
+ * page's source path and text, and the root settings.md's. Put into the
705
+ * page here, in the preview only - a served file is never what was
706
+ * written to disk, and the source path of a secret page carries its
707
+ * salt, which is fine in the author's own browser and nowhere else.
708
+ * `settings` is the folder's view; the root slot of `markdown` is the
709
+ * root settings.md, or null when the project has none yet.
710
+ */
711
+ function previewSource(target, settings, config) {
712
+ const rootSettings = settings?.raw?.("markdown")?.[0]
713
+ return {
714
+ path: target?.source ?? null,
715
+ markdown: target?.metadata?.markdown ?? null,
716
+ settings: { path: "settings.md", markdown: rootSettings?.at(-1) ?? null },
717
+ // The in-page editor is not part of 1.0: it mounts only when the
718
+ // dev server was started with `vowel --editor` (config.editor).
719
+ // The client bundle is injected regardless, because it is also
720
+ // the live-reload client.
721
+ editor: config?.editor === true
722
+ }
723
+ }
724
+
725
+ function handlePreviewRequest(body, { target, settings, config } = {}) {
760
726
  const html = body.toString("utf-8")
761
727
  const fileSplit = html.split("</body>")
762
- fileSplit.splice(1, 0, `<script>${openSocket.toString()}\n\nopenSocket()</script>`)
728
+ // "<" escaped so a "</script>" inside the markdown cannot end the tag.
729
+ const source = JSON.stringify(previewSource(target, settings, config)).replaceAll("<", "\\u003c")
730
+ fileSplit.splice(1, 0, `<script type="application/json" id="vowel-source">${source}</script><script type="module">${editorClientScript}</script>`)
763
731
  return fileSplit.join("")
764
732
  }
765
733
 
@@ -773,6 +741,10 @@ function handlePreviewError() {
773
741
  const writeHTML = {
774
742
  extensions: [".html"],
775
743
  format: "text",
744
+ // The partials (header nav per folder, the aside tree) are stubs this
745
+ // processor declares and the partials processor reads.
746
+ createStubs: ({ api }) => createPartialStubs(api),
747
+ expandStubs: expandPartial,
776
748
  writeFile,
777
749
  handlePreviewRequest,
778
750
  handlePreviewError
@@ -782,7 +754,7 @@ const writeHTML = {
782
754
  /** @type {Votive.VotivePlugin} */
783
755
  const vowelWriteHTMLPlugin = {
784
756
  name: "vowel-write-html",
785
- processors: [writeHTML],
757
+ processors: [writeHTML, partialsProcessor],
786
758
  }
787
759
 
788
760
  export default vowelWriteHTMLPlugin