package web import ( "net/http" "strings" "videoweb/app/service/configser" "videoweb/app/service/seoser" "github.com/gin-gonic/gin" ) // RobotsTXT 输出可抓取规则及绝对 sitemap 地址。 func RobotsTXT(c *gin.Context) { cfg := configser.FetchAppConfigVMOrEmpty(c) siteURL := seoser.ResolveSiteURL(c, cfg) c.Header("Content-Type", "text/plain; charset=utf-8") c.String(http.StatusOK, seoser.BuildRobotsTXT(siteURL)) } // LLMSTXT 输出简洁站点说明及核心页面的规范地址,供 AI 抓取工具发现内容。 func LLMSTXT(c *gin.Context) { cfg := configser.FetchAppConfigVMOrEmpty(c) writeLLMSTXT(c, cfg) } func writeLLMSTXT(c *gin.Context, cfg configser.AppConfigVM) { siteURL := seoser.ResolveSiteURL(c, cfg) c.Header("Content-Type", "text/plain; charset=utf-8") c.String(http.StatusOK, seoser.BuildLLMSTXT(siteURL, cfg)) } // SEOVerifyFile 输出 IndexNow 所有权验证文本。 func SEOVerifyFile(c *gin.Context) { key := strings.TrimSuffix(strings.TrimPrefix(c.Request.URL.Path, "/"), ".txt") configured := seoser.VerifyFromConfig().IndexNowKey if key == "" || key != configured { NotFound(c) return } c.Header("Content-Type", "text/plain; charset=utf-8") c.String(http.StatusOK, configured) } // DownloadApp 将站内统一下载入口重定向到配置的官方地址,避免模板回退链接产生 404。 func DownloadApp(c *gin.Context) { cfg := configser.FetchAppConfigVMOrEmpty(c) target := strings.TrimSpace(cfg.AppAddr) if target == "" { target = strings.TrimSpace(cfg.OfficialAppAddr) } if target == "" { target = "/" } c.Header("X-Robots-Tag", "noindex, nofollow") c.Redirect(http.StatusFound, target) }