package web import ( "fmt" "html" "io" "net/http" ) // pausePage 渲染一个「停一下」的极简提示页:给一句人话、一个回首页的按钮, // 需要时再自动跳回首页。用于「内容对访客不开放」这类情况—— // 直接甩 404 会让人以为站点坏了,说清楚再引导走开才不突兀。 // // autoSeconds > 0 时页面会自己跳回首页(同时把按钮留给人手动点)。 func (s *Server) pausePage(w http.ResponseWriter, status int, icon, title, msg string, autoSeconds int) { var auto string if autoSeconds > 0 { auto = fmt.Sprintf(``, autoSeconds) } if icon == "" { icon = "🔒" } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Cache-Control", "no-store") w.WriteHeader(status) fmt.Fprintf(w, ``+ ``+ `%s%s`+ ``+ `
`+ `
%s

%s

%s

`+ `返回首页`, html.EscapeString(title), auto, assetVersion, icon, html.EscapeString(title), html.EscapeString(msg)) if autoSeconds > 0 { fmt.Fprintf(w, `
%d 秒后自动回到首页
`, autoSeconds) } io.WriteString(w, `
`) } // placeHiddenPage 是「这个地点没对访客开放」时的回应。 // // 注意取舍:以前这里直接 404,好处是访客分不清「被藏起来了」和「根本不存在」。 // 现在改成明确告知,更好懂,代价是能反推出某个 ID 确实存在。个人站点这个取舍划算, // 想换回原样只需要把这一处改回 http.NotFound。 func (s *Server) placeHiddenPage(w http.ResponseWriter) { s.pausePage(w, http.StatusForbidden, "🔒", "这个地点没有对访客开放", "站长按区域设置隐藏了这个地点的记录。带你去别处看看。", 4) }