feat: 可配置站点 URL 风格
- 新增 urlStyle 工具与测试:postPath/userPath/sitePagePath 统一生成链接 - 管理端新增 UrlStylePanel 设置面板,settings 服务与 handler 适配 - 全站路由链接与 JSON-LD/sitemap 切换为统一 URL 生成 - middleware 与相关组件适配
This commit is contained in:
@@ -245,8 +245,12 @@ func (h *Handlers) SiteState(c *gin.Context) {
|
||||
c.JSON(503, gin.H{"error": "状态暂不可用"})
|
||||
return
|
||||
}
|
||||
urlStyle, e := h.Setting.UrlStyle()
|
||||
if e != nil {
|
||||
urlStyle = service.DefaultUrlStyle
|
||||
}
|
||||
c.Header("Cache-Control", "no-store")
|
||||
c.JSON(200, gin.H{"allow_register": cfg.AllowRegister, "register_notice": cfg.RegisterNotice, "verify_email": cfg.VerifyEmail, "password_reset": cfg.PasswordReset, "maintenance": m, "bypass": h.administrator(c), "site_url": h.Cfg.SiteURL})
|
||||
c.JSON(200, gin.H{"allow_register": cfg.AllowRegister, "register_notice": cfg.RegisterNotice, "verify_email": cfg.VerifyEmail, "password_reset": cfg.PasswordReset, "maintenance": m, "bypass": h.administrator(c), "site_url": h.Cfg.SiteURL, "url_style": urlStyle})
|
||||
}
|
||||
func (h *Handlers) SendEmailCode(c *gin.Context) {
|
||||
var req struct {
|
||||
|
||||
@@ -75,6 +75,8 @@ type updateSettingsRequest struct {
|
||||
|
||||
Levels *[]model.LevelDef `json:"levels"`
|
||||
LevelsFx *bool `json:"levels_fx"`
|
||||
|
||||
UrlStyle *string `json:"url_style"`
|
||||
}
|
||||
|
||||
func settingsPayload(saved service.PublicSiteSettings) gin.H {
|
||||
@@ -132,6 +134,8 @@ func settingsPayload(saved service.PublicSiteSettings) gin.H {
|
||||
|
||||
"levels": saved.Levels,
|
||||
"levels_fx": saved.LevelsFx,
|
||||
|
||||
"url_style": saved.UrlStyle,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +158,8 @@ func (req *updateSettingsRequest) hasAny() bool {
|
||||
req.PointsReplyReward != nil || req.PointsReplyDailyCap != nil ||
|
||||
req.PointsRecommendReward != nil || req.Levels != nil || req.LevelsFx != nil ||
|
||||
req.PostEditLockHours != nil || req.CommentEditLockHours != nil ||
|
||||
req.NecroReplyAfterHours != nil || req.NecroReplyPenalty != nil
|
||||
req.NecroReplyAfterHours != nil || req.NecroReplyPenalty != nil ||
|
||||
req.UrlStyle != nil
|
||||
}
|
||||
|
||||
// AdminGetSettings 超管读取站点设置(与公开 payload 字段一致)
|
||||
@@ -537,6 +542,16 @@ func (h *Handlers) UpdateSettings(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if req.UrlStyle != nil {
|
||||
if err := h.Setting.SetUrlStyle(*req.UrlStyle); err != nil {
|
||||
if errors.Is(err, service.ErrInvalidSiteSetting) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "链接风格无效"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "保存站点设置失败"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
saved, err := h.Setting.Public()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user