fix: 修复发帖后链接404 + 通知卡片跳转错误
- post_repo.go: FindByIDWithAuthor/Restore 中 posts.uid 改为 posts.id(posts 表主键是 id,不存在 uid 列) - theme/loader.go: 新增 derefUint 模板函数,显式解引用 *uint 指针(Go 1.26 模板引擎传参给 printf 时不自动解引用) - messages/index.html: 通知卡片链接使用 derefUint 包裹 RelatedID 避免打印指针地址
This commit is contained in:
@ -24,6 +24,15 @@ func LoadTemplates(roots ...TemplateRoot) (*template.Template, error) {
|
||||
"subtract": func(a, b int) int { return a - b },
|
||||
"formatTTL": formatTTL,
|
||||
"assetV": common.AssetV,
|
||||
// derefUint 安全解引用 *uint 指针。
|
||||
// Go 1.26 的模板引擎在将 *uint 传给 printf/print 时不会自动解引用,
|
||||
// 导致打印指针地址而非值。通过此函数显式解引用后传给 printf。
|
||||
"derefUint": func(p *uint) uint {
|
||||
if p == nil {
|
||||
return 0
|
||||
}
|
||||
return *p
|
||||
},
|
||||
}
|
||||
t := template.New("").Funcs(funcMap)
|
||||
for _, root := range roots {
|
||||
|
||||
Reference in New Issue
Block a user