aboutsummaryrefslogtreecommitdiffstats
path: root/entry.go
diff options
context:
space:
mode:
authorEddy Pedroni <epedroni@pm.me>2025-04-08 17:01:55 +0200
committerEddy Pedroni <epedroni@pm.me>2025-04-08 17:02:46 +0200
commit83d175b7b069bc3bbc0d600c2fab4d082e04b521 (patch)
tree9d1b7975ad16f7d5433285d3fab0a7cc38d24564 /entry.go
parent38b40d8c5a8915716b3aa46aac4a0a84d0113b25 (diff)
Python implementation with better multi-entry page support
Diffstat (limited to 'entry.go')
-rw-r--r--entry.go78
1 files changed, 0 insertions, 78 deletions
diff --git a/entry.go b/entry.go
deleted file mode 100644
index ddb3bd8..0000000
--- a/entry.go
+++ /dev/null
@@ -1,78 +0,0 @@
-package main
-
-import (
- "os"
- "path/filepath"
- "regexp"
- "sort"
- "strconv"
-)
-
-/*
- * This file contains all the code related to reading and processing entries
- */
-type entry struct {
- name string
- rawName string
- fullPath string
-}
-
-type logEntry struct {
- baseEntry entry
- day int
- month int
- year int
-}
-
-func findEntries(root string) (entries []Renderer) {
- baseEntryRegex := regexp.MustCompile("([A-z\\-]+)\\.md")
- logEntryRegex := regexp.MustCompile("(20[0-9]{2})-([0-9]{2})-([0-9]{2})-([A-z\\-]+)\\.md")
-
- logEntries := make([]logEntry, 0)
-
- err := filepath.Walk(root, func(p string, f os.FileInfo, e error) error {
- if !f.IsDir() && baseEntryRegex.MatchString(f.Name()) {
- baseCaptures := baseEntryRegex.FindStringSubmatch(f.Name())
- newBaseEntry := entry{name: nameify(baseCaptures[1]),
- rawName: baseCaptures[1],
- fullPath: p}
-
- if logEntryRegex.MatchString(f.Name()) {
- logCaptures := logEntryRegex.FindStringSubmatch(f.Name())
- y, _ := strconv.Atoi(logCaptures[1])
- m, _ := strconv.Atoi(logCaptures[2])
- d, _ := strconv.Atoi(logCaptures[3])
-
- newLogEntry := logEntry{
- baseEntry: newBaseEntry,
- day: d,
- month: m,
- year: y}
- logEntries = append(logEntries, newLogEntry)
- } else {
- entries = append(entries, newBaseEntry)
- }
- }
- return nil
- })
- if err != nil {
- panic(err)
- }
-
- sort.Slice(logEntries, func(i, j int) bool {
- if logEntries[i].year != logEntries[j].year {
- return logEntries[i].year > logEntries[j].year
- } else if logEntries[i].month != logEntries[j].month {
- return logEntries[i].month > logEntries[j].month
- } else {
- return logEntries[i].day > logEntries[j].day
- }
- })
-
- // must append each manually: https://golang.org/doc/faq#convert_slice_of_interface
- for _, e := range logEntries {
- entries = append(entries, e)
- }
-
- return
-}