mirror of
https://github.com/Dvorinka/bizoni.git
synced 2026-06-05 03:02:57 +00:00
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
This commit is contained in:
@@ -1424,6 +1424,32 @@ func main() {
|
|||||||
http.ServeFile(w, r, slugPath)
|
http.ServeFile(w, r, slugPath)
|
||||||
return
|
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)<meta name="slug" content="([^"]+)"`)
|
||||||
|
m := re.FindStringSubmatch(s)
|
||||||
|
if len(m) >= 2 && m[1] == path {
|
||||||
|
http.ServeFile(w, r, numericPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not found, serve 404
|
// If not found, serve 404
|
||||||
|
|||||||
Reference in New Issue
Block a user