package main import ( "fmt" "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(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(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} 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 }