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
@@ -1,13 +1,68 @@
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
- writeFile: (target, settings, api) => {
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
67
  // FIXME move the filter to SQLite
13
68
  const pages = api
@@ -25,12 +80,12 @@ const processor = {
25
80
  })
26
81
  .filter(a => a.extension === ".html" && a.path)
27
82
 
28
- const domain = target.metadata.domain
29
- && target.metadata.domain.startsWith("http")
30
- ? target.metadata.domain
31
- : "http://" + target.metadata.domain
32
-
33
- // FIXME allow falsey returns from writeFile to abort write
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)
34
89
  if (!domain) return { data: "" }
35
90
 
36
91
  function createEntry(page) {
@@ -62,13 +117,23 @@ const processor = {
62
117
  const sitemap = createSitemap(pages, domain)
63
118
 
64
119
  return {
65
- data: sitemap,
66
- urls: []
120
+ data: sitemap
67
121
  }
68
122
 
69
123
  } else if (target.path === "feed.xml") {
70
124
 
71
- const pages = api.targets({
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, {
72
137
  query: {
73
138
  "!": {
74
139
  rss_item: false
@@ -79,11 +144,13 @@ const processor = {
79
144
  orderBy: { property: "date", direction: "desc" }
80
145
  })
81
146
  .filter(a => a.metadata.date)
147
+ .slice(0, limit)
82
148
 
83
- const domain = target.metadata.domain
84
- && target.metadata.domain.startsWith("http")
85
- ? target.metadata.domain
86
- : "http://" + target.metadata.domain
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: "" }
87
154
 
88
155
  const feed = [];
89
156
 
@@ -94,7 +161,7 @@ const processor = {
94
161
  }
95
162
  },
96
163
  {
97
- title: target.metadata.title
164
+ title: settings.raw("fm_name")?.[0]?.at(-1)
98
165
  },
99
166
  )
100
167
 
@@ -113,14 +180,15 @@ const processor = {
113
180
  }
114
181
  );
115
182
 
116
- if (target.metadata.author)
183
+ const feedAuthor = settings.lastNonNull("fm_author")
184
+ if (feedAuthor)
117
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/>.
118
188
  {
119
- author: {
120
- name: target.metadata.author
121
- }
189
+ author: [{ name: feedAuthor }]
122
190
  },
123
- { rights: `Copyright (c) ${new Date().getFullYear()} ${target.metadata.author}` }
191
+ { rights: `Copyright (c) ${new Date().getFullYear()} ${feedAuthor}` }
124
192
  );
125
193
 
126
194
  feed.push(
@@ -152,26 +220,25 @@ const processor = {
152
220
 
153
221
  if (page.metadata.author) {
154
222
  entry.push({
155
- author: {
156
- name: page.metadata.author
157
- }
223
+ author: [{ name: page.metadata.author }]
158
224
  });
159
225
  }
160
226
 
161
- entry.push({
162
- content: page.data
163
- })
164
-
165
- // TODO consider rendering full page in RSS
166
-
167
- /*
168
- entry.push({
169
- content: [
170
- { _attr: { type: 'html' } },
171
- render(Page, { props: { page, level: 0, format: 'rss' } }).html
172
- ]
173
- });
174
- */
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
+ }
175
242
 
176
243
  return {
177
244
  entry
@@ -196,12 +263,7 @@ const processor = {
196
263
  /** @type {Votive.VotivePlugin} */
197
264
  const vowelXMLPlugin = {
198
265
  name: "vowel-xml",
199
- processors: [processor],
200
- router: ({ name, dir, ext }) => {
201
- return {
202
- name, dir, ext
203
- }
204
- }
266
+ processors: [processor]
205
267
  }
206
268
 
207
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 }