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

@@ -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))