aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2020-01-29 22:35:25 +0100
committerEddy Pedroni <eddy@0xf7.com>2020-01-29 22:35:25 +0100
commit5ec92205b871ede6ae4b8afc755efb7d06d1ffd9 (patch)
tree0ce16f82ea099ba80aa3190cb41fe32f3f787c04
parent2c055e3ca001ee6064677a0db16172148e5edcef (diff)
Added better name handling for entries
-rw-r--r--entry.go17
-rw-r--r--utils.go7
2 files changed, 16 insertions, 8 deletions
diff --git a/entry.go b/entry.go
index d8f488f..01abf50 100644
--- a/entry.go
+++ b/entry.go
@@ -24,19 +24,20 @@ type logEntry struct {
}
func findEntries(cfg config) (entries []Renderer, err error) {
- baseEntryRegex := regexp.MustCompile(".*\\.md")
- logEntryRegex := regexp.MustCompile("(20[0-9]{2})-([0-9]{2})-([0-9]{2}).*\\.md")
+ baseEntryRegex := regexp.MustCompile("([A-z\\-]+)\\.md")
+ logEntryRegex := regexp.MustCompile("(20[0-9]{2})-([0-9]{2})-([0-9]{2})-([A-z\\-]+)\\.md")
err = filepath.Walk(cfg.DocsRoot, func(p string, f os.FileInfo, e error) error {
if !f.IsDir() && baseEntryRegex.MatchString(f.Name()) {
- fmt.Println(p)
- newBaseEntry := entry{name: f.Name(), fullPath: p}
+ baseCaptures := baseEntryRegex.FindStringSubmatch(f.Name())
+ newBaseEntry := entry{name: nameify(baseCaptures[1]), fullPath: p}
+ fmt.Println(newBaseEntry.name)
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])
+ logCaptures := logEntryRegex.FindStringSubmatch(f.Name())
+ y, _ := strconv.Atoi(logCaptures[1])
+ m, _ := strconv.Atoi(logCaptures[2])
+ d, _ := strconv.Atoi(logCaptures[3])
newLogEntry := logEntry{
baseEntry: newBaseEntry,
diff --git a/utils.go b/utils.go
index b5b3f02..c78cbcc 100644
--- a/utils.go
+++ b/utils.go
@@ -18,3 +18,10 @@ func readConfig(file string) (cfg config, err error) {
cfg.BaseUrl = strings.TrimSuffix(cfg.BaseUrl, "/")
return
}
+
+func nameify(raw string) (clean string) {
+ clean = strings.ReplaceAll(raw, "-", " ")
+ clean = strings.TrimSpace(clean)
+ clean = strings.Title(clean)
+ return
+}