Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
28 lines
751 B
Go
28 lines
751 B
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// NotFound 统一 404 页(HTTP 404)。
|
|
func NotFound(c *gin.Context, title string) {
|
|
if title == "" {
|
|
title = "页面未找到"
|
|
}
|
|
data := gin.H{
|
|
"title": title,
|
|
"path": c.Request.URL.RequestURI(),
|
|
}
|
|
setNoIndex(data, true)
|
|
HTML(c, http.StatusNotFound, "404.html", data)
|
|
}
|
|
|
|
// emptyScopedPage 判断带明确资源标识的列表详情是否不存在。
|
|
// 聚合页允许暂时为空;标签、分类、专题等详情页成功返回空结果时应响应 404,
|
|
// 避免用空模板和 HTTP 200 形成搜索引擎软 404。
|
|
func emptyScopedPage(hasIdentifier bool, totalCount int64, itemCount int) bool {
|
|
return hasIdentifier && totalCount <= 0 && itemCount == 0
|
|
}
|