This commit is contained in:
tamakyi
2026-10-19 16:16:07 +08:00
parent e9fba8b9ed
commit 3202ef9821
54 changed files with 12000 additions and 75 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ var (
BuildCommit = "dev"
// StaticVersion 静态资源缓存版本号:base.css 与主题 css 共用,改样式只改这一处。
StaticVersion = "20261019e"
StaticVersion = "20261019f"
)
// 文本审核通道取值([security] text_censor_source)。定义在 conf 侧,
+15
View File
@@ -26,6 +26,7 @@ import (
"github.com/tamakyi/TamaBox/internal/i18n"
"github.com/tamakyi/TamaBox/internal/shared"
templatepkg "github.com/tamakyi/TamaBox/internal/template"
"github.com/tamakyi/TamaBox/internal/theme"
)
type EndpointType string
@@ -239,6 +240,13 @@ func Contexter() flamego.Handler {
isUserPage := strings.HasPrefix(path, "/user") || strings.HasPrefix(path, "/_/")
c.Data["IsUserPage"] = isUserPage
// 主题:/user 后台是箱主本人的页面,跟随本人配置;
// /_/{domain} 的箱主主题由 question.Pager 覆盖(访客看到的是箱主的选择)。
// 空串(未选且站点无默认主题)= 不加载主题 css。
if isThemeScope(path) && c.IsLogged {
c.Data["ThemeSlug"] = theme.Resolve(c.User.Theme)
}
// SEO:仅公开页(首页/注册/登录/explore)允许被搜索引擎收录;
// 提问内容(提问箱页、单题页)、密码页、私信、用户后台等隐私页一律 noindex。
isPublicPage := path == "/" || path == "/register" || path == "/login" || strings.HasPrefix(path, "/explore")
@@ -327,3 +335,10 @@ func (c *Context) Lang() string {
}
return i18n.Default
}
// isThemeScope 判断该路径的主题是否由「当前登录用户自己的配置」决定。
// 只覆盖 /user 后台(本人页面);提问箱相关页面由 question.Pager 按箱主注入,
// 公开页(首页/探索/登录)保持站点默认外观,不跟随登录状态变化。
func isThemeScope(path string) bool {
return path == "/user" || strings.HasPrefix(path, "/user/")
}
+30
View File
@@ -0,0 +1,30 @@
package context
import "testing"
// 主题作用域:/user 后台必须命中(否则设置页、题目管理页拿不到自己的主题),
// 其余路径不得命中(提问箱页面由 question.Pager 按箱主注入,公开页保持站点默认)。
func TestIsThemeScope(t *testing.T) {
cases := map[string]bool{
"/user": true,
"/user/": true,
"/user/profile": true,
"/user/questions": true,
"/user/votes/1/results": true,
"/username": false, // 前缀相近但不是用户后台
"/_/admin6": false,
"/_/admin6/share-card": false,
"/": false,
"/explore": false,
"/vote/abc": false,
"/api/v1/user/admin6": false,
"/api/v1/user": false,
"/deactivated": false,
}
for path, want := range cases {
if got := isThemeScope(path); got != want {
t.Errorf("isThemeScope(%q) = %v, want %v", path, got, want)
}
}
}
+1 -1
View File
@@ -933,7 +933,7 @@ var enDict = map[string]string{
// 主题:设置页选择器与主题显示名(theme.name.<slug> 由 internal/theme 约定)
"profile.theme.title": "Theme",
"profile.theme.hint": "Applies to your question box pages only; the rest of the site keeps the default look.",
"profile.theme.hint": "Applies to your question box pages and your dashboard; public pages (home, explore) keep the default look.",
"profile.theme.followDefault": "Follow site default",
"profile.theme.save": "Save theme",
"profile.theme.saved": "Theme saved",
+1 -1
View File
@@ -933,7 +933,7 @@ var jaDict = map[string]string{
// 主题:设置页选择器与主题显示名(theme.name.<slug> 由 internal/theme 约定)
"profile.theme.title": "テーマ",
"profile.theme.hint": "質問箱のページにのみ適用されます。他のページは既定の外観のままです。",
"profile.theme.hint": "質問箱のページと管理画面に適用されます。ホーム・探索などの公開ページは既定の外観のままです。",
"profile.theme.followDefault": "サイト既定に従う",
"profile.theme.save": "テーマを保存",
"profile.theme.saved": "テーマを保存しました",
+1 -1
View File
@@ -874,7 +874,7 @@ var zhCNDict = map[string]string{
// 主题:设置页选择器与主题显示名(theme.name.<slug> 由 internal/theme 约定)
"profile.theme.title": "主题外观",
"profile.theme.hint": "仅对提问箱页面生效,站内其它页面保持默认外观。",
"profile.theme.hint": "对提问箱页面和你的后台页面生效,首页/探索等公开页保持默认外观。",
"profile.theme.followDefault": "跟随站点默认",
"profile.theme.save": "保存主题",
"profile.theme.saved": "主题已保存",
+1 -1
View File
@@ -933,7 +933,7 @@ var zhTWDict = map[string]string{
// 主题:设置页选择器与主题显示名(theme.name.<slug> 由 internal/theme 约定)
"profile.theme.title": "主題外觀",
"profile.theme.hint": "僅對提問箱頁面生效,站內其他頁面維持預設外觀。",
"profile.theme.hint": "對提問箱頁面與你的後台頁面生效,首頁/探索等公開頁維持預設外觀。",
"profile.theme.followDefault": "跟隨站點預設",
"profile.theme.save": "儲存主題",
"profile.theme.saved": "主題已儲存",