aboutsummaryrefslogtreecommitdiffstats
path: root/entry.go
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2020-01-25 18:35:06 +0100
committerEddy Pedroni <eddy@0xf7.com>2020-01-25 18:35:06 +0100
commitce81b97e80ada42a223a7fd45c5abaa5c9667d75 (patch)
tree969e4c13e215b54a730f13d2aa36746165219c09 /entry.go
parent282405f468f43c0a0b6fbffc57924e609c0cce36 (diff)
Added entry processing, stubs for page processing, basic utils, empty main
Diffstat (limited to 'entry.go')
-rw-r--r--entry.go53
1 files changed, 53 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
+}
+