-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfg.go
86 lines (67 loc) · 1.45 KB
/
cfg.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
84
85
86
package markdown
import (
"os"
"path/filepath"
"strings"
"time"
)
type Project struct {
Name string
Path string
Markdown []string
Attachments []string
}
type Config struct {
SearchPaths []string
OutDir string
}
func (c *Config) Collect() ([]Project, error) {
var res []Project
for _, root := range c.SearchPaths {
p := Project{
Path: root,
Name: filepath.Base(root),
}
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if strings.HasPrefix(info.Name(), ".") {
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
if info.IsDir() {
return nil
}
relPath, err := filepath.Rel(root, path)
if err != nil {
panic("cannot happen")
}
if strings.HasSuffix(strings.ToLower(info.Name()), ".md") {
p.Markdown = append(p.Markdown, relPath)
} else {
p.Attachments = append(p.Attachments, relPath)
}
return nil
})
if err != nil {
return res, err
}
res = append(res, p)
}
return res, nil
}
type PageConfig struct {
// Alternate title for the page
Title string `yaml:"title"`
// Menu is slash separated, like my/cool/menu
Menu string `yaml:"menu"`
// ManagedBy names someone who is in charge of the page
ManagedBy string `yaml:"managedBy"`
// whatever that means
Date time.Time `yaml:"date"`
// Tags for an alternate hierarchyless navigation
Tags []string `yaml:"tags"`
}