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.
- package/README.md +23 -17
- package/bin.js +87 -30
- package/cli.js +15 -0
- package/config.js +102 -16
- package/extractDate.js +70 -6
- package/index.js +14 -5
- package/package.json +42 -7
- package/plugins/assets/index.js +65 -0
- package/plugins/atproto/index.js +132 -0
- package/plugins/atproto/password.js +71 -0
- package/plugins/atproto/publish.js +406 -0
- package/plugins/atproto/record.js +144 -0
- package/plugins/atproto/rkey.js +54 -0
- package/plugins/deploy-cloudflare/index.js +92 -0
- package/plugins/fonts/index.js +18 -21
- package/plugins/html/assets/bundle-BeK1Hptv.css +21 -0
- package/plugins/html/bundle/assets/index-BeK1Hptv.css +21 -0
- package/plugins/html/bundle/index.js +21145 -0
- package/plugins/html/editor/EditButton.svelte +152 -0
- package/plugins/html/editor/Editor.svelte +51 -0
- package/plugins/html/editor/Overlays.svelte +6 -0
- package/plugins/html/editor/SettingsPanel.svelte +397 -0
- package/plugins/html/editor/Toolbar.svelte +644 -0
- package/plugins/html/editor/create-session.js +250 -0
- package/plugins/html/editor/directives.js +128 -0
- package/plugins/html/editor/frontmatter.js +97 -0
- package/plugins/html/editor/ingest.js +339 -0
- package/plugins/html/editor/main.js +94 -0
- package/plugins/html/editor/nodes/Alert.svelte +21 -0
- package/plugins/html/editor/nodes/Blockquote.svelte +9 -0
- package/plugins/html/editor/nodes/CodeBlock.svelte +19 -0
- package/plugins/html/editor/nodes/Embed.svelte +19 -0
- package/plugins/html/editor/nodes/Emphasis.svelte +11 -0
- package/plugins/html/editor/nodes/Heading.svelte +15 -0
- package/plugins/html/editor/nodes/Highlight.svelte +11 -0
- package/plugins/html/editor/nodes/Image.svelte +18 -0
- package/plugins/html/editor/nodes/InlineCode.svelte +11 -0
- package/plugins/html/editor/nodes/Link.svelte +17 -0
- package/plugins/html/editor/nodes/List.svelte +15 -0
- package/plugins/html/editor/nodes/ListItem.svelte +9 -0
- package/plugins/html/editor/nodes/Page.svelte +21 -0
- package/plugins/html/editor/nodes/Paragraph.svelte +9 -0
- package/plugins/html/editor/nodes/Strikethrough.svelte +11 -0
- package/plugins/html/editor/nodes/Strong.svelte +11 -0
- package/plugins/html/editor/nodes/ThematicBreak.svelte +9 -0
- package/plugins/html/editor/nodes/index.js +18 -0
- package/plugins/html/editor/rollup.config.js +35 -0
- package/plugins/html/editor/serialize.js +157 -0
- package/plugins/html/editor/settings-file.js +83 -0
- package/plugins/html/editor/socket.js +202 -0
- package/plugins/html/editor/source.js +43 -0
- package/plugins/html/image.js +104 -0
- package/plugins/html/index.js +760 -0
- package/plugins/html/partials.js +299 -0
- package/plugins/html/socialLinks.js +67 -0
- package/plugins/html/writeRules.js +377 -0
- package/plugins/icons/index.js +2 -6
- package/plugins/images/index.js +78 -55
- package/plugins/markdown/brandColors.js +10 -0
- package/plugins/markdown/colorScheme.js +64 -0
- package/plugins/markdown/emoji.js +30 -0
- package/plugins/markdown/frontmatter.js +253 -0
- package/plugins/markdown/index.js +287 -1274
- package/plugins/markdown/links.js +97 -0
- package/plugins/markdown/metadata.js +308 -0
- package/plugins/markdown/readRules.js +143 -0
- package/plugins/markdown/typography.js +109 -0
- package/plugins/markdown/visitor.js +143 -0
- package/plugins/publish/index.js +34 -0
- package/plugins/robots/agents.js +79 -0
- package/plugins/robots/index.js +30 -10
- package/plugins/robots/robots.js +48 -0
- package/plugins/styles/index.js +111 -26
- package/plugins/styles/theme.js +116 -0
- package/plugins/urls/index.js +78 -0
- package/plugins/urls/urlMetadata.js +246 -0
- package/plugins/vectors/index.js +5 -9
- package/plugins/xml/entryContent.js +103 -0
- package/plugins/xml/index.js +123 -50
- package/secretPaths.js +170 -0
- package/stylesheets/DefaultStyles.css +367 -437
- package/stylesheets/ResetStyles.css +2 -38
- package/stylesheets/SyntaxHighlightingStyles.css +269 -0
- package/stylesheets/TypographyStyles.css +386 -128
- package/systemPaths.js +48 -0
- package/utils.js +56 -5
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -73
- package/.github/ISSUE_TEMPLATE/config.yml +0 -7
- package/docs-source/.cache.json +0 -9
- package/docs-source/.obsidian/app.json +0 -3
- package/docs-source/.obsidian/appearance.json +0 -3
- package/docs-source/.obsidian/core-plugins-migration.json +0 -30
- package/docs-source/.obsidian/core-plugins.json +0 -20
- package/docs-source/.obsidian/workspace.json +0 -168
- package/docs-source/.stackblitzrc +0 -3
- package/docs-source/.votive.db +0 -0
- package/docs-source/about.md +0 -3
- package/docs-source/blog/home.md +0 -5
- package/docs-source/blog/url-ui.md +0 -21
- package/docs-source/blog.md +0 -5
- package/docs-source/docs/.votive.db +0 -0
- package/docs-source/docs/deploy.md +0 -67
- package/docs-source/docs/file-structure.md +0 -31
- package/docs-source/docs/folder-settings.md +0 -23
- package/docs-source/docs/home.md +0 -55
- package/docs-source/docs/images.md +0 -10
- package/docs-source/docs/items.md +0 -13
- package/docs-source/docs/pages.md +0 -141
- package/docs-source/docs/settings.md +0 -4
- package/docs-source/docs/styling.md +0 -34
- package/docs-source/docs/taxonomies.md +0 -37
- package/docs-source/features/cards.md +0 -7
- package/docs-source/features/editing.md +0 -7
- package/docs-source/features/emoji.md +0 -7
- package/docs-source/features/frontmatter.md +0 -7
- package/docs-source/features/lists.md +0 -7
- package/docs-source/features/navigation.md +0 -7
- package/docs-source/features/rich-previews.md +0 -7
- package/docs-source/features/robots.md +0 -7
- package/docs-source/features/rss.md +0 -7
- package/docs-source/features/sitemap.md +0 -7
- package/docs-source/features/speed.md +0 -7
- package/docs-source/features/static.md +0 -7
- package/docs-source/features/taxonomies.md +0 -7
- package/docs-source/home.md +0 -42
- package/docs-source/output/about.html +0 -1
- package/docs-source/output/blog/url-ui.html +0 -8
- package/docs-source/output/blog.html +0 -1
- package/docs-source/output/default.css +0 -1
- package/docs-source/output/docs/deploy.html +0 -34
- package/docs-source/output/docs/file-structure.html +0 -24
- package/docs-source/output/docs/folder-settings.html +0 -20
- package/docs-source/output/docs/images.html +0 -2
- package/docs-source/output/docs/items.html +0 -6
- package/docs-source/output/docs/pages.html +0 -101
- package/docs-source/output/docs/styling.html +0 -18
- package/docs-source/output/docs/taxonomies.html +0 -20
- package/docs-source/output/docs.html +0 -28
- package/docs-source/output/features/cards.html +0 -1
- package/docs-source/output/features/editing.html +0 -1
- package/docs-source/output/features/emoji.html +0 -1
- package/docs-source/output/features/frontmatter.html +0 -1
- package/docs-source/output/features/lists.html +0 -1
- package/docs-source/output/features/navigation.html +0 -1
- package/docs-source/output/features/rich-previews.html +0 -1
- package/docs-source/output/features/robots.html +0 -1
- package/docs-source/output/features/rss.html +0 -1
- package/docs-source/output/features/sitemap.html +0 -1
- package/docs-source/output/features/speed.html +0 -1
- package/docs-source/output/features/static.html +0 -1
- package/docs-source/output/features/taxonomies.html +0 -1
- package/docs-source/output/features.html +0 -1
- package/docs-source/output/feed.xml +0 -1
- package/docs-source/output/index.html +0 -21
- package/docs-source/output/reset.css +0 -1
- package/docs-source/output/roadmap.html +0 -87
- package/docs-source/output/robots.txt +0 -14
- package/docs-source/output/sitemap.xml +0 -16
- package/docs-source/output/typography.css +0 -1
- package/docs-source/roadmap.md +0 -98
- package/docs-source/settings.md +0 -13
- package/getMetadata.js +0 -41
- package/jsconfig.json +0 -10
- package/regex.js +0 -36
- package/stylesheets/brand-colors.css +0 -119
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import path from "node:path"
|
|
2
|
+
import { h } from "hastscript"
|
|
3
|
+
import { common, createLowlight } from "lowlight"
|
|
4
|
+
import { toText } from "hast-util-to-text"
|
|
5
|
+
import GithubSlugger from "github-slugger"
|
|
6
|
+
import { createVisitor, SKIP } from "../markdown/visitor.js"
|
|
7
|
+
import { toTitleCase, listPages } from "../../utils.js"
|
|
8
|
+
import { globClasses } from "./editor/directives.js"
|
|
9
|
+
import createDynamicImage from "./image.js"
|
|
10
|
+
import { displayPath } from "../../secretPaths.js"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The write walk: one pass over a page's hast for everything that
|
|
14
|
+
* renders against other targets, settings or the url store - which is
|
|
15
|
+
* why it is here and not at read (a read runs before its neighbours
|
|
16
|
+
* exist) or at transform (a transform runs once per read and never
|
|
17
|
+
* again; a write re-runs whenever the page is stale, which is exactly
|
|
18
|
+
* when a note, icon or preview it was waiting for has arrived).
|
|
19
|
+
*
|
|
20
|
+
* Context: `{ target, api, config, settings, makeHeader, makeTable,
|
|
21
|
+
* highlighted }`. `highlighted` is set by the highlight rule so the
|
|
22
|
+
* write can link the highlight stylesheet only on pages that need it.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const lowlight = createLowlight(common)
|
|
26
|
+
|
|
27
|
+
/** @param {any} node */
|
|
28
|
+
const isElement = (node) => node?.type === "element"
|
|
29
|
+
|
|
30
|
+
/** @param {any} node @param {string} name */
|
|
31
|
+
const hasClass = (node, name) => Array.isArray(node.properties?.className) && node.properties.className.includes(name)
|
|
32
|
+
|
|
33
|
+
/** A paragraph whose only content is one text node. */
|
|
34
|
+
const soleText = (node) => isElement(node) && node.tagName === "p" && node.children?.length === 1 && typeof node.children[0]?.value === "string"
|
|
35
|
+
? node.children[0].value
|
|
36
|
+
: null
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `[text](./post.md)` resolves by *source* path to the routed target -
|
|
40
|
+
* which for a secret page is the hashed one, with no second trip
|
|
41
|
+
* through the router. The href may arrive percent-encoded (toHast
|
|
42
|
+
* normalizes non-ASCII). A link to a file that produces no page is the
|
|
43
|
+
* author's to notice, not a reason to stop the build.
|
|
44
|
+
* @type {import("../markdown/visitor.js").BlockRule}
|
|
45
|
+
*/
|
|
46
|
+
const relativeLink = {
|
|
47
|
+
name: "relativeLink",
|
|
48
|
+
test: (node) => isElement(node) && node.tagName === "a" && typeof node.properties?.href === "string" && node.properties.href.startsWith("./"),
|
|
49
|
+
transform: (node, index, parent, { target, api, config }) => {
|
|
50
|
+
// A stub has a source path but no neighbours to resolve against.
|
|
51
|
+
if (!target.source) return
|
|
52
|
+
const sourcePath = path.normalize(path.join(path.dirname(target.source), decodeURIComponent(node.properties.href)))
|
|
53
|
+
const found = api.targetBySource(sourcePath)
|
|
54
|
+
if (!found) {
|
|
55
|
+
config.log?.("warn", `${target.source}: link to ${node.properties.href} matches no page`)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
node.properties.href = found.metadata.prettyURL
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A note by name, the way Obsidian finds it - as best we can guess
|
|
64
|
+
* (Sam, Sept 19):
|
|
65
|
+
*
|
|
66
|
+
* - by **filename without extension, case-insensitively**, whatever
|
|
67
|
+
* folder it is in (`[[Hello World]]` finds `hello world.md` and
|
|
68
|
+
* `Hello World.md`, never `hello-world.md`), or by one of the note's
|
|
69
|
+
* `aliases:`;
|
|
70
|
+
* - a **path** narrows it: `[[notes/twin]]` wants a `twin` whose folder
|
|
71
|
+
* path ends in `notes`, from the vault root or any folder above it;
|
|
72
|
+
* - when several still match, **the nearest wins**: the linking page's
|
|
73
|
+
* own folder, then the longest shared folder prefix, then the
|
|
74
|
+
* shortest path, then alphabetical.
|
|
75
|
+
*
|
|
76
|
+
* A filtered listing on `note_key`/`note_aliases` (metadata.js), so a
|
|
77
|
+
* note that appears later restales this page and the write runs again.
|
|
78
|
+
* @param {string} name
|
|
79
|
+
* @param {{ api: any, target: any }} context
|
|
80
|
+
*/
|
|
81
|
+
function resolveNote(name, { api, target }) {
|
|
82
|
+
const segments = name.trim().replace(/^\/+/, "").split("/").map(segment => segment.trim().toLowerCase()).filter(Boolean)
|
|
83
|
+
const key = segments.at(-1)
|
|
84
|
+
if (!key) return null
|
|
85
|
+
const folderHint = segments.slice(0, -1).join("/")
|
|
86
|
+
|
|
87
|
+
const candidates = api.targets({
|
|
88
|
+
folder: "",
|
|
89
|
+
recursive: true,
|
|
90
|
+
query: { "|": { note_key: key, note_aliases: { "~": key } } }
|
|
91
|
+
}).filter(candidate => (
|
|
92
|
+
candidate.extension === ".html"
|
|
93
|
+
&& candidate.path !== target.path
|
|
94
|
+
&& (!folderHint || sourceFolder(candidate).endsWith(folderHint))
|
|
95
|
+
))
|
|
96
|
+
|
|
97
|
+
const here = target.dir.split(path.sep).join("/")
|
|
98
|
+
const rank = (candidate) => {
|
|
99
|
+
const there = candidate.dir.split(path.sep).join("/")
|
|
100
|
+
return [there === here ? 0 : 1, -sharedPrefix(here, there), candidate.path.length, candidate.path]
|
|
101
|
+
}
|
|
102
|
+
return candidates.sort((a, b) => {
|
|
103
|
+
const [ad, as, al, ap] = rank(a)
|
|
104
|
+
const [bd, bs, bl, bp] = rank(b)
|
|
105
|
+
return ad - bd || as - bs || al - bl || (ap < bp ? -1 : ap > bp ? 1 : 0)
|
|
106
|
+
})[0] ?? null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A candidate's source folder as the author sees it: salts stripped, lowercase, forward slashes. */
|
|
110
|
+
function sourceFolder(candidate) {
|
|
111
|
+
const source = candidate.source ? displayPath(candidate.source) : candidate.path
|
|
112
|
+
return path.dirname(source).split(path.sep).join("/").toLowerCase().replace(/^\.$/, "")
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** How many leading folder segments two folder paths share. */
|
|
116
|
+
function sharedPrefix(a, b) {
|
|
117
|
+
const as = a ? a.split("/") : []
|
|
118
|
+
const bs = b ? b.split("/") : []
|
|
119
|
+
const shared = as.findIndex((segment, index) => segment !== bs[index])
|
|
120
|
+
return shared === -1 ? as.length : shared
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A file by name (`[[Hello World.jpeg]]`): beside the page, then at the
|
|
125
|
+
* root.
|
|
126
|
+
* @param {string} name
|
|
127
|
+
* @param {{ api: any, target: any }} context
|
|
128
|
+
*/
|
|
129
|
+
function resolveFile(name, { api, target }) {
|
|
130
|
+
const lower = name.trim().toLowerCase()
|
|
131
|
+
return api.target(path.join(target.dir, lower)) ?? api.target(lower) ?? null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The read parsed `[[Name#Section|text]]` into `<a class=wikilink
|
|
136
|
+
* data-note data-section>text</a>`; this gives it an href. Unresolved
|
|
137
|
+
* stays an <a> with no href - never a span.
|
|
138
|
+
* @type {import("../markdown/visitor.js").BlockRule}
|
|
139
|
+
*/
|
|
140
|
+
const wikilink = {
|
|
141
|
+
name: "wikilink",
|
|
142
|
+
test: (node) => isElement(node) && node.tagName === "a" && hasClass(node, "wikilink") && typeof node.properties?.dataNote === "string",
|
|
143
|
+
transform: (node, index, parent, context) => {
|
|
144
|
+
const name = node.properties.dataNote
|
|
145
|
+
const section = node.properties.dataSection
|
|
146
|
+
const isFile = /\.[a-z0-9]+$/i.test(name.trim())
|
|
147
|
+
const found = isFile ? resolveFile(name, context) : resolveNote(name, context)
|
|
148
|
+
if (!found) {
|
|
149
|
+
delete node.properties.href
|
|
150
|
+
return SKIP
|
|
151
|
+
}
|
|
152
|
+
const url = found.metadata?.prettyURL ?? `/${found.path}`
|
|
153
|
+
const anchor = section ? `#${new GithubSlugger().slug(section)}` : ""
|
|
154
|
+
node.properties.href = url + anchor
|
|
155
|
+
return SKIP
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* `:fa/surfer:` is `fa/surfer.svg` in the project, read through
|
|
161
|
+
* api.target() so a replaced icon restales the page. The same shape as
|
|
162
|
+
* a#logo - an <img> plus --icon-url - so a monochrome SVG can be masked
|
|
163
|
+
* in currentColor. Missing: the shortcode is put back as written.
|
|
164
|
+
* @type {import("../markdown/visitor.js").BlockRule}
|
|
165
|
+
*/
|
|
166
|
+
const icon = {
|
|
167
|
+
name: "icon",
|
|
168
|
+
test: (node) => isElement(node) && node.tagName === "img" && hasClass(node, "icon") && typeof node.properties?.dataIcon === "string",
|
|
169
|
+
transform: (node, index, parent, { api }) => {
|
|
170
|
+
const name = node.properties.dataIcon
|
|
171
|
+
const found = api.target(`${name}.svg`)
|
|
172
|
+
if (!found) return { type: "text", value: `:${name}:` }
|
|
173
|
+
const src = `/${found.path}`
|
|
174
|
+
node.properties.src = src
|
|
175
|
+
node.properties.style = `--icon-url: url("${src}")`
|
|
176
|
+
return SKIP
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A fenced block with a language: what rehype-highlight did, without
|
|
182
|
+
* its walk. hljs plus per-token spans on the <code>; the language class
|
|
183
|
+
* is left for the stylesheet. An unregistered language is left alone.
|
|
184
|
+
* @type {import("../markdown/visitor.js").BlockRule}
|
|
185
|
+
*/
|
|
186
|
+
const highlight = {
|
|
187
|
+
name: "highlight",
|
|
188
|
+
test: (node) => isElement(node) && node.tagName === "pre" && isElement(node.children?.[0]) && node.children[0].tagName === "code",
|
|
189
|
+
transform: (node, index, parent, context) => {
|
|
190
|
+
const code = node.children[0]
|
|
191
|
+
const language = (code.properties?.className ?? []).map(String).find(name => name.startsWith("language-"))?.slice("language-".length)
|
|
192
|
+
if (!language) return SKIP
|
|
193
|
+
let result
|
|
194
|
+
try {
|
|
195
|
+
result = lowlight.highlight(language, toText(code, { whitespace: "pre" }))
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (/Unknown language/.test(error.message)) return SKIP
|
|
198
|
+
throw error
|
|
199
|
+
}
|
|
200
|
+
code.properties.className = ["hljs", ...code.properties.className.filter(name => name !== "hljs")]
|
|
201
|
+
if (result.children.length) code.children = result.children
|
|
202
|
+
context.highlighted = true
|
|
203
|
+
return SKIP
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* A project image becomes a responsive <picture>; first in its
|
|
209
|
+
* paragraph with siblings after it, those are its caption.
|
|
210
|
+
* @type {import("../markdown/visitor.js").BlockRule}
|
|
211
|
+
*/
|
|
212
|
+
const image = {
|
|
213
|
+
name: "image",
|
|
214
|
+
test: (node) => isElement(node) && node.tagName === "img" && !hasClass(node, "icon"),
|
|
215
|
+
transform: (node, index, parent, { api }) => {
|
|
216
|
+
const { src, alt } = node.properties
|
|
217
|
+
const picture = createDynamicImage(src, api, alt)
|
|
218
|
+
if (!picture) return SKIP
|
|
219
|
+
if (index === 0 && parent.children.length > 1) {
|
|
220
|
+
const caption = parent.children.slice(1)
|
|
221
|
+
parent.children = [h("figure", [picture, h("figcaption", caption)])]
|
|
222
|
+
return SKIP
|
|
223
|
+
}
|
|
224
|
+
return picture
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* A paragraph that is just a path: `/blog/post` is a reference card,
|
|
230
|
+
* `/blog/*` and `/blog/**` are listings, with the query string as the
|
|
231
|
+
* listing's parameters. Every parameter is carried in the class list so
|
|
232
|
+
* the editor can collapse the expansion back to the directive
|
|
233
|
+
* (plugins/html/editor/directives.js).
|
|
234
|
+
*
|
|
235
|
+
* Two spellings, two address spaces (Sam, Sept 19). An absolute path
|
|
236
|
+
* (`/blog/*`) is a *published* path and names targets. A relative one
|
|
237
|
+
* (`./posts/*`, `../notes/x`) is a *source* path, resolved against the
|
|
238
|
+
* page's own file and then routed - which is the only way to list a
|
|
239
|
+
* secret folder, since the salt lives in the source name
|
|
240
|
+
* (`./members##autumn-glaze/*`) and the listing renders the hashed
|
|
241
|
+
* urls. A `##` in an absolute path can match nothing, and the paragraph
|
|
242
|
+
* is dropped rather than rendered: a salt never reaches output.
|
|
243
|
+
* @type {import("../markdown/visitor.js").BlockRule}
|
|
244
|
+
*/
|
|
245
|
+
const directive = {
|
|
246
|
+
name: "directive",
|
|
247
|
+
test: (node) => /^(\/|\.\.?\/)\S*$/.test(soleText(node) ?? ""),
|
|
248
|
+
transform: (node, index, parent, { target, api, config, makeHeader, makeTable }) => {
|
|
249
|
+
const value = node.children[0].value
|
|
250
|
+
const relative = !value.startsWith("/")
|
|
251
|
+
|
|
252
|
+
if (!relative && value.includes("##")) {
|
|
253
|
+
config.log?.("error", `${target.source ?? target.path}: a listing by published path cannot name a secret folder (${value}); write it relative to this file, as \`./…\``)
|
|
254
|
+
return []
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// A relative path is joined to this file's folder in source space
|
|
258
|
+
// and sent through the router cascade, so the folder or page it
|
|
259
|
+
// names is the published one, hashed if secret. `#` is not a url
|
|
260
|
+
// character (it starts a fragment), so the query string is split
|
|
261
|
+
// off before anything is parsed as a url.
|
|
262
|
+
const [pathPart, search = ""] = value.split("?")
|
|
263
|
+
const routed = relative
|
|
264
|
+
? routeRelative(pathPart, target, config)
|
|
265
|
+
: pathPart
|
|
266
|
+
if (routed === undefined) {
|
|
267
|
+
config.log?.("warn", `${target.path}: ${value} cannot be resolved from a page with no source file`)
|
|
268
|
+
return SKIP
|
|
269
|
+
}
|
|
270
|
+
const url = new URL(routed, "thismessage://")
|
|
271
|
+
if (search) url.search = search
|
|
272
|
+
const { dir, base } = path.parse(url.pathname)
|
|
273
|
+
const recursive = base === "**"
|
|
274
|
+
const many = base === "*" || base === "**"
|
|
275
|
+
|
|
276
|
+
if (!many) {
|
|
277
|
+
const info = path.parse(url.pathname)
|
|
278
|
+
info.ext ||= ".html"
|
|
279
|
+
delete info.base
|
|
280
|
+
// Lowercased: every vowel target path is (config.js's router).
|
|
281
|
+
const found = api.target(path.relative("/", path.format(info)).toLowerCase())
|
|
282
|
+
if (!found) return SKIP
|
|
283
|
+
return makeHeader(found.metadata, found.metadata.prettyURL, api, config)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const folder = path.relative("/", dir)
|
|
287
|
+
const count = url.searchParams.get("count")
|
|
288
|
+
const tag = url.searchParams.get("tag")
|
|
289
|
+
const view = url.searchParams.get("view")
|
|
290
|
+
// ?properties=title,description,image picks the table's columns, in
|
|
291
|
+
// order. A name is looked up as written, then with the fm_ prefix.
|
|
292
|
+
const properties = (url.searchParams.get("properties") || "").split(",").map(name => name.trim()).filter(Boolean)
|
|
293
|
+
const query = tag ? { tags: { "~": tag } } : {}
|
|
294
|
+
|
|
295
|
+
// A relative glob is in source space, where the author named the
|
|
296
|
+
// folder salt and all, so it sees the hidden (secret) pages there;
|
|
297
|
+
// a published-path glob never does.
|
|
298
|
+
const listing = { folder, recursive, query, orderBy: { property: "date", direction: "desc" }, limit: count ? Number(count) : undefined }
|
|
299
|
+
const targets = relative
|
|
300
|
+
? api.targets(listing).filter(page => page.write !== false && page.extension === ".html")
|
|
301
|
+
: listPages(api, listing)
|
|
302
|
+
|
|
303
|
+
const listClasses = globClasses({ folder, recursive, limit: count, tag, view, properties })
|
|
304
|
+
|
|
305
|
+
return view === "table"
|
|
306
|
+
? makeTable(listClasses, properties.length ? properties : ["title"], targets, api)
|
|
307
|
+
: h("ul", { class: listClasses }, targets.map(found => h("li", makeHeader(found.metadata, found.metadata.prettyURL, api, config))))
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* A relative directive path as the absolute published path it names.
|
|
313
|
+
* The glob's last segment (`*`, `**`) rides along untouched: the
|
|
314
|
+
* cascade hashes and lowercases segments and leaves those alone.
|
|
315
|
+
* @param {string} value - `./members##salt/*`, `../notes/x`
|
|
316
|
+
* @param {{source?: string | null}} target - the page being written
|
|
317
|
+
* @param {{router?: (sourcePath: string) => string}} config
|
|
318
|
+
* @returns {string | undefined} `/studio/<hash>/*`, or undefined for a
|
|
319
|
+
* page with no source to resolve against (a stub)
|
|
320
|
+
*/
|
|
321
|
+
function routeRelative(value, target, config) {
|
|
322
|
+
if (!target.source) return undefined
|
|
323
|
+
const sourcePath = path.normalize(path.join(path.dirname(target.source), value))
|
|
324
|
+
const routed = config.router ? config.router(sourcePath) : sourcePath
|
|
325
|
+
return "/" + routed.split(path.sep).join("/")
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A paragraph that is just a url is a link preview. api.url() both
|
|
330
|
+
* reads and asks: nothing fetched yet leaves the paragraph as written,
|
|
331
|
+
* and the fetch landing restales this page.
|
|
332
|
+
* @type {import("../markdown/visitor.js").BlockRule}
|
|
333
|
+
*/
|
|
334
|
+
const preview = {
|
|
335
|
+
name: "preview",
|
|
336
|
+
test: (node) => /^https?:\/\/\S+$/.test(soleText(node) ?? ""),
|
|
337
|
+
transform: (node, index, parent, { api }) => {
|
|
338
|
+
const url = node.children[0].value
|
|
339
|
+
const data = api.url(url)
|
|
340
|
+
if (!data) return SKIP
|
|
341
|
+
return h("a.link-preview", { href: url, target: "_blank", rel: "noopener noreferrer" }, [
|
|
342
|
+
data.image ? h("img.link-preview-image", { src: data.image, alt: "" }) : null,
|
|
343
|
+
h("span.link-preview-body", [
|
|
344
|
+
h("span.link-preview-title", data.title || url),
|
|
345
|
+
data.description ? h("span.link-preview-description", data.description) : null
|
|
346
|
+
].filter(Boolean))
|
|
347
|
+
].filter(Boolean))
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* A GFM alert: a blockquote whose first line is `[!NOTE]` (or WARNING,
|
|
353
|
+
* DANGER...) becomes an aside with the label as its heading.
|
|
354
|
+
* @type {import("../markdown/visitor.js").BlockRule}
|
|
355
|
+
*/
|
|
356
|
+
const alert = {
|
|
357
|
+
name: "alert",
|
|
358
|
+
test: (node) => isElement(node) && node.tagName === "blockquote"
|
|
359
|
+
&& isElement(node.children?.[1]) && node.children[1].tagName === "p"
|
|
360
|
+
&& node.children[1].children?.length === 1
|
|
361
|
+
&& /^\[!(\w+)\]$/.test(node.children[1].children[0].value ?? ""),
|
|
362
|
+
transform: (node) => {
|
|
363
|
+
const [, label] = node.children[1].children[0].value.match(/^\[!(\w+)\]$/)
|
|
364
|
+
node.tagName = "aside"
|
|
365
|
+
node.properties = { class: `alert ${label.toLowerCase()}` }
|
|
366
|
+
node.children.splice(0, 2, h("h2", toTitleCase(label)))
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const skipped = new Set(["pre", "code", "script", "style"])
|
|
371
|
+
|
|
372
|
+
const writeWalk = createVisitor({
|
|
373
|
+
block: [relativeLink, wikilink, icon, highlight, image, directive, preview, alert],
|
|
374
|
+
skip: (node) => isElement(node) && skipped.has(node.tagName)
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
export { writeWalk }
|
package/plugins/icons/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/** @type {Votive.VotiveProcessor} */
|
|
4
4
|
const iconReader = {
|
|
5
|
+
router: ({ name, dir, ext }) => ({ name, dir, ext }),
|
|
5
6
|
syntax: "icon",
|
|
6
7
|
filter: {
|
|
7
8
|
extensions: [".ico"]
|
|
@@ -15,12 +16,7 @@ const iconReader = {
|
|
|
15
16
|
/** @type {Votive.VotivePlugin} */
|
|
16
17
|
const vowelIconsPlugin = {
|
|
17
18
|
name: "vowel-icons",
|
|
18
|
-
processors: [iconReader]
|
|
19
|
-
router: ({ name, dir, ext }) => {
|
|
20
|
-
return {
|
|
21
|
-
name, dir, ext
|
|
22
|
-
}
|
|
23
|
-
}
|
|
19
|
+
processors: [iconReader]
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
export default vowelIconsPlugin
|
package/plugins/images/index.js
CHANGED
|
@@ -1,75 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import fs from "fs/promises"
|
|
3
|
-
import sharp from 'sharp'
|
|
1
|
+
import { hash as digest } from "node:crypto"
|
|
4
2
|
import path from "node:path"
|
|
5
|
-
import
|
|
3
|
+
import sharp from 'sharp'
|
|
4
|
+
import { createImagePath, imageSizes, imageExts } from "./../../utils.js"
|
|
6
5
|
|
|
7
6
|
/** @import * as Votive from "votive" */
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
const EXTENSIONS = [".jpeg", ".jpg", ".png", ".webp", ".gif", ".avif"]
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An image's derivatives - four widths in avif, webp and its own format
|
|
12
|
+
* - are the image's **owned targets**: its read returns them (votive's
|
|
13
|
+
* ReadHookResult.targets), each a recipe in metadata and nothing else.
|
|
14
|
+
* Votive stores them with the image as their source, which is the whole
|
|
15
|
+
* mechanism: at write, `target.buffer()` reads the owner's file, so a
|
|
16
|
+
* derivative resizes from the original with nothing carried between
|
|
17
|
+
* stages; and ownership decides their lifetime - a changed image (a new
|
|
18
|
+
* hash, so new paths) replaces its set, a deleted image takes its
|
|
19
|
+
* twelve with it, and a warm start finds rows for every file and does
|
|
20
|
+
* nothing.
|
|
21
|
+
*
|
|
22
|
+
* They used to be written straight to disk by the original's write,
|
|
23
|
+
* which only worked while every launch was a cold build: the startup
|
|
24
|
+
* sweep deleted every unclaimed file on the second launch. A stub
|
|
25
|
+
* version in between worked, but declared them two builds after the
|
|
26
|
+
* read (an enumerator sees only the database) and needed a module-level
|
|
27
|
+
* map to find the original at write, since a stub has no file behind
|
|
28
|
+
* it. The read that has the bytes is the right place to say what they
|
|
29
|
+
* become.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The two-byte hex of one channel.
|
|
34
|
+
* @param {number} channel
|
|
35
|
+
*/
|
|
36
|
+
function hex(channel) {
|
|
37
|
+
return Math.round(channel).toString(16).padStart(2, "0")
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Runs deferred, with the bytes (buffer format), so this is where an
|
|
42
|
+
* image is looked at. Dimensions go on <img width height> so the browser
|
|
43
|
+
* reserves the box before the bytes arrive; the dominant colour becomes
|
|
44
|
+
* a custom property on the <picture> for a placeholder that matches; the
|
|
45
|
+
* content hash names the derivatives, so they change exactly when the
|
|
46
|
+
* pixels do. sharp decodes the image once here, and the result - the
|
|
47
|
+
* derivative list included - is in the buffer cache after the first
|
|
48
|
+
* read.
|
|
49
|
+
* @type {Votive.ProcessorRead}
|
|
50
|
+
*/
|
|
51
|
+
async function readImagePath(source) {
|
|
52
|
+
const buffer = source.buffer()
|
|
53
|
+
const image = sharp(buffer)
|
|
54
|
+
const [{ width, height }, { dominant }] = await Promise.all([image.metadata(), image.stats()])
|
|
55
|
+
const dominantColor = dominant ? `#${hex(dominant.r)}${hex(dominant.g)}${hex(dominant.b)}` : undefined
|
|
56
|
+
const hash = digest("sha1", buffer).slice(0, 8)
|
|
57
|
+
|
|
58
|
+
const ext = path.extname(source.target)
|
|
59
|
+
const targets = imageSizes.flatMap(size => [...imageExts, ext].map(format => ({
|
|
60
|
+
path: createImagePath({ targetFilePath: source.target, size, ext: format, targetDirectory: "", uuid: hash }),
|
|
61
|
+
metadata: { derivative: { size, format: format.replace(/^\./, "") } }
|
|
62
|
+
})))
|
|
63
|
+
|
|
64
|
+
return { metadata: { hash, width, height, dominant: dominantColor }, targets }
|
|
65
|
+
}
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
/**
|
|
68
|
+
* An original is copied through. A derivative is resized and converted
|
|
69
|
+
* from its owner's bytes - which is what target.buffer() reads, because
|
|
70
|
+
* votive stored the owner as the derivative's source.
|
|
71
|
+
* @type {Votive.ProcessorWrite}
|
|
72
|
+
*/
|
|
73
|
+
async function writeImage(target) {
|
|
74
|
+
const bytes = target.buffer()
|
|
75
|
+
const recipe = target.metadata?.derivative
|
|
76
|
+
if (!recipe) return { data: bytes }
|
|
77
|
+
|
|
78
|
+
const format = recipe.format === "jpg" ? "jpeg" : recipe.format
|
|
79
|
+
const data = await sharp(bytes).resize(recipe.size).toFormat(format).toBuffer()
|
|
80
|
+
return { data }
|
|
54
81
|
}
|
|
55
82
|
|
|
56
83
|
/** @type {Votive.VotiveProcessor} */
|
|
57
|
-
const
|
|
84
|
+
const imagesProcessor = {
|
|
58
85
|
format: "buffer",
|
|
59
|
-
extensions:
|
|
86
|
+
extensions: EXTENSIONS,
|
|
87
|
+
router: ({ name, dir, ext }) => ({ name, dir, ext }),
|
|
60
88
|
readFile: readImagePath,
|
|
61
89
|
writeFile: writeImage
|
|
62
90
|
}
|
|
63
91
|
|
|
64
92
|
/** @type {Votive.VotivePlugin} */
|
|
65
93
|
const vowelImagesPlugin = {
|
|
66
|
-
name: "vowel-
|
|
67
|
-
processors: [
|
|
68
|
-
router: ({ name, dir, ext }) => {
|
|
69
|
-
return {
|
|
70
|
-
name, dir, ext
|
|
71
|
-
}
|
|
72
|
-
}
|
|
94
|
+
name: "vowel-images",
|
|
95
|
+
processors: [imagesProcessor]
|
|
73
96
|
}
|
|
74
97
|
|
|
75
98
|
export default vowelImagesPlugin
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Vowel's brand pair, the seeds every default-theme site falls back to
|
|
2
|
+
// when `theme.colors` isn't configured (see colorScheme.js).
|
|
3
|
+
//
|
|
4
|
+
// Its own module because both halves need it and they cannot share a
|
|
5
|
+
// file: colorScheme.js imports colorhorse, which has no business in the
|
|
6
|
+
// browser bundle, while the settings panel needs the same two values to
|
|
7
|
+
// show what the colour pickers are actually defaulting to. Same
|
|
8
|
+
// arrangement as typography.js and editor/directives.js - keep it free of
|
|
9
|
+
// node builtins.
|
|
10
|
+
export const fallbackColors = ["#5119ff", "#00edc6"]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { getScheme } from "colorhorse"
|
|
2
|
+
import { fallbackColors } from "./brandColors.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ten shades per role, named `01` (darkest) to `10` (lightest) in
|
|
6
|
+
* colorhorse's own darkest-first order. DefaultStyles.css reads them
|
|
7
|
+
* that way round: `light-dark(var(--primary-10), var(--primary-01))`
|
|
8
|
+
* is the body background. tests/colorScheme.js pins the order.
|
|
9
|
+
*/
|
|
10
|
+
const shadeCount = 10
|
|
11
|
+
|
|
12
|
+
/** @param {number} index */
|
|
13
|
+
function shadeName(index) {
|
|
14
|
+
return String(index).padStart(2, "0")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Builds the `:root` block for a theme's `colors` seed pair, falling
|
|
19
|
+
* back to Vowel's brand colors when a site hasn't configured any.
|
|
20
|
+
*
|
|
21
|
+
* Colors that *are* configured but unusable throw, so the author is told
|
|
22
|
+
* rather than left wondering why theirs did nothing; colorhorse's own
|
|
23
|
+
* messages are specific ("colorOne has a chroma of zero...") and are
|
|
24
|
+
* left to surface as they are.
|
|
25
|
+
* @param {unknown} colors - a theme setting's `colors`
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
function colorSchemeCSS(colors) {
|
|
29
|
+
if (colors === undefined || colors === null) return colorSchemeCSS(fallbackColors)
|
|
30
|
+
|
|
31
|
+
if (!Array.isArray(colors) || colors.length !== 2) {
|
|
32
|
+
throw new Error(`theme.colors must be an array of two "#rrggbb" colors, got ${JSON.stringify(colors)}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const [colorOne, colorTwo] = colors
|
|
36
|
+
const scheme = getScheme(colorOne, colorTwo, { shadeCount, minLightness: 0.3, maxLightness: 0.99, minChroma: 0.2 })
|
|
37
|
+
|
|
38
|
+
const declarations = Object.entries(scheme).flatMap(([role, ramp]) => (
|
|
39
|
+
ramp.map((color, index) => ` --${role}-${shadeName(index + 1)}: ${color};`)
|
|
40
|
+
))
|
|
41
|
+
|
|
42
|
+
return `:root {\n${declarations.join("\n")}\n}\n`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The build-facing entry point: always returns a usable `:root` block.
|
|
47
|
+
* Invalid configuration is reported through `onError` and then falls
|
|
48
|
+
* back to the brand colors, so a typo in settings.md leaves the site
|
|
49
|
+
* styled instead of stripping every color variable out from under
|
|
50
|
+
* DefaultStyles.css.
|
|
51
|
+
* @param {unknown} colors
|
|
52
|
+
* @param {(error: Error) => void} onError
|
|
53
|
+
* @returns {string}
|
|
54
|
+
*/
|
|
55
|
+
function themeColorSchemeCSS(colors, onError) {
|
|
56
|
+
try {
|
|
57
|
+
return colorSchemeCSS(colors)
|
|
58
|
+
} catch (error) {
|
|
59
|
+
onError(error)
|
|
60
|
+
return colorSchemeCSS(fallbackColors)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { colorSchemeCSS, themeColorSchemeCSS, fallbackColors }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import emojilib from "emojilib/dist/emoji-en-US.json" with { type: "json" }
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shortcode -> emoji, from emojilib. Each emoji's first keyword is its
|
|
5
|
+
* name (`grinning_face`, `party_popper`), and those win; the rest of its
|
|
6
|
+
* keywords (`smile`, `tada`, `+1`) are fallbacks, first emoji listed
|
|
7
|
+
* wins, so the GitHub-style short names still land somewhere sensible.
|
|
8
|
+
* Built once at load. Free of node builtins.
|
|
9
|
+
* @type {Map<string, string>}
|
|
10
|
+
*/
|
|
11
|
+
const byName = new Map()
|
|
12
|
+
const byKeyword = new Map()
|
|
13
|
+
|
|
14
|
+
for (const [emoji, keywords] of Object.entries(emojilib)) {
|
|
15
|
+
const [name, ...rest] = keywords
|
|
16
|
+
if (!byName.has(name)) byName.set(name, emoji)
|
|
17
|
+
for (const keyword of rest) {
|
|
18
|
+
if (!byKeyword.has(keyword)) byKeyword.set(keyword, emoji)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {string} shortcode - without the colons
|
|
24
|
+
* @returns {string | undefined}
|
|
25
|
+
*/
|
|
26
|
+
function emojiFor(shortcode) {
|
|
27
|
+
return byName.get(shortcode) ?? byKeyword.get(shortcode)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { emojiFor }
|