diff options
-rw-r--r-- | entry.go | 53 | ||||
-rw-r--r-- | main.go | 5 | ||||
-rw-r--r-- | page.go | 7 | ||||
-rw-r--r-- | utils.go | 20 |
4 files changed, 85 insertions, 0 deletions
diff --git a/entry.go b/entry.go new file mode 100644 index 0000000..1ee123a --- /dev/null +++ b/entry.go @@ -0,0 +1,53 @@ +package main + +import ( + "os" + "path/filepath" + "regexp" + "strconv" +) + +/* + * This file contains all the code related to reading and processing entries + */ +type entry struct { + name string + fullPath string +} + +type logEntry struct { + baseEntry entry + day int + month int + year int +} + +func findEntries(rootPath string, cfg config) (entries []Renderer, err error) { + baseEntryRegex := regexp.MustCompile(".*\\.md") + logEntryRegex := regexp.MustCompile("(20[0-9]{2})-([0-9]{2})-([0-9]{2}).*\\.md") + + err = filepath.Walk(rootPath, func(p string, f os.FileInfo, e error) error { + if !f.IsDir() && baseEntryRegex.MatchString(f.Name()) { + newBaseEntry := entry{name: f.Name(), fullPath: p} + + if logEntryRegex.MatchString(f.Name()) { + captures := logEntryRegex.FindStringSubmatch(f.Name()) + y, _ := strconv.Atoi(captures[1]) + m, _ := strconv.Atoi(captures[2]) + d, _ := strconv.Atoi(captures[3]) + + newLogEntry := logEntry{ + baseEntry: newBaseEntry, + day: d, + month: m, + year: y} + entries = append(entries, newLogEntry) + } else { + entries = append(entries, newBaseEntry) + } + } + return nil + }) + return +} + @@ -0,0 +1,5 @@ +package main + +func main() { + +} @@ -0,0 +1,7 @@ +package main + +/* + * This file contains all the code related to turning entries into HTML pages + */ +type Renderer interface { +} diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..7157072 --- /dev/null +++ b/utils.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/BurntSushi/toml" + "strings" +) + +type config struct { + docsRoot string + templateFile string + targetDir string + cssFile string + baseUrl string +} + +func readConfig(file string) (cfg config, err error) { + _, err = toml.DecodeFile(file, &cfg) + cfg.baseUrl = strings.TrimSuffix(cfg.baseUrl, "/") + return +} |