Support selecting theme on the footer (#35741)
Fixes: https://github.com/go-gitea/gitea/pull/27576
This commit is contained in:
@@ -5,13 +5,16 @@ package context
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/services/webtheme"
|
||||
)
|
||||
|
||||
var _ context.Context = TemplateContext(nil)
|
||||
|
||||
func NewTemplateContext(ctx context.Context) TemplateContext {
|
||||
return TemplateContext{"_ctx": ctx}
|
||||
func NewTemplateContext(ctx context.Context, req *http.Request) TemplateContext {
|
||||
return TemplateContext{"_ctx": ctx, "_req": req}
|
||||
}
|
||||
|
||||
func (c TemplateContext) parentContext() context.Context {
|
||||
@@ -33,3 +36,19 @@ func (c TemplateContext) Err() error {
|
||||
func (c TemplateContext) Value(key any) any {
|
||||
return c.parentContext().Value(key)
|
||||
}
|
||||
|
||||
func (c TemplateContext) CurrentWebTheme() *webtheme.ThemeMetaInfo {
|
||||
req := c["_req"].(*http.Request)
|
||||
var themeName string
|
||||
if webCtx := GetWebContext(c); webCtx != nil {
|
||||
if webCtx.Doer != nil {
|
||||
themeName = webCtx.Doer.Theme
|
||||
}
|
||||
}
|
||||
if themeName == "" {
|
||||
if cookieTheme, _ := req.Cookie("gitea_theme"); cookieTheme != nil {
|
||||
themeName = cookieTheme.Value
|
||||
}
|
||||
}
|
||||
return webtheme.GuaranteeGetThemeMetaInfo(themeName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user