This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
main.go
83 lines (68 loc) · 1.74 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"github.com/BurntSushi/toml"
wikilink "github.com/abhinav/goldmark-wikilink"
"github.com/yuin/goldmark"
"io/ioutil"
"path/filepath"
"time"
)
var md goldmark.Markdown
func init() {
md = goldmark.New(
goldmark.WithExtensions(&wikilink.Extender{}),
)
}
type Link struct {
Source string `json:"source"`
Target string `json:"target"`
Text string `json:"text"`
}
type LinkTable = map[string][]Link
type Index struct {
Links LinkTable `json:"links"`
Backlinks LinkTable `json:"backlinks"`
}
type Content struct {
Title string `json:"title"`
Content string `json:"content"`
LastModified time.Time `json:"lastmodified"`
Tags []string `json:"tags"`
}
type ContentIndex = map[string]Content
type ConfigTOML struct {
IgnoredFiles []string `toml:"ignoreFiles"`
}
func getIgnoredFiles(base string) (res map[string]struct{}) {
res = make(map[string]struct{})
source, err := ioutil.ReadFile(filepath.FromSlash(base + "/config.toml"))
if err != nil {
return res
}
var config ConfigTOML
if _, err := toml.Decode(string(source), &config); err != nil {
return res
}
for _, glb := range config.IgnoredFiles {
matches, _ := filepath.Glob(base + glb)
for _, match := range matches {
res[match] = struct{}{}
}
}
return res
}
func main() {
in := flag.String("input", ".", "Input Directory")
out := flag.String("output", ".", "Output Directory")
root := flag.String("root", "..", "Root Directory (for config parsing)")
index := flag.Bool("index", false, "Whether to index the content")
flag.Parse()
ignoreBlobs := getIgnoredFiles(*root)
l, i := walk(*in, ".md", *index, ignoreBlobs)
f := filter(l)
err := write(f, i, *index, *out, *root)
if err != nil {
panic(err)
}
}