From 4f3164956ac399b81a7af42c11a13f9e958fad12 Mon Sep 17 00:00:00 2001 From: Tomas Dvorak Date: Sat, 14 Mar 2026 11:27:08 +0100 Subject: [PATCH] Add slug-to-numeric resolution for blog URLs - Modified blog handler to resolve slugs to numeric files when slug files don't exist - This allows slug URLs to work without creating duplicate slug files - Fixes sorting issues while maintaining slug URL compatibility --- backend/main.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/backend/main.go b/backend/main.go index 16eb3e8..5a6bcf2 100644 --- a/backend/main.go +++ b/backend/main.go @@ -1424,6 +1424,32 @@ func main() { http.ServeFile(w, r, slugPath) return } + + // If slug file doesn't exist, try to resolve slug to numeric file + blogDir := filepath.Join(sp, "blog") + entries, err := os.ReadDir(blogDir) + if err == nil { + for _, entry := range entries { + name := entry.Name() + if !regexp.MustCompile(`^\d{4}\.html$`).MatchString(name) { + continue + } + numericPath := filepath.Join(blogDir, name) + + // Check if this numeric file has the matching slug + b, err := os.ReadFile(numericPath) + if err != nil { + continue + } + s := string(b) + re := regexp.MustCompile(`(?is)= 2 && m[1] == path { + http.ServeFile(w, r, numericPath) + return + } + } + } } // If not found, serve 404