From ce81b97e80ada42a223a7fd45c5abaa5c9667d75 Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Sat, 25 Jan 2020 18:35:06 +0100 Subject: Added entry processing, stubs for page processing, basic utils, empty main --- entry.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 5 +++++ page.go | 7 +++++++ utils.go | 20 ++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 entry.go create mode 100644 main.go create mode 100644 page.go create mode 100644 utils.go 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 +} + diff --git a/main.go b/main.go new file mode 100644 index 0000000..7905807 --- /dev/null +++ b/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + +} diff --git a/page.go b/page.go new file mode 100644 index 0000000..207a80b --- /dev/null +++ b/page.go @@ -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 +} -- cgit v1.2.3