mirror of
https://github.com/Dvorinka/bizoni.git
synced 2026-06-03 18:22:57 +00:00
Fix image paths and remove duplicate slug files
- Remove duplicate slug files that were causing duplicate entries - Add logic to find corresponding numeric ID for image paths - This fixes broken images in admin interface for slug-based blogs
This commit is contained in:
+17
-3
@@ -610,7 +610,6 @@ func listLatestBlogs(siteRoot string, limit int) ([]BlogItem, error) {
|
|||||||
title := extractTitle(blogPath)
|
title := extractTitle(blogPath)
|
||||||
slug := extractSlug(blogPath, name)
|
slug := extractSlug(blogPath, name)
|
||||||
cats := extractCategories(blogPath)
|
cats := extractCategories(blogPath)
|
||||||
blogID := extractBlogID(blogPath, name)
|
|
||||||
|
|
||||||
// Mark this ID as seen
|
// Mark this ID as seen
|
||||||
seenIDs[id] = true
|
seenIDs[id] = true
|
||||||
@@ -620,7 +619,22 @@ func listLatestBlogs(siteRoot string, limit int) ([]BlogItem, error) {
|
|||||||
if err1 == nil {
|
if err1 == nil {
|
||||||
mtime = htmlInfo.ModTime()
|
mtime = htmlInfo.ModTime()
|
||||||
}
|
}
|
||||||
if imgInfo, err2 := os.Stat(filepath.Join(imgDir, blogID+".png")); err2 == nil {
|
// For image path, try to find corresponding numeric ID
|
||||||
|
imageID := id
|
||||||
|
if regexp.MustCompile(`^[a-z]`).MatchString(id) {
|
||||||
|
// This is a slug, try to find corresponding numeric file
|
||||||
|
numericFiles, _ := filepath.Glob(filepath.Join(blogDir, "????.html"))
|
||||||
|
for _, numericFile := range numericFiles {
|
||||||
|
numericID := strings.TrimSuffix(filepath.Base(numericFile), ".html")
|
||||||
|
numericPath := filepath.Join(blogDir, numericFile)
|
||||||
|
numericSlug := extractSlug(numericPath, numericFile)
|
||||||
|
if numericSlug == id {
|
||||||
|
imageID = numericID
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if imgInfo, err2 := os.Stat(filepath.Join(imgDir, imageID+".png")); err2 == nil {
|
||||||
// If image is newer, use that as a proxy for recency
|
// If image is newer, use that as a proxy for recency
|
||||||
if imgInfo.ModTime().After(mtime) {
|
if imgInfo.ModTime().After(mtime) {
|
||||||
mtime = imgInfo.ModTime()
|
mtime = imgInfo.ModTime()
|
||||||
@@ -638,7 +652,7 @@ func listLatestBlogs(siteRoot string, limit int) ([]BlogItem, error) {
|
|||||||
Title: title,
|
Title: title,
|
||||||
Slug: slug,
|
Slug: slug,
|
||||||
Link: link,
|
Link: link,
|
||||||
Image: "/img/blog/" + blogID + ".png",
|
Image: "/img/blog/" + imageID + ".png",
|
||||||
MTime: mtime,
|
MTime: mtime,
|
||||||
Categories: cats,
|
Categories: cats,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user