diff options
| author | Fuwn <[email protected]> | 2026-01-20 06:25:55 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-20 06:25:55 -0800 |
| commit | 9b0b5cd9563702263300e80d48ef3dc73f0add8e (patch) | |
| tree | cdc503855c84b67fdc12d46e192d9506a8fa34a1 | |
| parent | fix: Use generic error message for unknown error types (diff) | |
| download | kaze-9b0b5cd9563702263300e80d48ef3dc73f0add8e.tar.xz kaze-9b0b5cd9563702263300e80d48ef3dc73f0add8e.zip | |
feat: Add custom_head option for injecting HTML into head
| -rw-r--r-- | config.example.yaml | 3 | ||||
| -rw-r--r-- | internal/config/config.go | 3 | ||||
| -rw-r--r-- | internal/server/server.go | 10 | ||||
| -rw-r--r-- | internal/server/templates/index.html | 1 |
4 files changed, 12 insertions, 5 deletions
diff --git a/config.example.yaml b/config.example.yaml index 50f6692..3fe5fa8 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -14,6 +14,9 @@ site: # favicon: "https://example.com/favicon.ico" # Optional favicon URL # theme_url: "https://raw.githubusercontent.com/anomalyco/opencode/main/packages/opencode/src/cli/cmd/tui/context/theme/opencode.json" # ^ Optional: URL to OpenCode-compatible theme JSON (see https://opencode.ai/theme.json for schema) + # custom_head: | + # <script async src="https://analytics.example.com/script.js"></script> + # ^ Optional: Custom HTML to inject into <head> (e.g., analytics, meta tags) # HTTP server settings server: diff --git a/internal/config/config.go b/internal/config/config.go index b819d8f..626873b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -40,7 +40,8 @@ type SiteConfig struct { Description string `yaml:"description"` Logo string `yaml:"logo"` Favicon string `yaml:"favicon"` - ThemeURL string `yaml:"theme_url"` // URL to OpenCode-compatible theme JSON + ThemeURL string `yaml:"theme_url"` // URL to OpenCode-compatible theme JSON + CustomHead string `yaml:"custom_head"` // Custom HTML to inject into <head> (e.g., analytics) } // ServerConfig contains HTTP server settings diff --git a/internal/server/server.go b/internal/server/server.go index 3a1d793..4217dd2 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -128,10 +128,11 @@ type PageData struct { LastUpdatedTooltip string // JSON data for last updated tooltip TickMode string // ping, minute, hour, day TickCount int - Timezone string // Timezone for display - UseBrowserTimezone bool // Use client-side timezone conversion - ThemeCSS template.CSS // OpenCode theme CSS (safe CSS) - Scale float64 // UI scale factor (0.5-2.0) + Timezone string // Timezone for display + UseBrowserTimezone bool // Use client-side timezone conversion + ThemeCSS template.CSS // OpenCode theme CSS (safe CSS) + CustomHead template.HTML // Custom HTML for <head> (trusted) + Scale float64 // UI scale factor (0.5-2.0) } // StatusCounts holds monitor status counts for display @@ -225,6 +226,7 @@ func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) { Timezone: s.config.Display.Timezone, UseBrowserTimezone: s.config.Display.Timezone == "Browser", ThemeCSS: themeCSS, + CustomHead: template.HTML(s.config.Site.CustomHead), Scale: s.config.Display.Scale, } diff --git a/internal/server/templates/index.html b/internal/server/templates/index.html index ea4a170..cd37584 100644 --- a/internal/server/templates/index.html +++ b/internal/server/templates/index.html @@ -20,6 +20,7 @@ <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 .CustomHead}}{{.CustomHead}}{{end}} </head> <body class="bg-neutral-50 dark:bg-neutral-950 text-neutral-900 dark:text-neutral-100 min-h-screen font-mono"> <div class="max-w-4xl mx-auto px-4 py-8 sm:py-12"> |