Improve comments

This commit is contained in:
2025-07-04 15:57:06 +08:00
parent 17663a9691
commit fdf2e21dce
2 changed files with 15 additions and 1 deletions

View File

@@ -90,7 +90,7 @@ func serveIndexHtml(c fiber.Ctx) error {
username := strings.TrimPrefix(path, "/user/")
u, err := service.GetUserByUsername(username)
if err == nil {
preview = fmt.Sprintf("/avatar/%d", u.ID)
preview = fmt.Sprintf("%s/avatar/%d", serverBaseURL, u.ID)
title = u.Username
description = "User " + u.Username + "'s profile"
}
@@ -105,6 +105,17 @@ func serveIndexHtml(c fiber.Ctx) error {
description = utils.ArticleToDescription(t.Description, 256)
}
}
} else if strings.HasPrefix(path, "/comments/") {
commentIDStr := strings.TrimPrefix(path, "/comments/")
commentID, err := strconv.Atoi(commentIDStr)
if err == nil {
cmt, err := service.GetCommentByID(uint(commentID))
if err == nil {
title = "Comment Details"
description = utils.ArticleToDescription(cmt.Content, 200)
preview = fmt.Sprintf("%s/avatar/%d", serverBaseURL, cmt.User.ID)
}
}
}
content = strings.ReplaceAll(content, "{{SiteName}}", siteName)