diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2020-01-29 22:35:25 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2020-01-29 22:35:25 +0100 |
commit | 5ec92205b871ede6ae4b8afc755efb7d06d1ffd9 (patch) | |
tree | 0ce16f82ea099ba80aa3190cb41fe32f3f787c04 | |
parent | 2c055e3ca001ee6064677a0db16172148e5edcef (diff) |
Added better name handling for entries
-rw-r--r-- | entry.go | 17 | ||||
-rw-r--r-- | utils.go | 7 |
2 files changed, 16 insertions, 8 deletions
@@ -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, @@ -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 +} |