feat: SSR 站点单页 /page/:slug 与 Admin CRUD

EOF

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-29 16:49:39 +08:00
parent c4faba81b3
commit 802f86605c
17 changed files with 410 additions and 8 deletions

44
routers/web/page.go Normal file
View File

@@ -0,0 +1,44 @@
package web
import (
"errors"
"html/template"
"net/http"
"git.iioio.com/freefire/jiang13-forum/services"
"github.com/gin-gonic/gin"
)
type sitePageViewData struct {
PageChrome
PageTitle string
Slug string
BodyHTML template.HTML
}
// SitePageGet 公开站点单页
func (d Deps) SitePageGet(c *gin.Context) {
ctx := d.ctx(c)
if d.SitePage == nil {
d.render404(ctx)
return
}
slug := c.Param("slug")
page, err := d.SitePage.GetBySlug(slug, false)
if err != nil {
if errors.Is(err, services.ErrSitePageNotFound) {
d.render404(ctx)
return
}
c.String(http.StatusInternalServerError, "加载失败")
return
}
html := services.SanitizePostHTML(page.Content)
chrome := d.chrome(ctx, page.Title+" · "+d.Settings.SiteBranding().Name, "", "")
ctx.HTML(http.StatusOK, "page/view", sitePageViewData{
PageChrome: chrome,
PageTitle: page.Title,
Slug: page.Slug,
BodyHTML: template.HTML(html),
})
}