vowel 0.7.1-beta.0 → 0.7.3
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/LICENSE +21 -0
- package/README.md +41 -239
- package/bin.js +91 -31
- package/cli.js +32 -0
- package/config.js +12 -0
- package/extractDate.js +1 -1
- package/package.json +8 -34
- package/pathDate.js +69 -0
- package/plugins/assets/index.js +1 -1
- package/plugins/atproto/body.js +3 -1
- package/plugins/atproto/index.js +5 -45
- package/plugins/atproto/publish.js +42 -11
- package/plugins/atproto/record.js +47 -4
- package/plugins/deploy-cloudflare/index.js +4 -1
- package/plugins/export/index.js +131 -0
- package/plugins/html/bundle/index.js +101 -44
- package/plugins/html/editor/Editor.svelte +9 -5
- package/plugins/html/editor/create-session.js +3 -1
- package/plugins/html/editor/directives.js +12 -0
- package/plugins/html/editor/frontmatter.js +77 -12
- package/plugins/html/editor/ingest.js +29 -31
- package/plugins/html/editor/main.js +5 -1
- package/plugins/html/editor/serialize.js +8 -4
- package/plugins/html/editor/socket.js +34 -4
- package/plugins/html/image.js +88 -27
- package/plugins/html/index.js +237 -109
- package/plugins/html/partials.js +41 -17
- package/plugins/html/socialLinks.js +13 -11
- package/plugins/html/writeRules.js +234 -42
- package/plugins/images/favicon.png +0 -0
- package/plugins/images/index.js +69 -8
- package/plugins/markdown/colorScheme.js +70 -14
- package/plugins/markdown/frontmatter.js +18 -8
- package/plugins/markdown/index.js +94 -25
- package/plugins/markdown/metadata.js +132 -32
- package/plugins/markdown/typography.js +11 -11
- package/plugins/styles/index.js +4 -4
- package/plugins/xml/index.js +17 -10
- package/stylesheets/DefaultStyles.css +163 -108
- package/stylesheets/TypographyStyles.css +148 -81
- package/utils.js +74 -21
|
@@ -9,17 +9,17 @@
|
|
|
9
9
|
:root {
|
|
10
10
|
/*
|
|
11
11
|
these variables declare a stack with system fallbacks
|
|
12
|
-
declare brand fonts with `--
|
|
12
|
+
declare brand fonts with `--fontfamily-x-brand` to keep stack intact
|
|
13
13
|
*/
|
|
14
|
-
--
|
|
15
|
-
--
|
|
16
|
-
--
|
|
14
|
+
--fontfamily-serif: var(--fontfamily-serif-brand), var(--fontfamily-serif-system);
|
|
15
|
+
--fontfamily-sans: var(--fontfamily-sans-brand), var(--fontfamily-sans-system);
|
|
16
|
+
--fontfamily-monospace: var(--fontfamily-monospace-brand), var(--fontfamily-monospace-system);
|
|
17
17
|
|
|
18
|
-
--
|
|
19
|
-
--
|
|
20
|
-
--
|
|
18
|
+
--fontfamily-serif-brand: "Declare a brand serif font with this variable";
|
|
19
|
+
--fontfamily-sans-brand: "Declare a brand sans-serif font with this variable";
|
|
20
|
+
--fontfamily-monospace-brand: "Declare a brand monospace font with this variable";
|
|
21
21
|
|
|
22
|
-
--
|
|
22
|
+
--fontfamily-sans-system:
|
|
23
23
|
-apple-system,
|
|
24
24
|
BlinkMacSystemFont,
|
|
25
25
|
avenir next,
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
arial,
|
|
35
35
|
sans-serif;
|
|
36
36
|
|
|
37
|
-
--
|
|
37
|
+
--fontfamily-monospace-system:
|
|
38
38
|
Menlo,
|
|
39
39
|
Consolas,
|
|
40
40
|
Monaco,
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
Lucida Console,
|
|
43
43
|
monospace;
|
|
44
44
|
|
|
45
|
-
--
|
|
45
|
+
--fontfamily-serif-system:
|
|
46
46
|
Iowan Old Style,
|
|
47
47
|
Apple Garamond,
|
|
48
48
|
Baskerville,
|
|
@@ -60,68 +60,96 @@
|
|
|
60
60
|
the recommended root font size on small screens (16px) and
|
|
61
61
|
large screens (18px)
|
|
62
62
|
*/
|
|
63
|
-
--
|
|
63
|
+
--fontsize-root: clamp(1rem, 0.875rem + 0.333vw, 1.125rem);
|
|
64
64
|
|
|
65
65
|
/*
|
|
66
66
|
the difference in size of h1 relative to the root
|
|
67
67
|
font size; increase or decrease this number for larger or
|
|
68
68
|
smaller headings
|
|
69
69
|
*/
|
|
70
|
-
--
|
|
70
|
+
--fontsize-delta: calc(1.5 * var(--fontsize-root));
|
|
71
71
|
|
|
72
72
|
/*
|
|
73
73
|
the rate of decay from h1 to h6 font size, where h6 is
|
|
74
74
|
almost as small as the root font size; a higher number
|
|
75
75
|
makes subheadings smaller
|
|
76
76
|
*/
|
|
77
|
-
--
|
|
77
|
+
--fontsize-decay: 3;
|
|
78
78
|
|
|
79
79
|
/*
|
|
80
80
|
letter spacing of h1 and h6, with h2-h6 imputed
|
|
81
81
|
according to the decay variable
|
|
82
82
|
*/
|
|
83
|
-
--
|
|
84
|
-
--
|
|
85
|
-
--
|
|
83
|
+
--letterspacing-h1: -0.01ch;
|
|
84
|
+
--letterspacing-h6: 0ch;
|
|
85
|
+
--letterspacing-decay: 2;
|
|
86
86
|
|
|
87
87
|
/*
|
|
88
88
|
weight of h1 and h6, with h2-h6 imputed according
|
|
89
89
|
to the decay variable
|
|
90
90
|
*/
|
|
91
|
-
--
|
|
92
|
-
--
|
|
93
|
-
--
|
|
91
|
+
--fontweight-h1: 800;
|
|
92
|
+
--fontweight-h6: 600;
|
|
93
|
+
--fontweight-decay: 2;
|
|
94
94
|
|
|
95
95
|
/*
|
|
96
96
|
*do not edit or overwrite*: calculations to impute
|
|
97
97
|
font sizes, weights, and spacing between h1 and h6
|
|
98
98
|
*/
|
|
99
|
-
--
|
|
100
|
-
--
|
|
101
|
-
--
|
|
102
|
-
--
|
|
103
|
-
--
|
|
104
|
-
--
|
|
105
|
-
--
|
|
106
|
-
--
|
|
107
|
-
--
|
|
108
|
-
--
|
|
109
|
-
--
|
|
110
|
-
--
|
|
111
|
-
--
|
|
112
|
-
--
|
|
113
|
-
--
|
|
114
|
-
--
|
|
99
|
+
--fontsize-h1: calc(var(--fontsize-root) + var(--fontsize-delta));
|
|
100
|
+
--fontsize-h2: calc(var(--fontsize-root) + calc(var(--fontsize-delta) * pow(5 / 6, var(--fontsize-decay))));
|
|
101
|
+
--fontsize-h3: calc(var(--fontsize-root) + calc(var(--fontsize-delta) * pow(4 / 6, var(--fontsize-decay))));
|
|
102
|
+
--fontsize-h4: calc(var(--fontsize-root) + calc(var(--fontsize-delta) * pow(3 / 6, var(--fontsize-decay))));
|
|
103
|
+
--fontsize-h5: calc(var(--fontsize-root) + calc(var(--fontsize-delta) * pow(2 / 6, var(--fontsize-decay))));
|
|
104
|
+
--fontsize-h6: calc(var(--fontsize-root) + calc(var(--fontsize-delta) * pow(1 / 6, var(--fontsize-decay))));
|
|
105
|
+
--_letterspacing-delta: calc(var(--letterspacing-h1) - var(--letterspacing-h6));
|
|
106
|
+
--letterspacing-h2: calc(var(--letterspacing-h6) + calc(var(--_letterspacing-delta) * pow(5 / 6, var(--letterspacing-decay))));
|
|
107
|
+
--letterspacing-h3: calc(var(--letterspacing-h6) + calc(var(--_letterspacing-delta) * pow(4 / 6, var(--letterspacing-decay))));
|
|
108
|
+
--letterspacing-h4: calc(var(--letterspacing-h6) + calc(var(--_letterspacing-delta) * pow(3 / 6, var(--letterspacing-decay))));
|
|
109
|
+
--letterspacing-h5: calc(var(--letterspacing-h6) + calc(var(--_letterspacing-delta) * pow(2 / 6, var(--letterspacing-decay))));
|
|
110
|
+
--_fontweight-delta: calc(var(--fontweight-h1) - var(--fontweight-h6));
|
|
111
|
+
--fontweight-h2: calc(var(--fontweight-h6) + calc(var(--_fontweight-delta) * pow(5 / 6, var(--fontweight-decay))));
|
|
112
|
+
--fontweight-h3: calc(var(--fontweight-h6) + calc(var(--_fontweight-delta) * pow(4 / 6, var(--fontweight-decay))));
|
|
113
|
+
--fontweight-h4: calc(var(--fontweight-h6) + calc(var(--_fontweight-delta) * pow(3 / 6, var(--fontweight-decay))));
|
|
114
|
+
--fontweight-h5: calc(var(--fontweight-h6) + calc(var(--_fontweight-delta) * pow(2 / 6, var(--fontweight-decay))));
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
heading sizes by context, for the contexts that differ: in
|
|
118
|
+
main, a heading inside a listing card (article), an aside or a
|
|
119
|
+
blockquote is set a step or two down the ramp. Set one of
|
|
120
|
+
these to change that context alone. No context is the
|
|
121
|
+
default, everywhere else.
|
|
122
|
+
*/
|
|
123
|
+
--fontsize-h1-article: var(--fontsize-h3);
|
|
124
|
+
--fontsize-h2-article: var(--fontsize-h3);
|
|
125
|
+
--fontsize-h3-article: var(--fontsize-h4);
|
|
126
|
+
--fontsize-h4-article: var(--fontsize-h5);
|
|
127
|
+
--fontsize-h5-article: var(--fontsize-h6);
|
|
128
|
+
--fontsize-h1-aside: var(--fontsize-h3);
|
|
129
|
+
--fontsize-h2-aside: var(--fontsize-h3);
|
|
130
|
+
--fontsize-h3-aside: var(--fontsize-h4);
|
|
131
|
+
--fontsize-h4-aside: var(--fontsize-h5);
|
|
132
|
+
--fontsize-h5-aside: var(--fontsize-h6);
|
|
133
|
+
--fontsize-h1-blockquote: var(--fontsize-h3);
|
|
134
|
+
--fontsize-h2-blockquote: var(--fontsize-h3);
|
|
135
|
+
--fontsize-h3-blockquote: var(--fontsize-h4);
|
|
136
|
+
--fontsize-h4-blockquote: var(--fontsize-h5);
|
|
137
|
+
--fontsize-h5-blockquote: var(--fontsize-h6);
|
|
138
|
+
|
|
139
|
+
/* the site's name, in the header */
|
|
140
|
+
--fontsize-name-header: var(--fontsize-h3);
|
|
141
|
+
--fontweight-name-header: var(--fontweight-h1);
|
|
142
|
+
--letterspacing-name-header: var(--letterspacing-h1);
|
|
115
143
|
}
|
|
116
144
|
|
|
117
145
|
html {
|
|
118
|
-
font-family: var(--
|
|
146
|
+
font-family: var(--fontfamily-sans);
|
|
119
147
|
}
|
|
120
148
|
|
|
121
149
|
pre,
|
|
122
150
|
code,
|
|
123
151
|
kbd {
|
|
124
|
-
font-family: var(--
|
|
152
|
+
font-family: var(--fontfamily-monospace);
|
|
125
153
|
}
|
|
126
154
|
|
|
127
155
|
/*
|
|
@@ -189,8 +217,11 @@
|
|
|
189
217
|
|
|
190
218
|
table {
|
|
191
219
|
border-collapse: collapse;
|
|
192
|
-
|
|
193
|
-
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* a table too wide for the page scrolls sideways inside its figure */
|
|
223
|
+
figure:has(>table) {
|
|
224
|
+
overflow-x: auto;
|
|
194
225
|
}
|
|
195
226
|
|
|
196
227
|
time {
|
|
@@ -303,15 +334,15 @@
|
|
|
303
334
|
&>section {
|
|
304
335
|
margin-top: 1lh;
|
|
305
336
|
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/* content */
|
|
309
|
-
section {
|
|
310
337
|
|
|
311
|
-
/* image caption space */
|
|
338
|
+
/* image caption space: the page's own captioned image, beside its title, as well as the content's */
|
|
312
339
|
figure {
|
|
313
340
|
gap: 1lh;
|
|
314
341
|
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/* content */
|
|
345
|
+
section {
|
|
315
346
|
|
|
316
347
|
/* list spacing */
|
|
317
348
|
ul,
|
|
@@ -339,6 +370,12 @@
|
|
|
339
370
|
overflow-x: auto;
|
|
340
371
|
}
|
|
341
372
|
|
|
373
|
+
/* markdown is prose: its long lines wrap rather than scroll */
|
|
374
|
+
pre:has(>code:is(.language-markdown, .language-md)) {
|
|
375
|
+
white-space: pre-wrap;
|
|
376
|
+
overflow-wrap: anywhere;
|
|
377
|
+
}
|
|
378
|
+
|
|
342
379
|
/* table spacing */
|
|
343
380
|
td,
|
|
344
381
|
th {
|
|
@@ -379,79 +416,109 @@
|
|
|
379
416
|
*/
|
|
380
417
|
|
|
381
418
|
body {
|
|
382
|
-
font-size: var(--
|
|
419
|
+
font-size: var(--fontsize-root);
|
|
383
420
|
}
|
|
384
421
|
|
|
385
422
|
h1 {
|
|
386
|
-
font-size: var(--
|
|
387
|
-
letter-spacing: var(--
|
|
388
|
-
font-weight: var(--
|
|
423
|
+
font-size: var(--fontsize-h1);
|
|
424
|
+
letter-spacing: var(--letterspacing-h1);
|
|
425
|
+
font-weight: var(--fontweight-h1);
|
|
426
|
+
|
|
427
|
+
main article & {
|
|
428
|
+
font-size: var(--fontsize-h1-article);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
main aside & {
|
|
432
|
+
font-size: var(--fontsize-h1-aside);
|
|
433
|
+
}
|
|
389
434
|
|
|
390
|
-
main article &,
|
|
391
|
-
main aside &,
|
|
392
435
|
main blockquote & {
|
|
393
|
-
font-size: var(--
|
|
436
|
+
font-size: var(--fontsize-h1-blockquote);
|
|
394
437
|
}
|
|
395
438
|
}
|
|
396
439
|
|
|
397
440
|
h2 {
|
|
398
|
-
font-size: var(--
|
|
399
|
-
letter-spacing: var(--
|
|
400
|
-
font-weight: var(--
|
|
441
|
+
font-size: var(--fontsize-h2);
|
|
442
|
+
letter-spacing: var(--letterspacing-h2);
|
|
443
|
+
font-weight: var(--fontweight-h2);
|
|
444
|
+
|
|
445
|
+
main article & {
|
|
446
|
+
font-size: var(--fontsize-h2-article);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
main aside & {
|
|
450
|
+
font-size: var(--fontsize-h2-aside);
|
|
451
|
+
}
|
|
401
452
|
|
|
402
|
-
main article &,
|
|
403
|
-
main aside &,
|
|
404
453
|
main blockquote & {
|
|
405
|
-
font-size: var(--
|
|
454
|
+
font-size: var(--fontsize-h2-blockquote);
|
|
406
455
|
}
|
|
407
456
|
}
|
|
408
457
|
|
|
409
458
|
h3 {
|
|
410
|
-
font-size: var(--
|
|
411
|
-
letter-spacing: var(--
|
|
412
|
-
font-weight: var(--
|
|
459
|
+
font-size: var(--fontsize-h3);
|
|
460
|
+
letter-spacing: var(--letterspacing-h3);
|
|
461
|
+
font-weight: var(--fontweight-h3);
|
|
462
|
+
|
|
463
|
+
main article & {
|
|
464
|
+
font-size: var(--fontsize-h3-article);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
main aside & {
|
|
468
|
+
font-size: var(--fontsize-h3-aside);
|
|
469
|
+
}
|
|
413
470
|
|
|
414
|
-
main article &,
|
|
415
|
-
main aside &,
|
|
416
471
|
main blockquote & {
|
|
417
|
-
font-size: var(--
|
|
472
|
+
font-size: var(--fontsize-h3-blockquote);
|
|
418
473
|
}
|
|
419
474
|
}
|
|
420
475
|
|
|
421
476
|
h4 {
|
|
422
|
-
font-size: var(--
|
|
423
|
-
letter-spacing: var(--
|
|
424
|
-
font-weight: var(--
|
|
477
|
+
font-size: var(--fontsize-h4);
|
|
478
|
+
letter-spacing: var(--letterspacing-h4);
|
|
479
|
+
font-weight: var(--fontweight-h4);
|
|
480
|
+
|
|
481
|
+
main article & {
|
|
482
|
+
font-size: var(--fontsize-h4-article);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
main aside & {
|
|
486
|
+
font-size: var(--fontsize-h4-aside);
|
|
487
|
+
}
|
|
425
488
|
|
|
426
|
-
main article &,
|
|
427
|
-
main aside &,
|
|
428
489
|
main blockquote & {
|
|
429
|
-
font-size: var(--
|
|
490
|
+
font-size: var(--fontsize-h4-blockquote);
|
|
430
491
|
}
|
|
431
492
|
}
|
|
432
493
|
|
|
433
494
|
h5 {
|
|
434
|
-
font-size: var(--
|
|
435
|
-
letter-spacing: var(--
|
|
436
|
-
font-weight: var(--
|
|
495
|
+
font-size: var(--fontsize-h5);
|
|
496
|
+
letter-spacing: var(--letterspacing-h5);
|
|
497
|
+
font-weight: var(--fontweight-h5);
|
|
498
|
+
|
|
499
|
+
main article & {
|
|
500
|
+
font-size: var(--fontsize-h5-article);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
main aside & {
|
|
504
|
+
font-size: var(--fontsize-h5-aside);
|
|
505
|
+
}
|
|
437
506
|
|
|
438
|
-
main article &,
|
|
439
|
-
main aside &,
|
|
440
507
|
main blockquote & {
|
|
441
|
-
font-size: var(--
|
|
508
|
+
font-size: var(--fontsize-h5-blockquote);
|
|
442
509
|
}
|
|
443
510
|
}
|
|
444
511
|
|
|
445
512
|
h6 {
|
|
446
|
-
font-size: var(--
|
|
447
|
-
letter-spacing: var(--
|
|
448
|
-
font-weight: var(--
|
|
513
|
+
font-size: var(--fontsize-h6);
|
|
514
|
+
letter-spacing: var(--letterspacing-h6);
|
|
515
|
+
font-weight: var(--fontweight-h6);
|
|
449
516
|
}
|
|
450
517
|
|
|
451
518
|
[rel=home] {
|
|
452
|
-
font-size: var(--
|
|
453
|
-
font-weight: var(--
|
|
454
|
-
letter-spacing: var(--
|
|
519
|
+
font-size: var(--fontsize-name-header);
|
|
520
|
+
font-weight: var(--fontweight-name-header);
|
|
521
|
+
letter-spacing: var(--letterspacing-name-header);
|
|
455
522
|
}
|
|
456
523
|
|
|
457
524
|
|
package/utils.js
CHANGED
|
@@ -2,6 +2,7 @@ import {fromMarkdown} from 'mdast-util-from-markdown'
|
|
|
2
2
|
import {toHast} from 'mdast-util-to-hast'
|
|
3
3
|
import path from "node:path"
|
|
4
4
|
import { randomUUID } from "node:crypto"
|
|
5
|
+
import { isSecretPath, displayPath } from "./secretPaths.js"
|
|
5
6
|
|
|
6
7
|
export const imageSizes = [414, 768, 1440, 1920]
|
|
7
8
|
export const imageExts = ["avif", "webp"]
|
|
@@ -22,26 +23,6 @@ export function createImagePath({ targetFilePath, size, ext, targetDirectory, uu
|
|
|
22
23
|
})
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
/**
|
|
26
|
-
* @param {string} targetFilePath
|
|
27
|
-
* @param {string} targetDirectory
|
|
28
|
-
* @param {string} uuid
|
|
29
|
-
*/
|
|
30
|
-
export function createImagePaths(targetFilePath, targetDirectory, uuid) {
|
|
31
|
-
const defaultExt = path.extname(targetFilePath)
|
|
32
|
-
return [...imageExts, defaultExt].map(ext => {
|
|
33
|
-
return imageSizes.map(size => {
|
|
34
|
-
return createImagePath({
|
|
35
|
-
targetFilePath,
|
|
36
|
-
size,
|
|
37
|
-
ext,
|
|
38
|
-
targetDirectory,
|
|
39
|
-
uuid
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
26
|
/** @param {string} text */
|
|
46
27
|
export function testURL(text) {
|
|
47
28
|
if (text.match(/^https?:\/\/[\S]+$/)) {
|
|
@@ -62,6 +43,53 @@ export function testHashtags(text) {
|
|
|
62
43
|
}
|
|
63
44
|
|
|
64
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The classes that place a page in the site, for `<body>` and for the
|
|
48
|
+
* page's card in a listing: one per folder it's in, from the top, and
|
|
49
|
+
* one for the page. `/` is `page_home`; `/blog/travel/hello-world` is
|
|
50
|
+
* `folder_blog folder_blog_travel page_blog_travel_hello-world`.
|
|
51
|
+
*
|
|
52
|
+
* From the published url, except where a segment is secret: there the
|
|
53
|
+
* author's name for it, without the salt, as the breadcrumb shows it
|
|
54
|
+
* (per Sam) - `blog/secret##purple-moon/hello-world.md` is
|
|
55
|
+
* `folder_blog folder_blog_secret page_blog_secret_hello-world`, never
|
|
56
|
+
* the hash and never the salt. Routing keeps a source's depth, so its
|
|
57
|
+
* segments line up with the url's. `_` joins segments, so one inside a
|
|
58
|
+
* segment becomes `-`, and a space becomes `-` too.
|
|
59
|
+
* @param {string | undefined} prettyURL
|
|
60
|
+
* @param {string} [source] - the page's source path, project-relative
|
|
61
|
+
* @returns {string[]}
|
|
62
|
+
*/
|
|
63
|
+
export function pageClasses(prettyURL, source) {
|
|
64
|
+
const urlSegments = String(prettyURL ?? "").split("/").filter(Boolean)
|
|
65
|
+
const sourceSegments = typeof source === "string" ? source.split(/[\\/]/) : []
|
|
66
|
+
const named = typeof source === "string" ? displayPath(source).split(/[\\/]/) : []
|
|
67
|
+
const segments = urlSegments
|
|
68
|
+
.map((segment, index) => isSecretPath(sourceSegments[index] ?? "") ? path.parse(named[index]).name.toLowerCase() : segment)
|
|
69
|
+
.map(segment => segment.replace(/[_\s]+/g, "-"))
|
|
70
|
+
if (!segments.length) return ["page_home"]
|
|
71
|
+
const folders = segments.slice(0, -1).map((_, index) => `folder_${segments.slice(0, index + 1).join("_")}`)
|
|
72
|
+
return [...folders, `page_${segments.join("_")}`]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A title or breadcrumb inferred from a name - a file's, a folder's, a
|
|
77
|
+
* tag's. A name the author cased themselves (any capital letter) is
|
|
78
|
+
* theirs, kept as written: `Hello World`, `iPhone notes`, `README`. An
|
|
79
|
+
* all-lowercase one is sentence-cased, its hyphens and underscores read
|
|
80
|
+
* as spaces: `hello-world` → "Hello world", `#machine-learning` →
|
|
81
|
+
* "Machine learning". Some names read awkwardly (`api-design` → "Api
|
|
82
|
+
* design"); per Sam, that's accepted - no rule handles every case.
|
|
83
|
+
* @param {string | undefined} name
|
|
84
|
+
* @returns {string | undefined}
|
|
85
|
+
*/
|
|
86
|
+
export function labelFromName(name) {
|
|
87
|
+
if (!name) return name
|
|
88
|
+
if (/\p{Lu}/u.test(name)) return name
|
|
89
|
+
const spaced = name.replace(/[-_]+/g, " ").replace(/\s+/g, " ").trim()
|
|
90
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1)
|
|
91
|
+
}
|
|
92
|
+
|
|
65
93
|
export function toTitleCase(string) {
|
|
66
94
|
if (!string) return
|
|
67
95
|
return string.split(" ").map(word => {
|
|
@@ -82,7 +110,7 @@ export function toTitleCase(string) {
|
|
|
82
110
|
* title, a routed prettyURL and a tracked listing without special cases.
|
|
83
111
|
*/
|
|
84
112
|
export function createHashtagPage(tag) {
|
|
85
|
-
return `# ${
|
|
113
|
+
return `# ${labelFromName(tag)}\n\n/**?tag=${tag}`
|
|
86
114
|
}
|
|
87
115
|
|
|
88
116
|
/**
|
|
@@ -129,3 +157,28 @@ export function isListedPage(target) {
|
|
|
129
157
|
&& target.extension === ".html"
|
|
130
158
|
&& !target.metadata?.hidden
|
|
131
159
|
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A page its author gave no file, on purpose (`html_file: false`). It has
|
|
163
|
+
* no url, but it is a page: shown wherever one can be without a link to
|
|
164
|
+
* it - a listing's card, a table row, a feed entry - which is what
|
|
165
|
+
* makes card-only and feed-only pages possible. Not in a nav, the
|
|
166
|
+
* sitemap, backlinks or a wikilink: those are links. Another target
|
|
167
|
+
* with no file (a deleted page) isn't this.
|
|
168
|
+
* @param {any} target
|
|
169
|
+
*/
|
|
170
|
+
export function isPageWithoutFile(target) {
|
|
171
|
+
return target.write === false && target.metadata?.html_file === false
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* listPages, plus pages without a file: for listings, cards and the
|
|
176
|
+
* feed, which can show a page without linking to it.
|
|
177
|
+
* @param {{targets: (query: object) => any[]}} api
|
|
178
|
+
* @param {object} query
|
|
179
|
+
*/
|
|
180
|
+
export function showPages(api, query) {
|
|
181
|
+
return api.targets(query).filter(target => isListedPage(target) || (
|
|
182
|
+
isPageWithoutFile(target) && target.extension === ".html" && !target.metadata?.hidden
|
|
183
|
+
))
|
|
184
|
+
}
|