Files
谢宇宁andClaude Opus 5.5 3639d2184a Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 14:47:17 +07:00

91 lines
2.6 KiB
Go
Raw Permalink 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, "pageName": title}
applyRichtextIndexPolicy(data, title)
if title == "帮助中心" {
data["faqItems"] = []seoser.FAQItem{
{Question: "付费剧集怎么观看?", Answer: "网页端可免费观看免费剧集;付费剧集请下载黄果短剧 App 观看完整内容。"},
{Question: "需要注册账号吗?", Answer: "不需要,网页端无需注册即可直接观看免费剧集。"},
{Question: "视频无法播放或加载缓慢?", Answer: "建议切换网络、刷新页面或更新浏览器;问题持续时可提交反馈。"},
{Question: "在哪里下载 App?", Answer: "点击页面上的“下载APP”入口,按提示扫码或直接下载安装。"},
}
}
HTMLOK(c, fallbackTemplate, data)
return
}
}
renderRichtextData(c, title, title, page)
}
}
func renderRichtext(c *gin.Context, title, pageName string) {
title = strings.TrimSpace(title)
page := configser.FetchRichTextByTitle(c, title)
renderRichtextData(c, title, pageName, page)
}
// pageName 为面包屑名称,与上游富文本标题可能不同。
func renderRichtextData(c *gin.Context, title, pageName 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,
"pageName": pageName,
}
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)
}
}