Neale Pickett
·
2025-02-27
frontmatter.mjs
1const fmsep = "---"
2
3export class Doc {
4 constructor(doc) {
5 this.header = ""
6 this.content = ""
7
8 let lines = doc.split(/\r?\n/)
9 let fm = false
10 for (let lineno in lines) {
11 let line = lines[lineno]
12 if ((lineno == 0) && (line == fmsep)) {
13 fm = true
14 } else if (fm && (line == fmsep)) {
15 fm = false
16 } else if (fm) {
17 this.header += `${line}\n`
18 } else {
19 this.content += `${line}\n`
20 }
21 }
22 }
23
24 urlpfx() {
25 let m = this.header.match(/urlpfx: "([^"]+)"/)
26 return m[1]
27 }
28}