-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
43 lines (34 loc) · 858 Bytes
/
util.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
41
42
43
package main
import (
"crypto/subtle"
"fmt"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/parser"
)
func IsKeyValid(key string) bool {
return subtle.ConstantTimeCompare([]byte(key), []byte(PASS)) == 1
}
func MakeIndex() (*Index, error) {
titles, err := listPosts()
if err != nil {
return nil, fmt.Errorf("error listing posts: %w", err)
}
index := Index{
Meta: Meta{TITLE, AUTHOR, EMAIL},
Titles: titles,
}
return &index, nil
}
func MakePost(name string) (*Post, error) {
content, err := getPost(name)
if err != nil {
return nil, fmt.Errorf("error getting post: %w", err)
}
ext := parser.CommonExtensions | parser.AutoHeadingIDs
parser := parser.NewWithExtensions(ext)
post := Post{
Meta: Meta{TITLE, AUTHOR, EMAIL},
Content: string(markdown.ToHTML(content, parser, nil)),
}
return &post, nil
}