-
Notifications
You must be signed in to change notification settings - Fork 188
/
custom_pages.go
40 lines (32 loc) · 922 Bytes
/
custom_pages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"io/ioutil"
"log"
"path"
"strings"
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday"
)
func initializeCustomPages(customPagesDir string) {
files, err := ioutil.ReadDir(customPagesDir)
if err != nil {
log.Fatal("Error reading the custom pages directory: ", err)
}
for _, file := range files {
fileName := file.Name()
if len(fileName) <= 3 {
continue
}
if strings.EqualFold(string(fileName[len(fileName)-3:len(fileName)]), ".md") {
contents, err := ioutil.ReadFile(path.Join(customPagesDir, fileName))
if err != nil {
log.Fatalf("Error reading file %s", fileName)
}
unsafe := blackfriday.MarkdownCommon(contents)
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
fileName := fileName[0 : len(fileName)-3]
customPages[fileName] = string(html)
customPagesNames[fileName] = strings.ReplaceAll(fileName, "_", " ")
}
}
}