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
package/plugins/xml/index.js
CHANGED
|
@@ -1,31 +1,91 @@
|
|
|
1
1
|
import xml from "xml"
|
|
2
|
+
import { listPages } from "./../../utils.js"
|
|
3
|
+
import { entryContent } from "./entryContent.js"
|
|
2
4
|
|
|
3
5
|
/** @import * as Votive from "votive" */
|
|
4
6
|
|
|
5
7
|
|
|
8
|
+
/**
|
|
9
|
+
* `sitemap.xml` and `feed.xml` exist exactly while a `domain` is
|
|
10
|
+
* configured. They used to be created from the markdown plugin's
|
|
11
|
+
* readFile when it happened to be reading settings.md, and each write
|
|
12
|
+
* then had to answer "should I exist?" with `{delete: true}`. Declaring
|
|
13
|
+
* them here moves that question to the one place that can answer it
|
|
14
|
+
* cheaply, and deleting a domain now removes both targets and both files
|
|
15
|
+
* by the ordinary rule.
|
|
16
|
+
*
|
|
17
|
+
* `params` carries the domain so the stub re-expands when it changes;
|
|
18
|
+
* the writes read it from settings, tracked, so they rerun too.
|
|
19
|
+
* @type {Votive.ProcessorStubs}
|
|
20
|
+
*/
|
|
21
|
+
function createStubs({ settings }) {
|
|
22
|
+
const domain = settings.lastNonNull("fm_domain")
|
|
23
|
+
if (!domain) return []
|
|
24
|
+
return [
|
|
25
|
+
{ path: "sitemap.xml", params: { domain } },
|
|
26
|
+
{ path: "feed.xml", params: { domain } }
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Both files are generated wholesale by writeFile from live listings, so
|
|
32
|
+
* there is no meaningful source text - the stub exists to give each one a
|
|
33
|
+
* source, and therefore a lifetime.
|
|
34
|
+
* @type {Votive.ProcessorExpand}
|
|
35
|
+
*/
|
|
36
|
+
function expandStubs() {
|
|
37
|
+
return { text: "" }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Reads the domain a write should use. Taken from settings rather than
|
|
42
|
+
* from metadata stamped onto the target at creation: the stub declares
|
|
43
|
+
* the file's *existence*, and settings are the live value, so changing
|
|
44
|
+
* the domain restales both writes through the ordinary settings
|
|
45
|
+
* dependency instead of needing the creator to run again.
|
|
46
|
+
*/
|
|
47
|
+
function resolveDomain(settings) {
|
|
48
|
+
const domain = settings.lastNonNull("fm_domain")
|
|
49
|
+
if (!domain) return null
|
|
50
|
+
return String(domain).startsWith("http") ? String(domain) : "http://" + domain
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const DEFAULT_FEED_LIMIT = 20
|
|
54
|
+
|
|
6
55
|
/** @type {Votive.VotiveProcessor} */
|
|
7
56
|
const processor = {
|
|
57
|
+
router: ({ name, dir, ext }) => ({ name, dir, ext }),
|
|
8
58
|
extensions: [".xml"],
|
|
9
59
|
format: "text",
|
|
10
|
-
|
|
60
|
+
createStubs,
|
|
61
|
+
expandStubs,
|
|
62
|
+
// An .xml source carries nothing worth inferring; writeFile generates
|
|
63
|
+
// the whole document.
|
|
64
|
+
readFile: (source) => ({ data: source.text, metadata: {} }),
|
|
65
|
+
writeFile: (target, { settings, api }) => {
|
|
11
66
|
if (target.path === "sitemap.xml") {
|
|
12
|
-
|
|
13
67
|
// FIXME move the filter to SQLite
|
|
14
|
-
const pages =
|
|
15
|
-
.
|
|
68
|
+
const pages = api
|
|
69
|
+
.targets({
|
|
16
70
|
folder: "",
|
|
17
71
|
recursive: true,
|
|
18
|
-
query: {
|
|
19
|
-
|
|
72
|
+
query: {
|
|
73
|
+
"!": {
|
|
74
|
+
"|": {
|
|
75
|
+
"sitemap_item": false,
|
|
76
|
+
"html_file": false
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
20
80
|
})
|
|
21
|
-
.filter(a => a.
|
|
22
|
-
|
|
23
|
-
const domain = target.metadata.domain
|
|
24
|
-
&& target.metadata.domain.startsWith("http")
|
|
25
|
-
? target.metadata.domain
|
|
26
|
-
: "http://" + target.metadata.domain
|
|
81
|
+
.filter(a => a.extension === ".html" && a.path)
|
|
27
82
|
|
|
28
|
-
//
|
|
83
|
+
// No {delete: true} any more: this target exists only because the
|
|
84
|
+
// enumerator declared it, and it does that only when a domain is
|
|
85
|
+
// set. Removing the domain un-declares the stub, and votive deletes
|
|
86
|
+
// the row and the file by the same rule it deletes a page whose
|
|
87
|
+
// source was removed. Nothing deletes itself.
|
|
88
|
+
const domain = resolveDomain(settings)
|
|
29
89
|
if (!domain) return { data: "" }
|
|
30
90
|
|
|
31
91
|
function createEntry(page) {
|
|
@@ -57,25 +117,40 @@ const processor = {
|
|
|
57
117
|
const sitemap = createSitemap(pages, domain)
|
|
58
118
|
|
|
59
119
|
return {
|
|
60
|
-
data: sitemap
|
|
61
|
-
jobs: []
|
|
120
|
+
data: sitemap
|
|
62
121
|
}
|
|
63
122
|
|
|
64
123
|
} else if (target.path === "feed.xml") {
|
|
65
124
|
|
|
66
|
-
|
|
67
|
-
|
|
125
|
+
// The most recent entries, not every dated page the site has
|
|
126
|
+
// ever published: a feed is what changed lately, and a reader
|
|
127
|
+
// fetches it hourly. It is also what keeps an edit cheap - every
|
|
128
|
+
// entry's content is its rendered body, parsed out of the page,
|
|
129
|
+
// and the feed used to re-render all of them (800 pages: 850 ms,
|
|
130
|
+
// on every edit to any of them). Cut after listPages' own filter,
|
|
131
|
+
// so a hidden or virtual page in the top twenty doesn't cost the
|
|
132
|
+
// feed an entry; the rows are cheap, only `data` is not, and only
|
|
133
|
+
// the entries kept read it. `feed_limit` in settings.md raises or
|
|
134
|
+
// lowers it.
|
|
135
|
+
const limit = Number(settings.lastNonNull("fm_feed_limit")) || DEFAULT_FEED_LIMIT
|
|
136
|
+
const pages = listPages(api, {
|
|
137
|
+
query: {
|
|
138
|
+
"!": {
|
|
139
|
+
rss_item: false
|
|
140
|
+
}
|
|
141
|
+
},
|
|
68
142
|
folder: "",
|
|
69
143
|
recursive: true,
|
|
70
|
-
|
|
144
|
+
orderBy: { property: "date", direction: "desc" }
|
|
71
145
|
})
|
|
72
146
|
.filter(a => a.metadata.date)
|
|
73
|
-
.
|
|
147
|
+
.slice(0, limit)
|
|
74
148
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
149
|
+
// Same rule as the sitemap: every <id> and <link> is absolute, and
|
|
150
|
+
// Atom requires <id> to be an absolute IRI. Without a domain this
|
|
151
|
+
// branch used to emit the literal string "http://undefined/feed".
|
|
152
|
+
const domain = resolveDomain(settings)
|
|
153
|
+
if (!domain) return { data: "" }
|
|
79
154
|
|
|
80
155
|
const feed = [];
|
|
81
156
|
|
|
@@ -86,8 +161,8 @@ const processor = {
|
|
|
86
161
|
}
|
|
87
162
|
},
|
|
88
163
|
{
|
|
89
|
-
title:
|
|
90
|
-
}
|
|
164
|
+
title: settings.raw("fm_name")?.[0]?.at(-1)
|
|
165
|
+
},
|
|
91
166
|
)
|
|
92
167
|
|
|
93
168
|
|
|
@@ -105,21 +180,21 @@ const processor = {
|
|
|
105
180
|
}
|
|
106
181
|
);
|
|
107
182
|
|
|
108
|
-
|
|
183
|
+
const feedAuthor = settings.lastNonNull("fm_author")
|
|
184
|
+
if (feedAuthor)
|
|
109
185
|
feed.push(
|
|
186
|
+
// Children are an array: the xml package renders an object
|
|
187
|
+
// value as an empty element, which is how this was <author/>.
|
|
110
188
|
{
|
|
111
|
-
author: {
|
|
112
|
-
name: target.metadata.author
|
|
113
|
-
}
|
|
189
|
+
author: [{ name: feedAuthor }]
|
|
114
190
|
},
|
|
115
|
-
{ rights: `Copyright (c) ${new Date().getFullYear()} ${
|
|
191
|
+
{ rights: `Copyright (c) ${new Date().getFullYear()} ${feedAuthor}` }
|
|
116
192
|
);
|
|
117
193
|
|
|
118
194
|
feed.push(
|
|
119
195
|
...pages.map((page) => {
|
|
120
196
|
const url = (new URL(page.path, domain)).href
|
|
121
197
|
|
|
122
|
-
|
|
123
198
|
/** @type {object[]} */
|
|
124
199
|
const entry = [
|
|
125
200
|
{
|
|
@@ -145,22 +220,25 @@ const processor = {
|
|
|
145
220
|
|
|
146
221
|
if (page.metadata.author) {
|
|
147
222
|
entry.push({
|
|
148
|
-
author: {
|
|
149
|
-
name: page.metadata.author
|
|
150
|
-
}
|
|
223
|
+
author: [{ name: page.metadata.author }]
|
|
151
224
|
});
|
|
152
225
|
}
|
|
153
226
|
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
227
|
+
// The post body, not the page: entryContent pulls
|
|
228
|
+
// <section id=content> out of the rendered HTML and makes every
|
|
229
|
+
// URL absolute, because a reader resolves /necklace.jpg against
|
|
230
|
+
// its own host. type="html" is required by Atom for a content
|
|
231
|
+
// element holding markup - without it a reader may show the
|
|
232
|
+
// tags as text.
|
|
233
|
+
const content = entryContent(page.data, domain)
|
|
234
|
+
if (content) {
|
|
235
|
+
entry.push({
|
|
236
|
+
content: [
|
|
237
|
+
{ _attr: { type: "html" } },
|
|
238
|
+
content
|
|
239
|
+
]
|
|
240
|
+
})
|
|
241
|
+
}
|
|
164
242
|
|
|
165
243
|
return {
|
|
166
244
|
entry
|
|
@@ -185,12 +263,7 @@ const processor = {
|
|
|
185
263
|
/** @type {Votive.VotivePlugin} */
|
|
186
264
|
const vowelXMLPlugin = {
|
|
187
265
|
name: "vowel-xml",
|
|
188
|
-
processors: [processor]
|
|
189
|
-
router: ({ name, dir, ext }) => {
|
|
190
|
-
return {
|
|
191
|
-
name, dir, ext
|
|
192
|
-
}
|
|
193
|
-
}
|
|
266
|
+
processors: [processor]
|
|
194
267
|
}
|
|
195
268
|
|
|
196
269
|
export default vowelXMLPlugin
|
package/secretPaths.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { hash } from "node:crypto"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Secret paths.
|
|
6
|
+
*
|
|
7
|
+
* A `##` inside a file or folder name, with a word character on each
|
|
8
|
+
* side, marks that segment secret. The text before it is the **name**; the text
|
|
9
|
+
* after it is the **salt**. The whole segment is replaced by a hash, so
|
|
10
|
+
* the page - or the whole folder - is published at an unguessable URL
|
|
11
|
+
* and nowhere else.
|
|
12
|
+
*
|
|
13
|
+
* blog/hidden##purple-bear/post.md -> blog/<hash>/post.html
|
|
14
|
+
* hello-world##red-whale.md -> <hash>.html
|
|
15
|
+
*
|
|
16
|
+
* **The hash input is frozen.** Changing any part of it rotates every
|
|
17
|
+
* secret URL on every site, silently. It is:
|
|
18
|
+
*
|
|
19
|
+
* the project-relative source path, forward slashes (whatever the
|
|
20
|
+
* platform's separator), no leading slash,
|
|
21
|
+
* up to and including the segment being hashed, salt in place, and a
|
|
22
|
+
* file's extension left off.
|
|
23
|
+
*
|
|
24
|
+
* So `blog/hidden##purple-bear/post.md` hashes its folder from
|
|
25
|
+
* `"blog/hidden##purple-bear"`, and `reports/dev##blue-parrot.md` hashes
|
|
26
|
+
* from `"reports/dev##blue-parrot"`. Without the extension, a page and
|
|
27
|
+
* the folder it indexes hash alike: `abc##xyz.md` is `<hash>.html` beside
|
|
28
|
+
* `abc##xyz/` at `<hash>/`, as `blog.md` sits beside `blog/`. Two files
|
|
29
|
+
* differing only by extension share a hash and keep their extensions,
|
|
30
|
+
* as `photo.md` and `photo.jpg` do. Each segment hashes against the
|
|
31
|
+
* *original* path, not one already rewritten above it, so the value is
|
|
32
|
+
* reproducible by hand. SHA-256, first 16 hex characters: 64 bits is far
|
|
33
|
+
* beyond guessable for a share-link, and short enough to paste.
|
|
34
|
+
*
|
|
35
|
+
* **This is a routing rule, installed as votive's `config.router`**, not
|
|
36
|
+
* a markdown feature. A secret folder holds images, fonts and stylesheets
|
|
37
|
+
* as well as pages, each routed by a different processor - a rule
|
|
38
|
+
* implemented per-processor leaks the folder name through whichever
|
|
39
|
+
* processor forgets it. One cascade above them all cannot be forgotten.
|
|
40
|
+
*
|
|
41
|
+
* Only routing is rewritten. The source keeps its real path everywhere it
|
|
42
|
+
* is stored, diffed or looked up. That means **the salt is in the
|
|
43
|
+
* database**, and every place a source path can reach rendered output
|
|
44
|
+
* has to go through `displayName()` first - the title, the breadcrumb,
|
|
45
|
+
* anything derived from a filename. `tests/secretPaths.js` walks the
|
|
46
|
+
* output folder and asserts no salt appears in it.
|
|
47
|
+
*
|
|
48
|
+
* `#` is legal in a filename on every platform and is plain ASCII, so
|
|
49
|
+
* nothing re-encodes it. It is the URL fragment character, which is
|
|
50
|
+
* why the marker must never reach a url: routing replaces the segment,
|
|
51
|
+
* and a relative link is decoded and resolved by *source* path before
|
|
52
|
+
* it becomes an href. The one place it could bite is a link that fails
|
|
53
|
+
* to resolve, which is left as written - tested.
|
|
54
|
+
*
|
|
55
|
+
* The security model is the unguessable URL. The salt is only as secret
|
|
56
|
+
* as the source tree.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
const MARKER = "##"
|
|
60
|
+
|
|
61
|
+
/** Lowercase by construction; votive lowercases stored target paths. */
|
|
62
|
+
function hashSegmentInput(input) {
|
|
63
|
+
return hash("sha256", input).slice(0, 16)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Splits a segment's stem into name and salt. `null` when it carries no
|
|
68
|
+
* marker. Throws on a malformed one - an empty name or salt, or a second
|
|
69
|
+
* marker - rather than guessing which part is which.
|
|
70
|
+
* @param {string} stem - a segment without its extension
|
|
71
|
+
* @param {string} sourcePath - for the error message
|
|
72
|
+
* @returns {{ name: string, salt: string } | null}
|
|
73
|
+
*/
|
|
74
|
+
function parseSecret(stem, sourcePath) {
|
|
75
|
+
const first = stem.indexOf(MARKER)
|
|
76
|
+
if (first === -1) return null
|
|
77
|
+
|
|
78
|
+
const name = stem.slice(0, first)
|
|
79
|
+
const salt = stem.slice(first + MARKER.length)
|
|
80
|
+
|
|
81
|
+
if (!name || !salt || !/\w$/.test(name) || !/^\w/.test(salt) || salt.includes(MARKER) || salt.includes("#")) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`"${sourcePath}": a secret segment is "<name>${MARKER}<salt>" with a word character ` +
|
|
84
|
+
`on each side of the ${MARKER}, and only one ${MARKER}. Got "${stem}".`
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return { name, salt }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A filename's stem and extension; a folder segment has no extension. */
|
|
92
|
+
function splitExtension(segment, isFile) {
|
|
93
|
+
if (!isFile) return { stem: segment, ext: "" }
|
|
94
|
+
const dot = segment.lastIndexOf(".")
|
|
95
|
+
if (dot <= 0) return { stem: segment, ext: "" }
|
|
96
|
+
return { stem: segment.slice(0, dot), ext: segment.slice(dot) }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* votive's `config.router`: source path in, source path out.
|
|
101
|
+
* @param {string} sourcePath - relative to sourceFolder
|
|
102
|
+
* @returns {string}
|
|
103
|
+
*/
|
|
104
|
+
function secretRouter(sourcePath) {
|
|
105
|
+
if (!sourcePath.includes(MARKER)) return sourcePath
|
|
106
|
+
|
|
107
|
+
// Stored paths use the platform separator; the hash *input* never does.
|
|
108
|
+
// It is frozen as forward-slash-joined so the same file hashes the same
|
|
109
|
+
// on every platform - otherwise a project moved to Windows would rotate
|
|
110
|
+
// every secret url.
|
|
111
|
+
const segments = sourcePath.split(path.sep)
|
|
112
|
+
|
|
113
|
+
return segments.map((segment, index) => {
|
|
114
|
+
const isFile = index === segments.length - 1
|
|
115
|
+
const { stem, ext } = splitExtension(segment, isFile)
|
|
116
|
+
if (!parseSecret(stem, sourcePath)) return segment
|
|
117
|
+
|
|
118
|
+
// Hashed from the original path up to and including this segment,
|
|
119
|
+
// without its extension.
|
|
120
|
+
const input = [...segments.slice(0, index), stem].join("/")
|
|
121
|
+
return hashSegmentInput(input) + ext
|
|
122
|
+
}).join(path.sep)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Does this source path have any secret segment? The read uses it to mark
|
|
127
|
+
* the page hidden, which keeps it out of every listing.
|
|
128
|
+
* @param {string} sourcePath
|
|
129
|
+
*/
|
|
130
|
+
function isSecretPath(sourcePath) {
|
|
131
|
+
return sourcePath.includes(MARKER)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A source path with every salt removed: what the name looks like to a
|
|
136
|
+
* reader. `blog/hidden##purple-bear/post.md` -> `blog/hidden/post.md`.
|
|
137
|
+
*
|
|
138
|
+
* **The single guard between the salt and the rendered page.** Anything
|
|
139
|
+
* that derives a title, a label or a breadcrumb from a source path goes
|
|
140
|
+
* through here first.
|
|
141
|
+
* @param {string} sourcePath
|
|
142
|
+
*/
|
|
143
|
+
function displayPath(sourcePath) {
|
|
144
|
+
if (!sourcePath.includes(MARKER)) return sourcePath
|
|
145
|
+
|
|
146
|
+
const segments = sourcePath.split(path.sep)
|
|
147
|
+
return segments.map((segment, index) => {
|
|
148
|
+
const isFile = index === segments.length - 1
|
|
149
|
+
const { stem, ext } = splitExtension(segment, isFile)
|
|
150
|
+
const secret = parseSecret(stem, sourcePath)
|
|
151
|
+
return secret ? secret.name + ext : segment
|
|
152
|
+
}).join(path.sep)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Every salt in a source path, for the leak test.
|
|
157
|
+
* @param {string} sourcePath
|
|
158
|
+
* @returns {string[]}
|
|
159
|
+
*/
|
|
160
|
+
function saltsIn(sourcePath) {
|
|
161
|
+
if (!sourcePath.includes(MARKER)) return []
|
|
162
|
+
const segments = sourcePath.split(path.sep)
|
|
163
|
+
return segments.flatMap((segment, index) => {
|
|
164
|
+
const { stem } = splitExtension(segment, index === segments.length - 1)
|
|
165
|
+
const secret = parseSecret(stem, sourcePath)
|
|
166
|
+
return secret ? [secret.salt] : []
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { MARKER, secretRouter, isSecretPath, displayPath, saltsIn, hashSegmentInput }
|