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
@@ -0,0 +1,116 @@
1
+ import { hash } from "node:crypto"
2
+ import { typographyCSS } from "../markdown/typography.js"
3
+
4
+ /**
5
+ * The themes vowel ships. A `theme` naming anything else gets no
6
+ * stylesheets at all, which is the behaviour the folder pass had.
7
+ */
8
+ const BUILT_IN_THEMES = ["reset", "typography", "default"]
9
+
10
+ /**
11
+ * A `theme` setting is either a bare name ("default") or an object
12
+ * carrying its own configuration ({name: "Default", colors: [...]}) -
13
+ * which is what `theme.colors` means as a path. Compared
14
+ * case-insensitively: settings.md is written by hand, and "Default" is
15
+ * what a person would type.
16
+ * @param {unknown} themeSetting
17
+ */
18
+ function resolveTheme(themeSetting) {
19
+ const isConfig = themeSetting && typeof themeSetting === "object" && !Array.isArray(themeSetting)
20
+ const config = isConfig ? themeSetting : { name: themeSetting }
21
+ const name = config.name ? String(config.name).toLowerCase() : "default"
22
+ return { config, name, known: BUILT_IN_THEMES.includes(name) }
23
+ }
24
+
25
+ /**
26
+ * A short, stable identity for a theme configuration: its canonical
27
+ * JSON (keys sorted at every depth), hashed. Two settings.md files that
28
+ * spell the same theme get the same key, and the same generated sheets.
29
+ * @param {unknown} themeSetting
30
+ */
31
+ function themeKey(themeSetting) {
32
+ const { config, name } = resolveTheme(themeSetting)
33
+ return hash("MD5", canonical({ ...config, name })).slice(0, 8)
34
+ }
35
+
36
+ /** @param {unknown} value */
37
+ function canonical(value) {
38
+ if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`
39
+ if (value && typeof value === "object") {
40
+ return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`
41
+ }
42
+ return JSON.stringify(value)
43
+ }
44
+
45
+ /** The generated sheets, the ones a theme's configuration decides. */
46
+ const GENERATED = /^(colors|type)(-[0-9a-f]{8})?\.css$/
47
+
48
+ /** The bundled sheets, part of the software rather than the project. */
49
+ const BUNDLED_SHEETS = ["reset.css", "typography.css", "default.css", "syntax-highlighting.css"]
50
+
51
+ /**
52
+ * The theme's stylesheets, in cascade order.
53
+ *
54
+ * **The single source of truth for two questions that must agree**: which
55
+ * sheets the styles processor declares as stubs, and which sheets a page
56
+ * links. They used to be one list built in the folder pass and written to
57
+ * a `stylesheets` setting that the html plugin read back; the list and the
58
+ * targets were produced by the same block, so they could not disagree.
59
+ * Now that the targets are stubs, this function is what keeps them in
60
+ * step - a sheet that is declared is linked, and nothing links a sheet
61
+ * that was never declared.
62
+ *
63
+ * A theme is a folder setting, so a folder can have its own - and the
64
+ * generated sheets (`colors.css`, `type.css`) are what differ between
65
+ * two themes; the bundled ones are shared. The root's theme keeps the
66
+ * plain names; any other theme's generated sheets carry the theme's
67
+ * key (`colors-3f9a2c1d.css`), so folders sharing a theme share a file
68
+ * and nothing is written twice.
69
+ *
70
+ * `type.css` is emitted only when the theme actually drives dynamic
71
+ * typography, and it comes before `colors.css`/`default.css` because a
72
+ * later `@layer` statement appends unseen layers to the end of the order.
73
+ *
74
+ * Every built-in is named here, `default` included: an undefined theme
75
+ * *is* the default theme, and a folder with none declared inherits
76
+ * whatever its nearest ancestor declared - `reset` at the root means
77
+ * `reset` below it, not `default`.
78
+ * @param {unknown} themeSetting - this folder's resolved theme
79
+ * @param {unknown} [rootThemeSetting] - the root's; omitted means "this
80
+ * is the root's". A rest parameter rather than a default, because an
81
+ * undeclared root theme is a real `undefined` that must not collapse
82
+ * into "same as this one".
83
+ * @returns {string[]}
84
+ */
85
+ function themeStylesheets(themeSetting, ...root) {
86
+ const rootThemeSetting = root.length ? root[0] : themeSetting
87
+ const { config, name, known } = resolveTheme(themeSetting)
88
+ if (!known) return []
89
+
90
+ const key = themeKey(themeSetting)
91
+ const suffix = key === themeKey(rootThemeSetting) ? "" : `-${key}`
92
+ const generated = (sheet) => `${sheet}${suffix}.css`
93
+
94
+ switch (name) {
95
+ case "reset":
96
+ return ["reset.css"]
97
+ case "typography":
98
+ return ["reset.css", "typography.css", ...(typographyCSS(config) ? [generated("type")] : [])]
99
+ case "default":
100
+ return ["reset.css", "typography.css", ...(typographyCSS(config) ? [generated("type")] : []), generated("colors"), "default.css"]
101
+ default:
102
+ return []
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Whether a stylesheet path is vowel's - bundled, or generated from a
108
+ * theme - as opposed to the project's own. Every one of them is a stub
109
+ * with a source path like any other source, so this is the test that
110
+ * separates them.
111
+ */
112
+ function isVowelStylesheet(sheetPath) {
113
+ return BUNDLED_SHEETS.includes(sheetPath) || GENERATED.test(sheetPath)
114
+ }
115
+
116
+ export { resolveTheme, themeStylesheets, themeKey, isVowelStylesheet, BUNDLED_SHEETS, BUILT_IN_THEMES }
@@ -1,83 +1,70 @@
1
- import { parseURLMetadata } from "votive/internals"
1
+ import path from "node:path"
2
+ import { hostSlug } from "votive"
3
+ import { default as parseURLMetadata } from "./urlMetadata.js"
2
4
 
3
5
  /** @import * as Votive from "votive" */
4
6
 
5
- const EXTERNAL_LINK_RE = /^https?:\/\/\S+$/
6
-
7
7
  /**
8
- * Matches a markdown paragraph whose only content is a bare URL - see
9
- * CLAUDE.md: "a URL that is the only child of a paragraph" -
10
- * Dinosaurs lived 65,000,000 years ago.
11
- *
12
- * https://dinosaurs.com/timeline
13
- *
14
- * We still find their fossils today.
15
- * Same shape html/index.js's own `testPaths` already matches for
16
- * internal single-link paragraphs (one text-only child) - this is the
17
- * external-URL counterpart.
18
- * @param {any} node
8
+ * A pure url reader. This plugin does not ask for anything: the html
9
+ * plugin asks, at write time, for every bare-url paragraph it renders,
10
+ * and votive drains the fetch queue after writeFile so that ask is
11
+ * fetched in the same pass. A transform-side walker used to live here
12
+ * too, which meant two walks over every page's tree for one question -
13
+ * and html-specific knowledge in a plugin whose job is parsing what came
14
+ * back.
19
15
  */
20
- function isExternalLinkParagraph(node) {
21
- if (node.type !== "element") return false
22
- if (node.tagName !== "p") return false
23
- if (node.children.length !== 1) return false
24
- const [child] = node.children
25
- if (!child || typeof child.value !== "string") return false
26
- return EXTERNAL_LINK_RE.test(child.value)
27
- }
28
16
 
29
17
  /**
30
- * Walks a target's abstract for link-preview paragraphs and queues one
31
- * fetch task per URL found, so the write side (html/index.js) can render
32
- * a preview card once the data is cached. Deliberately does not fetch
33
- * anything itself - tasks are only ever run when the caller invokes
34
- * runFetches() (see votive's fetchURLs.js), and a URL already cached
35
- * (success or in a failure cooldown) is skipped automatically, so this
36
- * never re-fetches the same link on every build.
37
- * @type {Votive.ReadAbstract}
18
+ * A readable path for a fetched page's file in the url store:
19
+ * `<host>/<last path segment or "index">`. The filename is not the
20
+ * identity - the url inside the file is - so this only has to be
21
+ * something a person can find. Votive appends a tiebreaker and `.yaml`.
22
+ * @param {URL} url
38
23
  */
39
- function transformFile(abstract, settings, api, config, targetFilePath) {
40
- const urls = []
41
-
42
- function walk(node) {
43
- if (!node || typeof node !== "object") return
44
- if (isExternalLinkParagraph(node)) {
45
- urls.push({
46
- data: node.children[0].value,
47
- runner: "text",
48
- target: targetFilePath
49
- })
50
- return
51
- }
52
- if (Array.isArray(node.children)) node.children.forEach(walk)
53
- }
54
-
55
- walk(abstract)
56
-
57
- return { abstract, urls }
24
+ function previewPath(url) {
25
+ const segments = url.pathname.split("/").filter(Boolean)
26
+ const leaf = (segments.at(-1) || "index")
27
+ .replace(/\.[a-z0-9]+$/i, "")
28
+ .toLowerCase()
29
+ .replace(/[^a-z0-9]+/g, "-")
30
+ .replace(/^-+|-+$/g, "")
31
+ .slice(0, 60) || "index"
32
+ return path.join(hostSlug(url), leaf)
58
33
  }
59
34
 
60
35
  /**
61
36
  * Parses a fetched page into the flat shape link-preview rendering
62
37
  * wants, preferring OpenGraph, then standard meta tags, then Twitter
63
- * Card, for each field independently.
64
- * @param {string} html
65
- * @returns {{ title: string, description: string, image: string | undefined }}
38
+ * Card, for each field independently, and says where to file it.
39
+ * The body method is lazy, so a plugin that only wanted headers would
40
+ * never read it; this one wants the HTML.
41
+ * @type {Votive.ProcessorReadURL}
66
42
  */
67
- function parseLinkPreview(html) {
68
- const meta = parseURLMetadata(html)
43
+ async function parseLinkPreview(response) {
44
+ const meta = parseURLMetadata(await response.text())
69
45
  return {
70
- title: meta.openGraph.title || meta.title || meta.twitterCard.title || "",
71
- description: meta.openGraph.description || meta.description || meta.twitterCard.description || "",
72
- image: meta.openGraph.image || meta.twitterCard.image || undefined
46
+ path: previewPath(response.url),
47
+ data: {
48
+ title: meta.openGraph.title || meta.title || meta.twitterCard.title || "",
49
+ description: meta.openGraph.description || meta.description || meta.twitterCard.description || "",
50
+ image: meta.openGraph.image || meta.twitterCard.image || undefined
51
+ }
73
52
  }
74
53
  }
75
54
 
76
- /** @type {Votive.VotiveProcessor} */
55
+ /**
56
+ * Parses what was fetched. Chosen by what the server says it sent -
57
+ * html, whatever the url looked like, so `bsky.app/profile/name.ca` is a
58
+ * page and not a ".ca file" - with the url's extension as the fallback
59
+ * for a response that names no type. Nothing else: an .mp3 or an .ical
60
+ * link is not a page and gets no preview until a processor for it
61
+ * exists. Exact matches only; there is no wildcard.
62
+ * @type {Votive.VotiveProcessor}
63
+ */
77
64
  const linkPreviewProcessor = {
78
- extensions: [".html"],
79
- format: "text",
80
- transformFile,
65
+ format: "url",
66
+ mediaTypes: ["text/html", "application/xhtml+xml"],
67
+ extensions: ["", ".html", ".htm"],
81
68
  readURL: parseLinkPreview
82
69
  }
83
70
 
@@ -88,4 +75,4 @@ const vowelURLsPlugin = {
88
75
  }
89
76
 
90
77
  export default vowelURLsPlugin
91
- export { isExternalLinkParagraph, parseLinkPreview }
78
+ export { parseLinkPreview, previewPath }
@@ -0,0 +1,246 @@
1
+ const META_TAG_RE = /<meta\s+[^>]*>/gi
2
+ const LINK_TAG_RE = /<link\s+[^>]*>/gi
3
+ const ATTR_RE = /([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g
4
+ const TITLE_TAG_RE = /<title[^>]*>([\s\S]*?)<\/title>/i
5
+ const LD_JSON_RE = /<script\s+[^>]*type\s*=\s*["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi
6
+
7
+ /**
8
+ * Decodes the handful of HTML entities that show up in meta/link
9
+ * attribute values often enough to matter for title/description text.
10
+ * Not a full entity table - just the five predefined XML entities.
11
+ * @param {string} value
12
+ */
13
+ function decodeEntities(value) {
14
+ return value
15
+ .replace(/&amp;/g, "&")
16
+ .replace(/&lt;/g, "<")
17
+ .replace(/&gt;/g, ">")
18
+ .replace(/&quot;/g, "\"")
19
+ .replace(/&#0?39;/g, "'")
20
+ }
21
+
22
+ /**
23
+ * Parses an HTML tag's attributes into a plain object, tolerant of
24
+ * attribute order and single/double quoting.
25
+ * @param {string} tag
26
+ * @returns {Record<string, string>}
27
+ */
28
+ function parseAttributes(tag) {
29
+ const attrs = {}
30
+ ATTR_RE.lastIndex = 0
31
+ let match
32
+ while ((match = ATTR_RE.exec(tag))) {
33
+ attrs[match[1].toLowerCase()] = match[2] ?? match[3] ?? ""
34
+ }
35
+ return attrs
36
+ }
37
+
38
+ /**
39
+ * @param {string} html
40
+ * @param {string} prefix
41
+ * @returns {Record<string, string>}
42
+ */
43
+ function parseMetaTagsByPrefix(html, prefix) {
44
+ const result = {}
45
+ const tags = html.match(META_TAG_RE) || []
46
+ for (const tag of tags) {
47
+ const attrs = parseAttributes(tag)
48
+ const key = attrs.property || attrs.name
49
+ if (!key || !key.startsWith(prefix) || attrs.content === undefined) continue
50
+ result[key.slice(prefix.length)] = decodeEntities(attrs.content)
51
+ }
52
+ return result
53
+ }
54
+
55
+ /**
56
+ * Extracts OpenGraph metadata (`<meta property="og:*">`) from an HTML
57
+ * string. Keys have the `og:` prefix stripped, e.g. `{ title, description,
58
+ * image, url, type, ... }`.
59
+ * @param {string} html
60
+ * @returns {Record<string, string>}
61
+ */
62
+ function parseOpenGraphTags(html) {
63
+ return parseMetaTagsByPrefix(html, "og:")
64
+ }
65
+
66
+ /**
67
+ * Extracts Twitter Card metadata (`<meta name="twitter:*">`) from an
68
+ * HTML string. Keys have the `twitter:` prefix stripped.
69
+ * @param {string} html
70
+ * @returns {Record<string, string>}
71
+ */
72
+ function parseTwitterCardTags(html) {
73
+ return parseMetaTagsByPrefix(html, "twitter:")
74
+ }
75
+
76
+ /**
77
+ * Returns a page's canonical URL (`<link rel="canonical">`), if present.
78
+ * @param {string} html
79
+ * @returns {string | undefined}
80
+ */
81
+ function parseCanonicalLink(html) {
82
+ const tags = html.match(LINK_TAG_RE) || []
83
+ for (const tag of tags) {
84
+ const attrs = parseAttributes(tag)
85
+ if (attrs.rel?.toLowerCase() === "canonical" && attrs.href) return attrs.href
86
+ }
87
+ return undefined
88
+ }
89
+
90
+ /**
91
+ * Returns a page's advertised oEmbed discovery URL
92
+ * (`<link type="application/json+oembed">`), if present. Discovery only -
93
+ * fetching this URL is the caller's responsibility, not this function's.
94
+ * @param {string} html
95
+ * @returns {string | undefined}
96
+ */
97
+ function parseOEmbedLink(html) {
98
+ const tags = html.match(LINK_TAG_RE) || []
99
+ for (const tag of tags) {
100
+ const attrs = parseAttributes(tag)
101
+ if (attrs.type === "application/json+oembed" && attrs.href) return attrs.href
102
+ }
103
+ return undefined
104
+ }
105
+
106
+ /**
107
+ * Returns a page's `<title>` text, if present.
108
+ * @param {string} html
109
+ * @returns {string | undefined}
110
+ */
111
+ function parseTitle(html) {
112
+ const match = html.match(TITLE_TAG_RE)
113
+ return match ? decodeEntities(match[1].trim()) : undefined
114
+ }
115
+
116
+ /**
117
+ * Returns a page's `<meta name="description">` content, if present.
118
+ * @param {string} html
119
+ * @returns {string | undefined}
120
+ */
121
+ function parseMetaDescription(html) {
122
+ return parseNamedMetaTag(html, "description")
123
+ }
124
+
125
+ /**
126
+ * Returns a page's `<meta name="keywords">` content as a list, split on
127
+ * commas and trimmed. Undefined if the tag is absent.
128
+ * @param {string} html
129
+ * @returns {string[] | undefined}
130
+ */
131
+ function parseMetaKeywords(html) {
132
+ const content = parseNamedMetaTag(html, "keywords")
133
+ if (content === undefined) return undefined
134
+ return content.split(",").map(keyword => keyword.trim()).filter(Boolean)
135
+ }
136
+
137
+ /**
138
+ * Returns a page's `<meta name="author">` content, if present.
139
+ * @param {string} html
140
+ * @returns {string | undefined}
141
+ */
142
+ function parseMetaAuthor(html) {
143
+ return parseNamedMetaTag(html, "author")
144
+ }
145
+
146
+ /**
147
+ * @param {string} html
148
+ * @param {string} name
149
+ * @returns {string | undefined}
150
+ */
151
+ function parseNamedMetaTag(html, name) {
152
+ const tags = html.match(META_TAG_RE) || []
153
+ for (const tag of tags) {
154
+ const attrs = parseAttributes(tag)
155
+ if (attrs.name?.toLowerCase() === name && attrs.content !== undefined) {
156
+ return decodeEntities(attrs.content)
157
+ }
158
+ }
159
+ return undefined
160
+ }
161
+
162
+ /**
163
+ * Returns a page's favicon URL, from any `<link rel="*icon*">` variant
164
+ * (`icon`, `shortcut icon`, `apple-touch-icon`, ...). Returns the first
165
+ * match found.
166
+ * @param {string} html
167
+ * @returns {string | undefined}
168
+ */
169
+ function parseFavicon(html) {
170
+ const tags = html.match(LINK_TAG_RE) || []
171
+ for (const tag of tags) {
172
+ const attrs = parseAttributes(tag)
173
+ if (attrs.rel?.toLowerCase().includes("icon") && attrs.href) return attrs.href
174
+ }
175
+ return undefined
176
+ }
177
+
178
+ /**
179
+ * Extracts schema.org structured data from `<script type="application/
180
+ * ld+json">` blocks. A page can carry more than one, so this returns an
181
+ * array - always, even for zero or one block found. Blocks that fail to
182
+ * parse as JSON are skipped rather than thrown, since this is running
183
+ * against untrusted external HTML.
184
+ * @param {string} html
185
+ * @returns {object[]}
186
+ */
187
+ function parseSchemaOrg(html) {
188
+ const results = []
189
+ LD_JSON_RE.lastIndex = 0
190
+ let match
191
+ while ((match = LD_JSON_RE.exec(html))) {
192
+ try {
193
+ results.push(JSON.parse(match[1]))
194
+ } catch (e) {
195
+ continue
196
+ }
197
+ }
198
+ return results
199
+ }
200
+
201
+ /**
202
+ * Convenience wrapper combining all the parsers above into one call, for
203
+ * a plugin's `read.url` handler to run against fetched HTML.
204
+ * @param {string} html
205
+ * @returns {{
206
+ * title: string | undefined,
207
+ * description: string | undefined,
208
+ * keywords: string[] | undefined,
209
+ * author: string | undefined,
210
+ * favicon: string | undefined,
211
+ * openGraph: Record<string, string>,
212
+ * twitterCard: Record<string, string>,
213
+ * canonical: string | undefined,
214
+ * oembedURL: string | undefined,
215
+ * schemaOrg: object[]
216
+ * }}
217
+ */
218
+ function metadata(html) {
219
+ return {
220
+ title: parseTitle(html),
221
+ description: parseMetaDescription(html),
222
+ keywords: parseMetaKeywords(html),
223
+ author: parseMetaAuthor(html),
224
+ favicon: parseFavicon(html),
225
+ openGraph: parseOpenGraphTags(html),
226
+ twitterCard: parseTwitterCardTags(html),
227
+ canonical: parseCanonicalLink(html),
228
+ oembedURL: parseOEmbedLink(html),
229
+ schemaOrg: parseSchemaOrg(html)
230
+ }
231
+ }
232
+
233
+ export {
234
+ parseTitle,
235
+ parseMetaDescription,
236
+ parseMetaKeywords,
237
+ parseMetaAuthor,
238
+ parseFavicon,
239
+ parseOpenGraphTags,
240
+ parseTwitterCardTags,
241
+ parseCanonicalLink,
242
+ parseOEmbedLink,
243
+ parseSchemaOrg,
244
+ metadata
245
+ }
246
+ export default metadata
@@ -4,7 +4,7 @@ import fs from "fs/promises"
4
4
  /** @type {Votive.ProcessorWrite} */
5
5
  async function writeFile(target) {
6
6
  return {
7
- data: target.abstract.svg
7
+ data: target.data
8
8
  }
9
9
  }
10
10
 
@@ -14,10 +14,11 @@ async function writeFile(target) {
14
14
  const processor = {
15
15
  extensions: [".svg"],
16
16
  format: "text",
17
- readFile: (text, filePath, targetPath, api) => {
17
+ router: ({ name, dir, ext }) => ({ name, dir, ext }),
18
+ readFile: ({ text }) => {
18
19
  const monochrome = text.includes("currentColor") || Boolean(text.match(/#000\b/))
19
20
  return {
20
- abstract: { svg: text },
21
+ data: text,
21
22
  metadata: { monochrome }
22
23
  }
23
24
  },
@@ -27,12 +28,7 @@ const processor = {
27
28
  /** @type {Votive.VotivePlugin} */
28
29
  const plugin = {
29
30
  name: "vowel-vectors",
30
- processors: [processor],
31
- router: ({ name, dir, ext }) => {
32
- return {
33
- name, dir, ext
34
- }
35
- }
31
+ processors: [processor]
36
32
  }
37
33
 
38
34
  export default plugin
@@ -0,0 +1,103 @@
1
+ import { fromHtml } from "hast-util-from-html"
2
+ import { toHtml } from "hast-util-to-html"
3
+ import { visit } from "unist-util-visit"
4
+
5
+ /**
6
+ * Attributes holding a single URL. `srcset` is handled separately: it is
7
+ * a comma-separated list of candidates, each a URL plus an optional
8
+ * descriptor.
9
+ */
10
+ const URL_PROPERTIES = ["src", "href", "poster"]
11
+
12
+ /**
13
+ * @param {string} value
14
+ * @param {string} domain
15
+ * @returns {string}
16
+ */
17
+ function absolute(value, domain) {
18
+ // Only root-relative paths need rewriting. A bare "#anchor" is left
19
+ // alone deliberately: in a reader it should still point within the
20
+ // entry, not back to the site.
21
+ if (!value.startsWith("/")) return value
22
+ return new URL(value, domain).href
23
+ }
24
+
25
+ /**
26
+ * @param {string} value - a srcset attribute
27
+ * @param {string} domain
28
+ * @returns {string}
29
+ */
30
+ function absoluteSrcset(value, domain) {
31
+ return value
32
+ .split(",")
33
+ .map(candidate => {
34
+ const [url, ...descriptor] = candidate.trim().split(/\s+/)
35
+ return [absolute(url, domain), ...descriptor].join(" ")
36
+ })
37
+ .join(", ")
38
+ }
39
+
40
+ /**
41
+ * @param {import("hast").Node} node
42
+ */
43
+ function isContentSection(node) {
44
+ if (node.type !== "element") return false
45
+ const id = node.properties?.id
46
+ return id === "content" || (Array.isArray(id) && id.includes("content"))
47
+ }
48
+
49
+ /**
50
+ * Pulls the post body out of a rendered page, with every URL made
51
+ * absolute.
52
+ *
53
+ * A feed entry's content is the *post*, not the page. `<main>` was the
54
+ * other candidate and is wrong: it also holds the breadcrumb nav, the
55
+ * table of contents and the rendered frontmatter lists, which are site
56
+ * furniture and read badly in a reader. `<section id=content>` is exactly
57
+ * the body.
58
+ *
59
+ * Taken from the rendered HTML rather than from `metadata.hastAbstract`,
60
+ * which is the tree as the markdown plugin produced it - before the html
61
+ * plugin resolves image paths, expands `/blog/**` directives and builds
62
+ * link-preview cards. A feed built from that would carry unresolved
63
+ * relative paths and literal directives.
64
+ *
65
+ * URLs are made absolute because a feed is read away from the site: a
66
+ * reader resolves `/necklace.jpg` against its own host, not yours.
67
+ *
68
+ * @param {string | null | undefined} html - the page's rendered output
69
+ * @param {string} domain - absolute, e.g. "https://example.com"
70
+ * @returns {string} the body as HTML, or "" when there is no content
71
+ */
72
+ export function entryContent(html, domain) {
73
+ if (!html) return ""
74
+
75
+ const tree = fromHtml(html, { fragment: false })
76
+
77
+ /** @type {import("hast").Element | undefined} */
78
+ let content
79
+ visit(tree, isContentSection, (node) => {
80
+ content = node
81
+ return false
82
+ })
83
+
84
+ if (!content) return ""
85
+
86
+ visit(content, "element", (node) => {
87
+ for (const property of URL_PROPERTIES) {
88
+ const value = node.properties?.[property]
89
+ if (typeof value === "string") node.properties[property] = absolute(value, domain)
90
+ }
91
+ const srcset = node.properties?.srcSet ?? node.properties?.srcset
92
+ if (typeof srcset === "string") {
93
+ const key = node.properties.srcSet !== undefined ? "srcSet" : "srcset"
94
+ node.properties[key] = absoluteSrcset(srcset, domain)
95
+ }
96
+ })
97
+
98
+ // The children, not the <section> itself - the wrapper is vowel's page
99
+ // structure, not part of the post.
100
+ return toHtml({ type: "root", children: content.children })
101
+ }
102
+
103
+ export default entryContent