feat: 关于本站对齐站点公告,增加全部与管理入口

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-18 01:47:39 +08:00
parent 184489bca2
commit 2ccfb5f330
15 changed files with 384 additions and 80 deletions

View File

@@ -10,6 +10,16 @@ import (
"gorm.io/gorm"
)
// SitePagesList 已发布单页目录(全部页)
func (h *Handlers) SitePagesList(c *gin.Context) {
list, err := h.SitePage.ListPublished()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "获取页面失败"})
return
}
c.JSON(http.StatusOK, gin.H{"pages": nonNilSlice(list)})
}
// SitePageDetail 公开单页详情(按 slug)
func (h *Handlers) SitePageDetail(c *gin.Context) {
slug := c.Param("slug")

View File

@@ -131,6 +131,7 @@ func Setup(cfg *config.Config) (*gin.Engine, error) {
pubAPI.GET("/users/:id/comments", h.UserComments)
pubAPI.GET("/announcements", h.AnnouncementsList)
pubAPI.GET("/announcements/:id", h.AnnouncementDetail)
pubAPI.GET("/pages", h.SitePagesList)
pubAPI.GET("/pages/:slug", h.SitePageDetail)
pubAPI.GET("/settings", h.PublicSettings)
pubAPI.POST("/telemetry/pageview", middleware.CSRFMiddleware(), h.TelemetryPageView)

View File

@@ -4,6 +4,7 @@ import (
"errors"
"regexp"
"strings"
"time"
"unicode/utf8"
"github.com/freefire/jiang13-bbs/model"
@@ -47,6 +48,16 @@ type SidebarPageItem struct {
Excerpt string `json:"excerpt"`
}
// PublishedPageItem 公开单页目录(全部页,含未进侧栏的已发布页)
type PublishedPageItem struct {
ID uint `json:"id"`
Slug string `json:"slug"`
Title string `json:"title"`
Excerpt string `json:"excerpt"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (in *SitePageInput) normalize(existing *model.SitePage) error {
in.Slug = strings.ToLower(strings.TrimSpace(in.Slug))
if in.Slug == "" {
@@ -133,6 +144,27 @@ func (s *SitePageService) ListSidebarPublished() ([]SidebarPageItem, error) {
return out, nil
}
// ListPublished 已发布单页目录(全部页;含未勾选侧栏的)
func (s *SitePageService) ListPublished() ([]PublishedPageItem, error) {
var pages []model.SitePage
err := s.db.Where("published = ?", true).
Order("sort_order ASC, id ASC").
Select("id", "slug", "title", "excerpt", "created_at", "updated_at").
Limit(100).
Find(&pages).Error
if err != nil {
return nil, err
}
out := make([]PublishedPageItem, 0, len(pages))
for _, p := range pages {
out = append(out, PublishedPageItem{
ID: p.ID, Slug: p.Slug, Title: p.Title, Excerpt: p.Excerpt,
CreatedAt: p.CreatedAt, UpdatedAt: p.UpdatedAt,
})
}
return out, nil
}
// GetPublishedBySlug 公开详情(仅已发布)
func (s *SitePageService) GetPublishedBySlug(slug string) (*model.SitePage, error) {
slug = strings.ToLower(strings.TrimSpace(slug))