aboutsummaryrefslogtreecommitdiffstats
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
parent282405f468f43c0a0b6fbffc57924e609c0cce36 (diff)
Added entry processing, stubs for page processing, basic utils, empty main
-rw-r--r--entry.go53
-rw-r--r--main.go5
-rw-r--r--page.go7
-rw-r--r--utils.go20
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
+}
+
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
+}