Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"videoweb/app/service/configser"
|
|
"videoweb/app/service/seoser"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// RobotsTXT 动态 robots.txt(含 Sitemap 声明)。
|
|
func RobotsTXT(c *gin.Context) {
|
|
cfg := configser.FetchAppConfigVMOrEmpty(c)
|
|
foreverURL := seoser.ResolveSiteURL(c, cfg)
|
|
c.Header("Content-Type", "text/plain; charset=utf-8")
|
|
c.Header("Cache-Control", "public, max-age=3600")
|
|
c.String(http.StatusOK, seoser.BuildRobotsTXT(foreverURL))
|
|
}
|
|
|
|
// SEOVerifyFile 提供百度 HTML 验证文件和 IndexNow key.txt。
|
|
func SEOVerifyFile(c *gin.Context) {
|
|
codes := seoser.VerifyFromConfig()
|
|
name := strings.TrimPrefix(c.Request.URL.Path, "/")
|
|
|
|
switch {
|
|
case codes.BaiduHTML != "" && name == codes.BaiduHTML:
|
|
c.Header("Cache-Control", "public, max-age=86400")
|
|
c.String(http.StatusOK, codes.Baidu)
|
|
return
|
|
case codes.IndexNowKey != "" && name == codes.IndexNowKey+".txt":
|
|
c.Header("Cache-Control", "public, max-age=86400")
|
|
c.Data(http.StatusOK, "text/plain; charset=utf-8", []byte(codes.IndexNowKey))
|
|
return
|
|
}
|
|
|
|
c.Status(http.StatusNotFound)
|
|
}
|