修 test01:窄屏装饰全藏导致素材消失、主题名显示成 i18n key

- 生成器:勾「窄屏隐藏全部装饰层」时给橙色警告(几层会消失)、图层行标「窄屏隐藏」、加层与导出结果再提醒;「窄屏」下拉在被全藏覆盖时标注不生效
- 新增 ?narrow=hide 复现该状态(这是「素材在手机上看不到」的头号来源:@media 把 10 槽全写 none,桌面完全正常)
- 主题名:新增 theme.DisplayName + 模板函数 themeName,i18n 未登记 theme.name.<slug> 时回退 slug;原来模板直接调用 i18n.T,缺词条就显示 "theme.name.test01"
- test01.css 删掉 @media 全 none 段:装饰是 fit 单位,浏览器会自己按视口缩,不需要这段
- StaticVersion → 20261020g(主题 css 内容变了,必须换缓存键,否则浏览器还会用旧文件)
This commit is contained in:
tamakyi
2026-10-20 18:23:21 +08:00
parent 3d0239d8f1
commit 6c014b3ad2
8 changed files with 110 additions and 105 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ var (
BuildCommit = "dev"
// StaticVersion 静态资源缓存版本号:base.css 与主题 css 共用,改样式只改这一处。
StaticVersion = "20261020f"
StaticVersion = "20261020g"
)
// 文本审核通道取值([security] text_censor_source)。定义在 conf 侧,
+7
View File
@@ -19,6 +19,7 @@ import (
"github.com/tamakyi/TamaBox/internal/conf"
"github.com/tamakyi/TamaBox/internal/i18n"
"github.com/tamakyi/TamaBox/internal/security/moderation"
"github.com/tamakyi/TamaBox/internal/theme"
)
var (
@@ -192,6 +193,12 @@ func FuncMap() []template.FuncMap {
"langName": func(lang string) string {
return i18n.Name(lang)
},
// themeName 返回主题显示名:i18n 没有 theme.name.<slug> 时回退成 slug 本身。
// 别在模板里直接 {{t .LangCode (printf "theme.name.%s" .Slug)}} ——
// i18n.T 缺词条返回 key,设置页就会显示 "theme.name.test01"。
"themeName": func(lang, slug string) string {
return theme.DisplayName(lang, slug)
},
// moderationStrictness 返回账号「最终生效」的审核严格度档位(lax / standard / strict)。
//
+15
View File
@@ -14,6 +14,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/tamakyi/TamaBox/internal/conf"
"github.com/tamakyi/TamaBox/internal/i18n"
"github.com/tamakyi/TamaBox/static"
)
@@ -46,6 +47,20 @@ var (
siteDef string // 站点默认主题;空串表示「基础外观,不加载主题 css」
)
// DisplayName 返回主题在设置页里的显示名。
//
// 优先取 i18n 的 theme.name.<slug>;**没登记就原样返回 slug**。
// 这条回退是必需的:自建主题(生成器导出的)只放一个 css 就到手,
// 不该为了显示名去改四份词典 —— 否则设置页会把 key 直接印出来(theme.name.test01),
// 而 i18n.T 缺词条时返回 key 本身,调用方无从判断「是缺失还是文案就叫这个」。
func DisplayName(lang, slug string) string {
key := "theme.name." + slug
if name := i18n.T(lang, key); name != key {
return name
}
return slug
}
func load() {
once.Do(func() {
themes, siteDef, bySlug = build(conf.Theme.Default, conf.Theme.Available)
+15
View File
@@ -115,3 +115,18 @@ func TestRuleBodyIgnoresComments(t *testing.T) {
assert.Equal(t, "#ffffff", tokenValue(body, "--tb-bg"))
assert.Equal(t, "rgba(74, 127, 193, 0.11)", tokenValue(body, "--tb-primary"))
}
// DisplayName 的回退是「自建主题零改代码」的前提:
// 生成器导出的主题只放一个 css,没人会为了名字去改四份词典。
// 一旦回退错,设置页会直接把 key 印出来(theme.name.test01),
// 用户看到的就是「主题名变成了键名」。
func TestDisplayName(t *testing.T) {
// 已登记词条的仍走翻译
assert.Equal(t, "基础外观", DisplayName("zh-CN", DefaultSlug))
assert.Equal(t, "Shiroko", DisplayName("en", "shiroko"))
// 没登记词条的自建主题:回退 slug,且绝不能返回 key 本身
assert.Equal(t, "test01", DisplayName("zh-CN", "test01"))
assert.Equal(t, "test01", DisplayName("ja", "test01"))
assert.Equal(t, "my-theme", DisplayName("en", "my-theme"))
}