Files
web_huangguo_web/app/api/web/richtext.go
T
fish03andClaude Opus 5.5 bef9f8b4ed Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 14:43:16 +07:00

89 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package web
import (
"net/url"
"strings"
"videoweb/app/service/configser"
"videoweb/app/service/seoser"
"github.com/gin-gonic/gin"
)
// Richtext 富文本页 SSR:GET /api/app/config/richtext/list?titles=
func Richtext(c *gin.Context) {
title := routeOrQuery(c, "title", "title")
target := "/richtext"
if title != "" {
target += "/" + url.PathEscape(title)
}
target += "/"
if redirectCanonical(c, target) {
return
}
renderRichtext(c, title)
}
func RichtextPage(title string) gin.HandlerFunc {
return func(c *gin.Context) {
page := configser.FetchRichTextByTitle(c, title)
if !page.Found {
fallbackTemplates := map[string]string{
"关于我们": "aboutUs.html",
"用户协议": "userAgreement.html",
"隐私政策": "privacyPolicy.html",
"帮助中心": "helpCenter.html",
}
if fallbackTemplate := fallbackTemplates[title]; fallbackTemplate != "" {
data := gin.H{"title": title}
applyRichtextIndexPolicy(data, title)
if title == "帮助中心" {
data["faqItems"] = []seoser.FAQItem{
{Question: "无法登录账号怎么办?", Answer: "请确认邮箱与密码是否正确;若忘记密码,可在登录页面使用“找回密码”。"},
{Question: "观看记录没有同步?", Answer: "请确认已登录同一账号并保持网络连接,记录通常会自动同步。"},
{Question: "视频无法播放或加载缓慢?", Answer: "建议切换网络、刷新页面或更新浏览器;问题持续时可提交反馈。"},
{Question: "如何管理收藏内容?", Answer: "进入个人中心的“追剧与收藏”页面,可查看或取消收藏。"},
}
}
HTMLOK(c, fallbackTemplate, data)
return
}
}
renderRichtextData(c, title, page)
}
}
func renderRichtext(c *gin.Context, title string) {
title = strings.TrimSpace(title)
page := configser.FetchRichTextByTitle(c, title)
renderRichtextData(c, title, page)
}
func renderRichtextData(c *gin.Context, title string, page configser.RichTextPageVM) {
if !page.Found {
NotFound(c, "未找到该内容")
return
}
displayTitle := page.Title
if displayTitle == "" {
displayTitle = "内容详情"
}
data := gin.H{
"title": displayTitle,
"richtext": page,
"richtextKey": title,
}
applyRichtextIndexPolicy(data, title)
HTMLOK(c, "richtext.html", data)
}
func applyRichtextIndexPolicy(data gin.H, title string) {
switch strings.TrimSpace(title) {
case "关于我们", "帮助中心":
return
default:
setNoIndex(data, true)
}
}