fix(ui): 登录页页脚被当纯文本显示(html/template 转义)+ 三处页脚统一
用户发现登录页出现 `<div class="navi-footer">…` 这串标记文字。 ① 根因:auth.go 把 beianFooter() 的字符串塞进 Go html/template(map[string]string), 模板自动转义整段 HTML → 页面上直接显示标记源码。 修法:改用 map[string]any + template.HTML(beianFooter 内部已对备案号做 html.EscapeString, 注入合法)。 ② 登录页与门户页此前**都无视**后台的「页脚」自定义字段(后台提示语写的是"填写后以这里为准")。 新增统一入口 siteFooter(info):自定义 footer 优先,否则按 icp/gongan/座右铭生成; pages.go(门户页)与 auth.go(登录页)都改走它。 ③ 页脚座右铭此前只由 navi.js 在 Dashy 页客户端注入 → 登录页/门户页永远没有。 新增 pageInfo 字段 motto(换行或 | 分行,留空用内置默认), footerMarkup() 生成时一并输出 .navi-quote 两行;navi.js 已有幂等判断不会重复注入。 后台「站点信息」新增座右铭输入框,并登记进 /api/schema。 ④ 登录页 / 门户页补页脚样式:左列两行备案号、右列两行座右铭;窄屏退化为居中单列。
This commit is contained in:
@ -160,7 +160,15 @@ input{width:100%;padding:11px 13px;border:1px solid var(--inbd);border-radius:10
|
||||
input:focus{border-color:var(--ac);box-shadow:0 0 0 3px rgba(37,99,235,.12)}
|
||||
button[type=submit]{width:100%;margin-top:18px;padding:11px;border:0;border-radius:10px;background:var(--ac);color:#fff;font:inherit;font-weight:750;cursor:pointer}
|
||||
.err{padding:9px 11px;border-radius:9px;background:var(--errbg);color:var(--errtx);font-size:13px;margin-bottom:14px}
|
||||
.foot{text-align:center;margin-top:22px;font-size:11px;color:var(--tx2)}.foot a{color:inherit;text-decoration:none}
|
||||
.foot{margin-top:22px;font-size:11px;color:var(--tx2)}
|
||||
.foot a{color:inherit;text-decoration:none}
|
||||
/* 页脚:左列两行备案号 / 右列两行座右铭(与主站一致)。
|
||||
登录卡片只有 400px,窄到放不下两列时退化为居中单列,避免挤压换行。 */
|
||||
.foot .navi-footer{display:grid;grid-template-columns:auto auto;grid-template-rows:auto auto;grid-auto-flow:column;gap:2px 12px;justify-content:space-between;align-items:center;text-align:left}
|
||||
.foot .navi-footer-sep{display:none}
|
||||
.foot .navi-quote{grid-column:2;justify-self:end;opacity:.85}
|
||||
@media(max-width:430px){.foot .navi-footer{grid-template-columns:auto;grid-auto-flow:row;justify-content:center;text-align:center;gap:2px}
|
||||
.foot .navi-quote{grid-column:1;justify-self:center}}
|
||||
@media(prefers-reduced-motion:reduce){*{transition:none!important}}
|
||||
</style></head><body><main class="card">
|
||||
<button class="theme" type="button" onclick="(function(){var n=document.documentElement.getAttribute('data-theme')==='dark'?'light':'dark';document.documentElement.setAttribute('data-theme',n);localStorage.setItem('theme',n)})()" title="切换深浅色" aria-label="切换深浅色">◐</button>
|
||||
@ -172,11 +180,14 @@ button[type=submit]{width:100%;margin-top:18px;padding:11px;border:0;border-radi
|
||||
func renderPortalLogin(w http.ResponseWriter, redirect, errText string) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
title, subtitle, logo, icp, gongan := authPageInfo()
|
||||
_ = portalLoginTemplate.Execute(w, map[string]string{
|
||||
title, subtitle, logo, _, _ := authPageInfo()
|
||||
// 关键:页脚是一段 HTML,必须用 template.HTML 交给模板。
|
||||
// 此前用 map[string]string,html/template 会把整段标记转义成文本,
|
||||
// 页面直接显示 <div class="navi-footer">… 源码(线上实测)。
|
||||
_ = portalLoginTemplate.Execute(w, map[string]any{
|
||||
"Redirect": url.QueryEscape(redirect), "Error": errText,
|
||||
"Title": title, "Subtitle": subtitle, "Logo": logo,
|
||||
"Footer": beianFooter(icp, gongan),
|
||||
"Footer": template.HTML(siteFooter(pageInfoMap())),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -826,7 +826,35 @@ func handleSyncInfo(w http.ResponseWriter, r *http.Request) {
|
||||
// 备案号在 /admin/ 里就是两个普通输入框,模板统一由服务端生成,
|
||||
// 用户不必写 HTML;类名与 web/navi.css 里的 .navi-footer 对应。
|
||||
// footer 字段本身仍然保留:传了自定义 HTML 就以它为准(高级用法)。
|
||||
// defaultMotto 是页脚座右铭的内置默认(每行一句)。
|
||||
// 可用后台「站点信息 → 页脚座右铭」或 POST /admin/api/pageinfo {"motto":"…"} 覆盖(换行或 | 分行)。
|
||||
const defaultMotto = "不念往昔之繁华\n无谓前路之沧桑"
|
||||
|
||||
// mottoLines 解析座右铭为多行;空值回落内置默认。
|
||||
func mottoLines(info map[string]any) []string {
|
||||
raw := strings.TrimSpace(mapString(info, "motto"))
|
||||
if raw == "" {
|
||||
raw = defaultMotto
|
||||
}
|
||||
parts := strings.FieldsFunc(raw, func(r rune) bool { return r == '\n' || r == '|' })
|
||||
out := make([]string, 0, len(parts))
|
||||
for _, p := range parts {
|
||||
if t := strings.TrimSpace(p); t != "" {
|
||||
out = append(out, t)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// beianFooter 保留旧签名(不含座右铭),供既有调用与测试使用。
|
||||
func beianFooter(icp, gongan string) string {
|
||||
return footerMarkup(icp, gongan, nil)
|
||||
}
|
||||
|
||||
// footerMarkup 生成页脚 HTML:备案号两项 + 座右铭若干行(.navi-quote)。
|
||||
// 结构契约:.navi-footer > (a 备案 ×2, span.navi-footer-sep ×2, span.navi-quote ×N)。
|
||||
// 分隔符保留在标记里(Dashy/登录页靠 CSS 隐藏并排成两列),这样旧样式也不会串行。
|
||||
func footerMarkup(icp, gongan string, motto []string) string {
|
||||
icp = strings.TrimSpace(icp)
|
||||
gongan = strings.TrimSpace(gongan)
|
||||
parts := make([]string, 0, 2)
|
||||
@ -836,10 +864,27 @@ func beianFooter(icp, gongan string) string {
|
||||
if gongan != "" {
|
||||
parts = append(parts, `<a href="https://beian.mps.gov.cn" target="_blank" rel="noopener noreferrer">`+html.EscapeString(gongan)+`</a>`)
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
if len(parts) == 0 && len(motto) == 0 {
|
||||
return ""
|
||||
}
|
||||
return `<div class="navi-footer">` + strings.Join(parts, `<span class="navi-footer-sep">·</span>`) + `</div>`
|
||||
inner := strings.Join(parts, `<span class="navi-footer-sep">·</span>`)
|
||||
for i, line := range motto {
|
||||
cls := "navi-quote"
|
||||
if i == 1 {
|
||||
cls += " navi-quote-2"
|
||||
}
|
||||
inner += `<span class="` + cls + `">` + html.EscapeString(line) + `</span>`
|
||||
}
|
||||
return `<div class="navi-footer">` + inner + `</div>`
|
||||
}
|
||||
|
||||
// siteFooter 是页脚的唯一入口:后台自定义 footer 优先,否则按备案号 + 座右铭生成。
|
||||
// 登录页 / 门户页 / Dashy 三处都必须走它,避免"某一页漏掉座右铭、或整段被转义"。
|
||||
func siteFooter(info map[string]any) string {
|
||||
if s := strings.TrimSpace(mapString(info, "footer")); s != "" {
|
||||
return s
|
||||
}
|
||||
return footerMarkup(mapString(info, "icp"), mapString(info, "gongan"), mottoLines(info))
|
||||
}
|
||||
|
||||
// mapString 读取 map 里的字符串字段,缺失或类型不符时返回空串。
|
||||
@ -876,6 +921,7 @@ func handlePageInfo(w http.ResponseWriter, r *http.Request) {
|
||||
Footer *string `json:"footer"`
|
||||
ICP *string `json:"icp"`
|
||||
Gongan *string `json:"gongan"`
|
||||
Motto *string `json:"motto"`
|
||||
NavLinks *[]map[string]any `json:"navLinks"`
|
||||
// 认证页与门户页的可配置文案(原先写死在代码/镜像里)
|
||||
AuthTitle *string `json:"authTitle"`
|
||||
@ -905,9 +951,18 @@ func handlePageInfo(w http.ResponseWriter, r *http.Request) {
|
||||
if body.Gongan != nil {
|
||||
cfg.PageInfo["gongan"] = *body.Gongan
|
||||
}
|
||||
// 页脚为空(留空 = 交给模板)时,按备案号重新生成。
|
||||
// 座右铭:留空回落内置默认;必须在下面"重新生成页脚"之前写入
|
||||
if body.Motto != nil {
|
||||
if strings.TrimSpace(*body.Motto) == "" {
|
||||
delete(cfg.PageInfo, "motto")
|
||||
} else {
|
||||
cfg.PageInfo["motto"] = strings.TrimSpace(*body.Motto)
|
||||
}
|
||||
}
|
||||
// 页脚为空(留空 = 交给模板)时,按备案号 + 座右铭重新生成。
|
||||
if strings.TrimSpace(mapString(cfg.PageInfo, "footer")) == "" {
|
||||
cfg.PageInfo["footer"] = beianFooter(mapString(cfg.PageInfo, "icp"), mapString(cfg.PageInfo, "gongan"))
|
||||
cfg.PageInfo["footer"] = footerMarkup(mapString(cfg.PageInfo, "icp"),
|
||||
mapString(cfg.PageInfo, "gongan"), mottoLines(cfg.PageInfo))
|
||||
} // 认证页 / 门户页文案:空串表示回落到内置默认值
|
||||
setPageStr := func(k string, v *string) {
|
||||
if v != nil {
|
||||
|
||||
@ -62,7 +62,7 @@ func renderPortalPage() []byte {
|
||||
"<!--PAGE_TITLE-->", html.EscapeString(pageStr(info, "portalTitle", defaultPortalTitle)),
|
||||
"<!--HERO_TITLE-->", html.EscapeString(pageStr(info, "heroTitle", defaultPortalHero)),
|
||||
"<!--HERO_SUBTITLE-->", html.EscapeString(pageStr(info, "heroSubtitle", defaultPortalHeroSub)),
|
||||
"<!--FOOTER-->", beianFooter(mapString(info, "icp"), mapString(info, "gongan")),
|
||||
"<!--FOOTER-->", siteFooter(info),
|
||||
)
|
||||
out := rep.Replace(string(builtin))
|
||||
// 服务卡片区可覆盖:数据卷 portal/cards.html 存在时替换标记之间的内容,
|
||||
@ -144,6 +144,15 @@ func handlePortalPage(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write(renderPortalPage())
|
||||
}
|
||||
|
||||
// pageInfoMap 读取数据卷里的站点信息(供 siteFooter 等统一入口使用)。
|
||||
func pageInfoMap() map[string]any {
|
||||
cfg, err := loadConfig()
|
||||
if err != nil || cfg == nil || cfg.PageInfo == nil {
|
||||
return map[string]any{}
|
||||
}
|
||||
return cfg.PageInfo
|
||||
}
|
||||
|
||||
// authPageInfo 返回登录页所需字段(供 auth.go 渲染)。
|
||||
func authPageInfo() (title, subtitle, logo, icp, gongan string) {
|
||||
cfg, err := loadConfig()
|
||||
|
||||
@ -28,7 +28,8 @@ var pageInfoFields = []struct{ Key, Label, Hint string }{
|
||||
{"heroSubtitle", "门户页副标题", "留空回落内置默认"},
|
||||
{"icp", "ICP 备案号", "显示于各页页脚;被代理页面也会注入"},
|
||||
{"gongan", "公安备案号", "可选,显示于页脚"},
|
||||
{"footer", "自定义页脚 HTML", "高级:整段替换页脚内容"},
|
||||
{"motto", "页脚座右铭", "每行一句(换行或 | 分隔);留空用内置默认"},
|
||||
{"footer", "自定义页脚 HTML", "高级:整段替换页脚内容(登录页/门户页同样生效)"},
|
||||
{"navLinks", "页脚导航链接数组", "数组,元素形如 {name,url}"},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user