diff options
| author | Fuwn <[email protected]> | 2026-01-19 23:05:26 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-19 23:05:26 -0800 |
| commit | 4cbee4da97dcc2832cd354142aa9909a80070952 (patch) | |
| tree | 338f54b0ee2dd033f5049888b586aa3c77e22c18 /internal/server | |
| parent | fix: Remove duplicate monitor name validation across groups (diff) | |
| download | kaze-4cbee4da97dcc2832cd354142aa9909a80070952.tar.xz kaze-4cbee4da97dcc2832cd354142aa9909a80070952.zip | |
feat: Add OpenCode-compatible theme loader
Add support for loading and applying OpenCode-compatible themes via URL.
Fetches theme JSON, resolves color references, generates CSS variables
and Tailwind class overrides to apply the theme seamlessly.
Features:
- Add theme_url config field under site section
- Fetch and parse OpenCode theme.json format
- Generate CSS custom properties (--theme-*) for all theme colors
- Generate Tailwind class overrides to apply theme colors
- Support both light and dark modes
- Template.CSS type for safe CSS injection
Example usage:
site:
theme_url: "https://raw.githubusercontent.com/anomalyco/opencode/.../opencode.json"
Theme schema: https://opencode.ai/theme.json
Diffstat (limited to 'internal/server')
| -rw-r--r-- | internal/server/server.go | 20 | ||||
| -rw-r--r-- | internal/server/templates/index.html | 6 |
2 files changed, 24 insertions, 2 deletions
diff --git a/internal/server/server.go b/internal/server/server.go index 8681873..6d76fa0 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -17,6 +17,7 @@ import ( "github.com/Fuwn/kaze/internal/config" "github.com/Fuwn/kaze/internal/monitor" "github.com/Fuwn/kaze/internal/storage" + "github.com/Fuwn/kaze/internal/theme" ) //go:embed templates/*.html @@ -126,8 +127,9 @@ type PageData struct { TickMode string // ping, minute, hour, day TickCount int ShowThemeToggle bool - Timezone string // Timezone for display - UseBrowserTimezone bool // Use client-side timezone conversion + Timezone string // Timezone for display + UseBrowserTimezone bool // Use client-side timezone conversion + ThemeCSS template.CSS // OpenCode theme CSS (safe CSS) } // GroupData contains data for a monitor group @@ -190,6 +192,19 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) { return } + // Load OpenCode theme if configured + var themeCSS template.CSS + if s.config.Site.ThemeURL != "" { + resolvedTheme, err := theme.LoadTheme(s.config.Site.ThemeURL) + if err != nil { + s.logger.Warn("failed to load theme", "url", s.config.Site.ThemeURL, "error", err) + } else if resolvedTheme != nil { + // Generate CSS variables and Tailwind mappings + cssString := resolvedTheme.GenerateCSS() + resolvedTheme.GenerateTailwindMappings() + themeCSS = template.CSS(cssString) + } + } + // Build page data data := PageData{ Site: s.config.Site, @@ -198,6 +213,7 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) { ShowThemeToggle: s.config.Display.ShowThemeToggle != nil && *s.config.Display.ShowThemeToggle, Timezone: s.config.Display.Timezone, UseBrowserTimezone: s.config.Display.Timezone == "Browser", + ThemeCSS: themeCSS, } overallUp := true diff --git a/internal/server/templates/index.html b/internal/server/templates/index.html index db4c61a..6bdfeff 100644 --- a/internal/server/templates/index.html +++ b/internal/server/templates/index.html @@ -11,6 +11,12 @@ <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎐</text></svg>"> {{end}} <link rel="stylesheet" href="/static/style.css"> + {{if .ThemeCSS}} + <style> + /* OpenCode Theme */ +{{.ThemeCSS}} + </style> + {{end}} <script> // Theme detection if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) { |