vowel 0.6.3 → 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 (165) hide show
  1. package/README.md +23 -17
  2. package/bin.js +87 -30
  3. package/cli.js +15 -0
  4. package/config.js +102 -16
  5. package/extractDate.js +70 -6
  6. package/index.js +14 -5
  7. package/package.json +42 -7
  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 +92 -0
  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 +104 -0
  53. package/plugins/html/index.js +760 -0
  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 +287 -1274
  64. package/plugins/markdown/links.js +97 -0
  65. package/plugins/markdown/metadata.js +308 -0
  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 -26
  74. package/plugins/styles/theme.js +116 -0
  75. package/plugins/urls/index.js +78 -0
  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 +123 -50
  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 +269 -0
  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/regex.js +0 -36
  165. package/stylesheets/brand-colors.css +0 -119
@@ -0,0 +1,97 @@
1
+ import path from "node:path"
2
+
3
+ /**
4
+ * The pages a page links to, explicitly. Recorded at read as
5
+ * `metadata.links`, and read back at write by every page asking "who
6
+ * links to me?" - that is what a backlink is, and it is a listing,
7
+ * which votive already keeps correct (a filtered listing tracks the
8
+ * labels it filters on, so a page gaining or losing a link restales the
9
+ * pages whose backlinks that changes).
10
+ *
11
+ * **Explicit** is the rule, per Sam. What counts:
12
+ *
13
+ * - a markdown link to a page: `[text](./post.md)` or `[text](/blog/post)`
14
+ * - a bare reference paragraph: a line that is just `/blog/post`
15
+ * - a frontmatter value that is a link: `related: ./post.md`
16
+ *
17
+ * What does not: a glob (`/blog/**` lists pages; it does not link to
18
+ * them), an external url, a fragment, and anything a listing *renders*
19
+ * - the author wrote none of those links, so none of them is a backlink.
20
+ *
21
+ * Two spellings, kept as two: a `./` link resolves to a **source path**
22
+ * (`blog/post.md`), a `/` link is a **target url** (`/blog/post`). The
23
+ * backlinks query matches either against the page's own source path or
24
+ * its prettyURL, so a secret page linked as `./notes##salt.md` gets its
25
+ * backlink by source path and nothing has to know the hash.
26
+ */
27
+
28
+ /** @param {string} value */
29
+ function isGlob(value) {
30
+ return /\*\s*$/.test(value)
31
+ }
32
+
33
+ /**
34
+ * Normalizes one href to a link identifier, or null when it is not a
35
+ * link to a page in this site.
36
+ * @param {string} href - as written
37
+ * @param {string} fromPath - the linking page's source path
38
+ * @returns {string | null}
39
+ */
40
+ function normalizeLink(href, fromPath) {
41
+ if (typeof href !== "string" || !href) return null
42
+
43
+ // Decoded: a link is an href, and toHast would percent-encode a marker
44
+ // in it; the source is stored as the author spelled it.
45
+ let decoded
46
+ try { decoded = decodeURIComponent(href) } catch { return null }
47
+
48
+ if (decoded.startsWith("./") || decoded.startsWith("../")) {
49
+ // A source path may contain the secret marker ("##"), so "#" is not
50
+ // where the path ends. The extension is: a fragment can only follow
51
+ // it. `./notes##salt.md#top` -> `notes##salt.md`; a link with no
52
+ // extension is taken whole.
53
+ const match = decoded.match(/^(.*?\.[a-z0-9]+)(?:[#?].*)?$/i)
54
+ const filePath = match ? match[1] : decoded
55
+ return path.normalize(path.join(path.dirname(fromPath), filePath))
56
+ }
57
+
58
+ // A target url never carries the marker - it is hashed away - so the
59
+ // first "#" or "?" ends it.
60
+ const withoutFragment = decoded.split("#")[0].split("?")[0]
61
+ if (!withoutFragment) return null
62
+
63
+ if (withoutFragment.startsWith("/") && !withoutFragment.startsWith("//")) {
64
+ if (isGlob(withoutFragment)) return null
65
+ // A target url: the prettyURL form, no extension, no trailing slash.
66
+ return withoutFragment.replace(/\.html$/, "").replace(/(.)\/$/, "$1")
67
+ }
68
+
69
+ return null
70
+ }
71
+
72
+ /**
73
+ * The tree's links come from the read walk (readRules.js); this adds the
74
+ * frontmatter's - any declared key whose value is a link - and keeps
75
+ * the list distinct, in order of first appearance.
76
+ * @param {string[]} fromTree - already normalized, from the walk
77
+ * @param {object} metadata - after getMetadata, with frontmatter on it
78
+ * @param {string} fromPath - the linking page's source path
79
+ * @returns {string[]}
80
+ */
81
+ function collectLinks(fromTree, metadata, fromPath) {
82
+ const found = [...fromTree]
83
+ const add = (href) => {
84
+ const link = normalizeLink(href, fromPath)
85
+ if (link && !found.includes(link)) found.push(link)
86
+ }
87
+
88
+ for (const key of metadata.frontmatter_keys || []) {
89
+ const value = metadata[key] ?? metadata[`fm_${key}`]
90
+ const values = Array.isArray(value) ? value : [value]
91
+ values.forEach(v => typeof v === "string" && (v.startsWith("./") || v.startsWith("/")) && add(v))
92
+ }
93
+
94
+ return found
95
+ }
96
+
97
+ export { collectLinks, normalizeLink }
@@ -0,0 +1,308 @@
1
+ import { toString as mdastToString } from 'mdast-util-to-string'
2
+ import extractDate, { dateSpan } from "./../../extractDate.js"
3
+ import { testURL, toTitleCase } from "./../../utils.js"
4
+ import path from "node:path"
5
+ import { displayPath } from "../../secretPaths.js"
6
+ import { coerce, parseFrontmatter, toISODate } from "./frontmatter.js"
7
+
8
+
9
+ /**
10
+ - menu_item: true | false
11
+ - secret_url: true | false
12
+ */
13
+
14
+ // Frontmatter keys that are vowel's own controls rather than content, and
15
+ // so keep their bare name instead of being prefixed.
16
+ /**
17
+ * Frontmatter keys that are recorded in metadata but never rendered into
18
+ * the page. The editor reproduces a file's frontmatter from the source
19
+ * (GET <page>?source), not from what it rendered, so a key can be kept
20
+ * out of the page without being lost on save. `secret_key` is the case
21
+ * that forced it: the page rendered its own key, and the secret URLs of
22
+ * every page sharing that key follow from it.
23
+ */
24
+ /**
25
+ * Frontmatter keys that never render into the page.
26
+ *
27
+ * Empty, and deliberately kept: `secret_key` was the only entry and
28
+ * secrecy is a path property now (see secretPaths.js), but the mechanism
29
+ * costs one filter call and the next key that must not be displayed will
30
+ * want it. See tasks/1-proposed/post-stubs-vowel-followups.md.
31
+ */
32
+ export const hiddenProperties = []
33
+
34
+ export const reservedProperties = [
35
+ "rss_item",
36
+ "sitemap_item",
37
+ "html_file",
38
+ "global_menu_item",
39
+ "local_menu_item",
40
+ "theme",
41
+ "logo",
42
+ "wordmark",
43
+ "breadcrumb"
44
+ ]
45
+
46
+ /**
47
+ * A "#" heading is the page title only in first position (frontmatter
48
+ * aside). Anywhere else it is an ordinary heading and gets demoted to h2
49
+ * by normalizeHeadingLevels.
50
+ * @param {object} tree
51
+ */
52
+ export function findTitleNode(tree) {
53
+ const [first] = tree.children.filter(child => child.type !== "yaml")
54
+ if (!first) return null
55
+ if (first.type !== "heading" || first.depth !== 1) return null
56
+ return first
57
+ }
58
+
59
+ /**
60
+ * Replaces mdast-normalize-headings, which shifts every heading to
61
+ * guarantee a single h1 - a different rule that would fight this one.
62
+ * @param {object} tree
63
+ */
64
+ export function normalizeHeadingLevels(tree) {
65
+ const titleNode = findTitleNode(tree)
66
+
67
+ for (const child of tree.children) {
68
+ if (child.type !== "heading") continue
69
+ if (child === titleNode) continue
70
+ if (child.depth === 1) child.depth = 2
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Marks a recognized date in place so it renders as <time> without moving
76
+ * out of the content. The editor reads the element's text back, so the
77
+ * author's own wording survives the round trip and the markup is simply
78
+ * re-inferred on the next build.
79
+ * @param {object} paragraph
80
+ * @param {Date} date
81
+ */
82
+ function markAsTime(paragraph, date) {
83
+ paragraph.children = [{
84
+ type: "time",
85
+ datetime: date.toISOString(),
86
+ children: paragraph.children
87
+ }]
88
+ }
89
+
90
+ /**
91
+ * Recognizable data that may precede the content. Each block is recorded
92
+ * where the author placed it and never relocated - only the title is
93
+ * hoisted (see findTitleNode). Adding another inferred property later (an
94
+ * ISBN, say) means adding a branch here, not new plumbing.
95
+ *
96
+ * @param {object} block
97
+ * @param {object} metadata
98
+ * @returns {boolean} whether the block was recognizable data
99
+ */
100
+ function recognizeData(block, metadata) {
101
+ if (block.type !== "paragraph") return false
102
+ if (block.children.length !== 1) return false
103
+
104
+ const [child] = block.children
105
+
106
+ if (child.type === "image") {
107
+ metadata.inferred_image = child.url
108
+ metadata.inferred_alt_text = child.alt
109
+ return true
110
+ }
111
+
112
+ const text = mdastToString(block)
113
+
114
+ // A reference or a listing directive (`/blog/post`, `/blog/**`,
115
+ // `./drafts/*`) is an instruction to the html plugin, not prose - it
116
+ // must not become the page's description, which is what a section
117
+ // index's own listing line was doing. Same test as writeRules'
118
+ // directive rule.
119
+ if (child.type === "text" && /^(\/|\.\.?\/)\S*$/.test(text.trim())) return true
120
+
121
+ if (testURL(text)) {
122
+ const url = new URL(text)
123
+ if (text.match(/\.(jpeg|jpg|png)$/)) {
124
+ metadata.inferred_image = url
125
+ } else {
126
+ metadata.inferred_link = url
127
+ }
128
+ return true
129
+ }
130
+
131
+ // A date is a property of the page only when the author wrote it as
132
+ // the whole paragraph and nothing else: one unmarked text node. Bold,
133
+ // italic, a link, or code around it makes it prose that happens to
134
+ // contain a date - the paragraph is saying something, not declaring a
135
+ // field. (Siblings are already excluded by the single-child check
136
+ // above.)
137
+ if (child.type !== "text") return false
138
+
139
+ // And it has to *be* the date, not mention one. mdast hands back
140
+ // "Published on 2026-03-04 by us." as a single text node, so the
141
+ // single-child check above cannot tell that apart from a bare date.
142
+ const span = dateSpan(text)
143
+ if (!span || span.trim() !== text.trim()) return false
144
+
145
+ const date = extractDate(text)
146
+ if (!date) return false
147
+
148
+ // Stored as ISO, like a frontmatter date (frontmatter.js, toISODate):
149
+ // one format in the column, which sorts lexically.
150
+ metadata.inferred_date = toISODate(date)
151
+ markAsTime(block, date)
152
+ return true
153
+ }
154
+
155
+ /**
156
+ * The frontmatter block into metadata, under frontmatter.js's rules:
157
+ * unparseable YAML goes back into the content, and every key vowel
158
+ * reads is checked and coerced, with one error line per problem.
159
+ * @param {object} tree
160
+ * @param {object} node
161
+ * @param {object} metadata
162
+ * @param {string} filePath
163
+ * @param {string} folder - what `./` paths resolve against
164
+ * @param {(message: string) => void} report
165
+ */
166
+ function readFrontmatter(tree, node, metadata, filePath, folder, report) {
167
+ const parsed = parseFrontmatter(tree, node, filePath, report)
168
+ if (!parsed) return
169
+
170
+ const frontmatter = coerce(parsed, filePath, folder, report)
171
+
172
+ for (const key in frontmatter) {
173
+ const name = reservedProperties.includes(key) ? key : "fm_" + key
174
+ metadata[name] = frontmatter[key]
175
+ }
176
+
177
+ // Recorded because presence alone cannot distinguish a property the
178
+ // author wrote from one selectMetadata derived: breadcrumb defaults to
179
+ // the title, and would otherwise render as though it had been declared.
180
+ // The keys as written, so a coerced-away key still counts as declared.
181
+ metadata.frontmatter_keys = Object.keys(parsed)
182
+ }
183
+
184
+ /**
185
+ * @param {object} tree
186
+ * @param {string} filePath - project-relative
187
+ * @param {string | null} targetPath - project-relative, or null for a
188
+ * source that routes nowhere
189
+ * @param {(message: string) => void} [report] - where a problem with the
190
+ * file's frontmatter is told (frontmatter.js); the caller's error log
191
+ */
192
+ function getMetadata(tree, filePath, targetPath, report = () => {}) {
193
+ const metadata = {}
194
+
195
+ const frontmatterNode = tree.children.find(child => child.type === "yaml")
196
+ // Paths resolve against where the page is published - the target's
197
+ // folder, which for a secret folder is the hashed one - or, for a
198
+ // source with no target, where it would have been.
199
+ const folder = path.dirname(targetPath ?? filePath).replace(/^\.$/, "")
200
+ if (frontmatterNode) readFrontmatter(tree, frontmatterNode, metadata, filePath, folder, report)
201
+
202
+ const titleNode = findTitleNode(tree)
203
+ if (titleNode) {
204
+ metadata.inferred_title = mdastToString(titleNode) || toTitleCase(path.parse(filePath).name)
205
+ }
206
+
207
+ // Everything up to the first block that is not recognizable data is
208
+ // metadata; that first block is where the content begins, and it also
209
+ // supplies the description.
210
+ const blocks = tree.children.filter(child => child.type !== "yaml" && child !== titleNode)
211
+
212
+ for (const block of blocks) {
213
+ const recognized = recognizeData(block, metadata)
214
+ if (recognized) continue
215
+
216
+ if (!metadata.fm_description) metadata.inferred_description = mdastToString(block)
217
+ break
218
+ }
219
+
220
+ // The title is the single exception to leaving data in place: it is
221
+ // hoisted out of the content and rendered as main's first child.
222
+ if (titleNode) {
223
+ tree.children.splice(tree.children.indexOf(titleNode), 1)
224
+ }
225
+
226
+ // Through displayPath first: a secret segment carries its salt in the
227
+ // source filename, and inferred_label feeds both `title` and
228
+ // `breadcrumb`. This is the one place a filename becomes text a reader
229
+ // sees, so it is the one place the salt has to be stripped.
230
+ const pathInfo = path.parse(displayPath(filePath))
231
+
232
+ metadata.inferred_label = toTitleCase(pathInfo.name)
233
+
234
+ // What a [[wikilink]] matches, the way Obsidian matches: the filename
235
+ // without its extension, case-insensitively, plus any `aliases:` the
236
+ // author declared. Lowercased here once so the lookup is one equality
237
+ // (writeRules.js, resolveNote).
238
+ metadata.note_key = pathInfo.name.toLowerCase()
239
+ if (Array.isArray(metadata.fm_aliases)) metadata.note_aliases = metadata.fm_aliases.map(alias => String(alias).toLowerCase())
240
+
241
+ if (targetPath) {
242
+ const targetInfo = path.parse(targetPath)
243
+ // Only the root's index.html is `/`; `blog/index.html` is a page
244
+ // called index, at `/blog/index`.
245
+ const name = targetInfo.name === "index" && !targetInfo.dir ? "" : targetInfo.name
246
+ // FIXME the prettyURL should include the preceding slash
247
+ metadata.prettyURL = (new URL(`${targetInfo.dir}/${name}`, "thismessage:/")).pathname
248
+ }
249
+
250
+ selectMetadata(metadata)
251
+
252
+ return metadata
253
+ }
254
+
255
+
256
+
257
+ function selectMetadata(metadata) {
258
+ const date =
259
+ metadata.fm_date
260
+ || metadata.inferred_date
261
+
262
+ if (date) {
263
+ metadata.date = date
264
+ }
265
+
266
+ const title =
267
+ metadata.fm_title
268
+ || metadata.inferred_title
269
+ || metadata.inferred_label
270
+
271
+ if (title) {
272
+ metadata.title = title
273
+ }
274
+
275
+ const breadcrumb =
276
+ metadata.fm_breadcrumb
277
+ || metadata.title
278
+ || metadata.inferred_label
279
+
280
+ if (breadcrumb) {
281
+ metadata.breadcrumb = breadcrumb
282
+ }
283
+
284
+ const description =
285
+ metadata.fm_description
286
+ || metadata.fm_tagline
287
+ || metadata.inferred_description
288
+
289
+ if (description) {
290
+ metadata.description = description
291
+ }
292
+
293
+ // The page's own author, for its feed entry. The site's `author` in
294
+ // settings.md is the feed's; Atom applies it to any entry without one.
295
+ if (metadata.fm_author) {
296
+ metadata.author = metadata.fm_author
297
+ }
298
+
299
+ const image =
300
+ metadata.fm_image
301
+ || metadata.inferred_image
302
+
303
+ if (image) {
304
+ metadata.image = image
305
+ }
306
+ }
307
+
308
+ export default getMetadata
@@ -0,0 +1,143 @@
1
+ import { createVisitor } from "./visitor.js"
2
+ import { normalizeLink } from "./links.js"
3
+ import { emojiFor } from "./emoji.js"
4
+ import { toTitleCase } from "../../utils.js"
5
+
6
+ /**
7
+ * The read walk: one pass over the mdast that records what the page
8
+ * says about itself and marks it up in place. Reading, per Sam's
9
+ * convention - metadata extraction and the AST mutation that goes with
10
+ * it happen together, in readFile, once.
11
+ *
12
+ * Context: `{ filePath, tags: string[], links: string[] }`. The caller
13
+ * copies `tags` and `links` onto metadata afterwards.
14
+ */
15
+
16
+ /** `#tag`, preceded by the start of the text or whitespace. */
17
+ const HASHTAG = /(^|\s)#([\w\-\/]+)\b/
18
+
19
+ /**
20
+ * `#tag` becomes a link to the tag page and is recorded. Runs on every
21
+ * text node outside code and links, so a tag in the middle of a
22
+ * sentence counts (the old paragraph-is-one-text-node rule did not).
23
+ * The class is what lets the editor's serializer write `#tag` back
24
+ * rather than a generic link.
25
+ * @type {import("./visitor.js").InlineRule}
26
+ */
27
+ const hashtag = {
28
+ name: "hashtag",
29
+ pattern: HASHTAG,
30
+ resolve: (match, context) => {
31
+ const [, before, tag] = match
32
+ if (!context.tags.includes(tag)) context.tags.push(tag)
33
+ const link = {
34
+ type: "link",
35
+ url: `/tags/${tag}`,
36
+ data: { hProperties: { className: ["hashtag"] } },
37
+ children: [{ type: "text", value: `#${tag}` }]
38
+ }
39
+ return before ? [{ type: "text", value: before }, link] : link
40
+ }
41
+ }
42
+
43
+ /**
44
+ * An explicit link to a page in this site is recorded for backlinks;
45
+ * the node itself is left alone. See links.js for what counts.
46
+ * @type {import("./visitor.js").BlockRule}
47
+ */
48
+ const link = {
49
+ name: "link",
50
+ test: (node) => node.type === "link",
51
+ transform: (node, index, parent, context) => {
52
+ record(context, node.url)
53
+ }
54
+ }
55
+
56
+ /**
57
+ * A bare reference paragraph - a line that is just `/blog/post` - is a
58
+ * link too. The html write renders it as a reference card.
59
+ * @type {import("./visitor.js").BlockRule}
60
+ */
61
+ const reference = {
62
+ name: "reference",
63
+ test: (node) => node.type === "paragraph"
64
+ && node.children?.length === 1
65
+ && node.children[0].type === "text"
66
+ && /^\/\S*$/.test(node.children[0].value.trim()),
67
+ transform: (node, index, parent, context) => {
68
+ record(context, node.children[0].value.trim())
69
+ }
70
+ }
71
+
72
+ /**
73
+ * @param {{ filePath: string, links: string[] }} context
74
+ * @param {string} href
75
+ */
76
+ function record(context, href) {
77
+ const normalized = normalizeLink(href, context.filePath)
78
+ if (normalized && !context.links.includes(normalized)) context.links.push(normalized)
79
+ }
80
+
81
+ /** `[[Name]]`, `[[Name#Section]]`, `[[Name|the words]]`, any combination. */
82
+ const WIKILINK = /\[\[([^\]|#]+)(#[^\]|]+)?(\|[^\]]+)?\]\]/
83
+
84
+ /** `:name:` or `:folder/name:` */
85
+ const SHORTCODE = /:([a-z0-9_+-]+(?:\/[a-z0-9_+-]+)?):/
86
+
87
+ /**
88
+ * `[[Hello World]]` is parsed here and resolved at write (the html
89
+ * plugin's writeRules.js), because resolution needs every target to
90
+ * exist and has to run again when the note appears. The node carries
91
+ * its parameters - name, section, label - so the write has what it
92
+ * needs and the editor can put `[[...]]` back. Recorded in `links` as
93
+ * `[[Name]]`, which is how the linked page finds its backlink.
94
+ * @type {import("./visitor.js").InlineRule}
95
+ */
96
+ const wikilink = {
97
+ name: "wikilink",
98
+ pattern: WIKILINK,
99
+ resolve: (match, context) => {
100
+ const [, name, section, label] = match
101
+ // Recorded by the note's key - the last path segment, lowercased -
102
+ // which is what resolves it at write (writeRules.js, resolveNote)
103
+ // and what the backlink index matches (partials.js).
104
+ const key = name.trim().replace(/^\/+/, "").split("/").at(-1)?.trim().toLowerCase()
105
+ const reference = `[[${key}]]`
106
+ if (key && !context.links.includes(reference)) context.links.push(reference)
107
+ return {
108
+ type: "wikilink",
109
+ name: name.trim(),
110
+ section: section ? section.slice(1).trim() : undefined,
111
+ children: [{ type: "text", value: label ? label.slice(1) : name.trim() }]
112
+ }
113
+ }
114
+ }
115
+
116
+ /**
117
+ * No slash: an emoji shortcode - the character itself, since a
118
+ * shortcode is a way of typing one and the emoji is valid markdown on
119
+ * its own; unknown is left as written, like GitHub. A slash: an icon in
120
+ * the project, resolved at write.
121
+ * @type {import("./visitor.js").InlineRule}
122
+ */
123
+ const shortcode = {
124
+ name: "shortcode",
125
+ pattern: SHORTCODE,
126
+ resolve: (match) => {
127
+ const [, name] = match
128
+ if (name.includes("/")) return { type: "icon", name }
129
+ const emoji = emojiFor(name)
130
+ return emoji ? { type: "text", value: emoji } : null
131
+ }
132
+ }
133
+
134
+ /** No tags inside code, and no link inside a link. */
135
+ const skipped = new Set(["code", "inlineCode", "yaml", "html", "link", "linkReference", "definition"])
136
+
137
+ const readWalk = createVisitor({
138
+ inline: [hashtag, wikilink, shortcode],
139
+ block: [link, reference],
140
+ skip: (node) => skipped.has(node.type)
141
+ })
142
+
143
+ export { readWalk, HASHTAG, WIKILINK, SHORTCODE }
@@ -0,0 +1,109 @@
1
+ // theme typography settings -> the variables TypographyStyles.css reads.
2
+ //
3
+ // The ramps live in the stylesheet: it declares the input variables with
4
+ // their defaults and computes h1..h6 from them with pow(). This module
5
+ // knows one thing - which settings.md key sets which of those variables -
6
+ // and emits only the ones the author set, into the same `typography`
7
+ // layer, loaded after the sheet so they win by source order. The
8
+ // settings panel imports the same table to write the same variables on
9
+ // the document for live preview, so preview and build cannot disagree.
10
+ //
11
+ // No bundled fonts, and no font setting: a family is CSS - the author
12
+ // sets `--font-sans-brand` (and the @font-face behind it) in their own
13
+ // stylesheet, where the sheet's stacks put a system fallback after it.
14
+ // Fonts by url is tasks/2-in-progress/load-fonts.md. Free of node
15
+ // builtins.
16
+
17
+ /**
18
+ * @typedef {object} TypographySetting
19
+ * @property {string} key - the settings.md key under `theme`
20
+ * @property {string} variable - the custom property in TypographyStyles.css
21
+ * @property {string} label
22
+ * @property {string} [hint]
23
+ * @property {"x" | "ch" | ""} unit - "x" is a multiple of --font-size-root
24
+ * @property {number} min
25
+ * @property {number} max
26
+ * @property {number} step
27
+ * @property {number} default - the sheet's own value, for the panel's slider
28
+ */
29
+
30
+ /** @type {TypographySetting[]} */
31
+ export const rampSettings = [
32
+ { key: "heading-size", variable: "--font-size-delta", label: "Heading size", hint: "How much larger h1 is than body text", unit: "x", min: 0.25, max: 4, step: 0.05, default: 2 },
33
+ { key: "heading-size-decay", variable: "--font-size-decay", label: "Size decay", hint: "Higher makes subheadings smaller", unit: "", min: 0.5, max: 6, step: 0.1, default: 3 },
34
+ { key: "h1-letter-spacing", variable: "--letter-spacing-h1", label: "h1 letter spacing", unit: "ch", min: -0.1, max: 0.1, step: 0.005, default: -0.01 },
35
+ { key: "h6-letter-spacing", variable: "--letter-spacing-h6", label: "h6 letter spacing", unit: "ch", min: -0.1, max: 0.1, step: 0.005, default: 0 },
36
+ { key: "letter-spacing-decay", variable: "--letter-spacing-decay", label: "Spacing decay", unit: "", min: 0.5, max: 6, step: 0.1, default: 2 },
37
+ { key: "h1-weight", variable: "--font-weight-h1", label: "h1 weight", unit: "", min: 100, max: 900, step: 10, default: 800 },
38
+ { key: "h6-weight", variable: "--font-weight-h6", label: "h6 weight", unit: "", min: 100, max: 900, step: 10, default: 600 },
39
+ { key: "weight-decay", variable: "--font-weight-decay", label: "Weight decay", unit: "", min: 0.5, max: 6, step: 0.1, default: 2 }
40
+ ]
41
+
42
+ /**
43
+ * The `theme` mapping, or {} for a bare theme name.
44
+ * @param {unknown} theme
45
+ * @returns {Record<string, unknown>}
46
+ */
47
+ function themeSettings(theme) {
48
+ return theme && typeof theme === "object" && !Array.isArray(theme) ? /** @type {Record<string, unknown>} */ (theme) : {}
49
+ }
50
+
51
+ /**
52
+ * A ramp setting's value as CSS, clamped to its range. "x" is a multiple
53
+ * of the root size, so headings follow the root's clamp() up and down.
54
+ * @param {TypographySetting} setting
55
+ * @param {number} value
56
+ */
57
+ function rampValue(setting, value) {
58
+ const clamped = Math.min(setting.max, Math.max(setting.min, value))
59
+ const number = String(Number(clamped.toFixed(4)))
60
+ if (setting.unit === "x") return `calc(${number} * var(--font-size-root))`
61
+ return `${number}${setting.unit}`
62
+ }
63
+
64
+ /**
65
+ * Every variable the theme sets, as [name, value] pairs - only the keys
66
+ * the author wrote, so the sheet's defaults stand for the rest. What
67
+ * the build emits and what the panel writes to the document.
68
+ * @param {unknown} theme
69
+ * @returns {[string, string][]}
70
+ */
71
+ export function typographyVariables(theme) {
72
+ const settings = themeSettings(theme)
73
+ const pairs = []
74
+
75
+ for (const setting of rampSettings) {
76
+ const raw = settings[setting.key]
77
+ const value = typeof raw === "number" ? raw : Number(raw)
78
+ if (raw === undefined || raw === null || raw === "" || !Number.isFinite(value)) continue
79
+ pairs.push([setting.variable, rampValue(setting, value)])
80
+ }
81
+
82
+ return pairs
83
+ }
84
+
85
+ /**
86
+ * The stylesheet for a theme's typography settings, or null when it
87
+ * sets none - the site then keeps whatever TypographyStyles.css gives
88
+ * it and no type.css is declared.
89
+ * @param {unknown} theme
90
+ * @returns {{css: string} | null}
91
+ */
92
+ export function typographyCSS(theme) {
93
+ const variables = typographyVariables(theme)
94
+ if (!variables.length) return null
95
+
96
+ const css = [
97
+ `/* Generated from theme settings in settings.md - edit the settings, not this file. */`,
98
+ `@layer reset, typography;`,
99
+ ``,
100
+ `@layer typography {`,
101
+ ` :root {`,
102
+ ...variables.map(([name, value]) => ` ${name}: ${value};`),
103
+ ` }`,
104
+ `}`,
105
+ ``
106
+ ].join("\n")
107
+
108
+ return { css }
109
+ }