设置页可配字数/编辑窗/分页与伪静态后缀;公开帖/板/用户链接走规范路径并 301。 Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.iioio.com/freefire/jiang13-forum/modules/webctx"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type boardsItemView struct {
|
|
ID uint
|
|
Name string
|
|
Href string
|
|
Description string
|
|
Icon string
|
|
ColorIndex int
|
|
PostCount int
|
|
}
|
|
|
|
type boardsPageData struct {
|
|
PageChrome
|
|
Items []boardsItemView
|
|
}
|
|
|
|
// BoardsGet 公开板块索引
|
|
func (d Deps) BoardsGet(c *gin.Context) {
|
|
ctx := d.ctx(c)
|
|
d.renderBoards(ctx)
|
|
}
|
|
|
|
func (d Deps) renderBoards(ctx *webctx.Context) {
|
|
brand := d.Settings.SiteBranding()
|
|
chrome := d.chrome(ctx, "板块 · "+brand.Name, "", "")
|
|
list, _ := d.Board.ListWithStats()
|
|
items := make([]boardsItemView, 0, len(list))
|
|
pl := d.permalink()
|
|
for _, b := range list {
|
|
color := b.ColorIndex
|
|
if color < 0 {
|
|
color = int(b.ID % 8)
|
|
}
|
|
items = append(items, boardsItemView{
|
|
ID: b.ID,
|
|
Name: b.Name,
|
|
Href: pl.BoardPath(b.ID),
|
|
Description: b.Description,
|
|
Icon: b.Icon,
|
|
ColorIndex: color,
|
|
PostCount: b.PostCount,
|
|
})
|
|
}
|
|
ctx.HTML(http.StatusOK, "boards/list", boardsPageData{
|
|
PageChrome: chrome,
|
|
Items: items,
|
|
})
|
|
}
|