Skip to content

Commit d853645

Browse files
committed
bringing back the preprocessor just for that one placeholder
1 parent 0b67c0c commit d853645

2 files changed

Lines changed: 12 additions & 67 deletions

File tree

src/content.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { marked } from 'https://unpkg.com/marked@17.0.1/lib/marked.esm.js'
22

3+
import preprocessor from '/src/preprocessor.js'
34
import postprocess from '/src/postprocessor.js'
45

56
const main = document.querySelector('main')
@@ -14,7 +15,9 @@ export default async () => {
1415
}
1516

1617
const path = location.pathname.slice(1)
17-
const content = path ? contents[path]?.path || '/content/not-found.md' : '/content/index.md'
18+
const contentIndex = path ? contents[path] ? path : 'not-found' : 'index'
19+
const contentData = contents[contentIndex]
20+
const contentPath = contentData.path
1821

1922
navContainer.replaceChildren(
2023
...Object
@@ -31,13 +34,13 @@ export default async () => {
3134
})
3235
)
3336

34-
if (content)
35-
await fetch(content)
36-
.then((r) => r.text())
37-
.then((text) => text.replace(/---[\r\n].*?[\r\n]---/s, ''))
38-
.then((text) => main.replaceChildren(
39-
...postprocess(marked.parse(text))
40-
)
37+
await fetch(contentPath)
38+
.then((r) => r.text())
39+
.then((text) => text.replace(/---[\r\n].*?[\r\n]---/s, ''))
40+
.then((text) => main.replaceChildren(
41+
...postprocess(marked.parse(preprocessor(text)))
4142
)
42-
.catch(console.error)
43+
)
44+
.then(() => document.title = contentData.metadata.name || contentIndex)
45+
.catch(console.error)
4346
}

src/preprocessor.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,9 @@
11
const preprocessors = Object.freeze(
22
[
3-
{
4-
filter: /{age}/g,
5-
replacer: () => {
6-
const age = (Date.now() / 1000 - 1171040400) / 31536000
7-
return `${Math.floor(age)}${age - Math.floor(age) >= .8 ? ` (almost ${Math.ceil(age)})` : ''}`
8-
}
9-
},
10-
11-
{ // go back, like literally go back on the path tree, not history
12-
filter: /{previousPath(?:\s+-([0-9])+)?}/g,
13-
replacer: (_, amount = 1) =>
14-
location.pathname
15-
.split('/')
16-
.slice(0, -Number(amount))
17-
.join('/')
18-
|| '/'
19-
},
20-
21-
{ // history "link" hack - part 1
22-
filter: /{history\s+(?:(-))?([0-9]+)}/g,
23-
replacer: (_, neg, amount) =>
24-
`/__secretevilpathnoonewoulduseonpurpose_history_${neg || ''}${amount}`
25-
},
26-
27-
{
28-
filter: /{timestamp(\slong)?\s+([0-9]+)}/g,
29-
replacer: (_, modifier = '', timestamp) => {
30-
const long = new Intl.DateTimeFormat(undefined, {
31-
weekday: 'long',
32-
month: 'long',
33-
day: 'numeric',
34-
year: 'numeric',
35-
hour: 'numeric',
36-
minute: 'numeric'
37-
})
38-
.format(Number(timestamp))
39-
40-
const short = new Intl.DateTimeFormat(undefined, {
41-
hour: 'numeric',
42-
minute: 'numeric'
43-
})
44-
.format(Number(timestamp))
45-
46-
return `<span class="timestamp" title="${long}">${ modifier.trim() === 'long' ? long : short }</span>`
47-
}
48-
},
49-
503
{
514
filter: /{origin}/g,
525
replacer: location.origin
536
},
54-
55-
{
56-
filter: /{dialogue}/g,
57-
replacer: '<span blockquote-dialogue></span>'
58-
},
59-
60-
{
61-
filter: /\[-([^\n\s]+)\s+([^\]]+)\s*\]/g,
62-
replacer: (_, mod, content) =>
63-
`<span class="${mod}">${content}</span>`
64-
}
657
].map(Object.freeze)
668
)
679

0 commit comments

Comments
 (0)