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,78 @@
|
|
|
1
|
+
import path from "node:path"
|
|
2
|
+
import { hostSlug } from "votive"
|
|
3
|
+
import { default as parseURLMetadata } from "./urlMetadata.js"
|
|
4
|
+
|
|
5
|
+
/** @import * as Votive from "votive" */
|
|
6
|
+
|
|
7
|
+
/**
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
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
|
|
23
|
+
*/
|
|
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)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Parses a fetched page into the flat shape link-preview rendering
|
|
37
|
+
* wants, preferring OpenGraph, then standard meta tags, then Twitter
|
|
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}
|
|
42
|
+
*/
|
|
43
|
+
async function parseLinkPreview(response) {
|
|
44
|
+
const meta = parseURLMetadata(await response.text())
|
|
45
|
+
return {
|
|
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
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
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
|
+
*/
|
|
64
|
+
const linkPreviewProcessor = {
|
|
65
|
+
format: "url",
|
|
66
|
+
mediaTypes: ["text/html", "application/xhtml+xml"],
|
|
67
|
+
extensions: ["", ".html", ".htm"],
|
|
68
|
+
readURL: parseLinkPreview
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @type {Votive.VotivePlugin} */
|
|
72
|
+
const vowelURLsPlugin = {
|
|
73
|
+
name: "vowel-urls",
|
|
74
|
+
processors: [linkPreviewProcessor]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default vowelURLsPlugin
|
|
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(/&/g, "&")
|
|
16
|
+
.replace(/</g, "<")
|
|
17
|
+
.replace(/>/g, ">")
|
|
18
|
+
.replace(/"/g, "\"")
|
|
19
|
+
.replace(/�?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
|
package/plugins/vectors/index.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|