hscontrol: consolidate assets into single package

Move favicon.png, style.css, and headscale.svg to hscontrol/assets/
and create a single assets.go file with all embed directives.

Update hscontrol/handlers.go and hscontrol/templates/general.go to
use the centralized assets package.
This commit is contained in:
Kristoffer Dalby
2025-11-12 14:23:15 +01:00
committed by Kristoffer Dalby
parent 09c9762fe0
commit e3ced80278
5 changed files with 38 additions and 22 deletions

View File

@@ -0,0 +1,24 @@
// Package assets provides embedded static assets for Headscale.
// All static files (favicon, CSS, SVG) are embedded here for
// centralized asset management.
package assets
import (
_ "embed"
)
// Favicon is the embedded favicon.png file served at /favicon.ico
//
//go:embed favicon.png
var Favicon []byte
// CSS is the embedded style.css stylesheet used in HTML templates.
// Contains Material for MkDocs design system styles.
//
//go:embed style.css
var CSS string
// SVG is the embedded headscale.svg logo used in HTML templates.
//
//go:embed headscale.svg
var SVG string

View File

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@@ -9,10 +9,12 @@
--md-primary-fg-color: #4051b5;
--md-accent-fg-color: #526cfe;
--md-typeset-a-color: var(--md-primary-fg-color);
--md-text-font: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI",
"Helvetica Neue", Arial, sans-serif;
--md-code-font: "Roboto Mono", "SF Mono", Monaco, "Cascadia Code", Consolas,
"Courier New", monospace;
--md-text-font:
"Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
Arial, sans-serif;
--md-code-font:
"Roboto Mono", "SF Mono", Monaco, "Cascadia Code", Consolas, "Courier New",
monospace;
}
/* Base Typography */

View File

@@ -2,7 +2,6 @@ package hscontrol
import (
"bytes"
_ "embed"
"encoding/json"
"errors"
"fmt"
@@ -14,6 +13,7 @@ import (
"github.com/chasefleming/elem-go/styles"
"github.com/gorilla/mux"
"github.com/juanfont/headscale/hscontrol/assets"
"github.com/juanfont/headscale/hscontrol/templates"
"github.com/juanfont/headscale/hscontrol/types"
"github.com/rs/zerolog/log"
@@ -278,12 +278,9 @@ func (a *AuthProviderWeb) RegisterHandler(
writer.Write([]byte(templates.RegisterWeb(registrationId).Render()))
}
//go:embed assets/favicon.png
var favicon []byte
func FaviconHandler(writer http.ResponseWriter, req *http.Request) {
writer.Header().Set("Content-Type", "image/png")
http.ServeContent(writer, req, "favicon.ico", time.Unix(0, 0), bytes.NewReader(favicon))
http.ServeContent(writer, req, "favicon.ico", time.Unix(0, 0), bytes.NewReader(assets.Favicon))
}
// BlankHandler returns a blank page with favicon linked.

View File

@@ -1,22 +1,15 @@
package templates
import (
_ "embed"
"github.com/chasefleming/elem-go"
"github.com/chasefleming/elem-go/attrs"
"github.com/chasefleming/elem-go/styles"
"github.com/juanfont/headscale/hscontrol/assets"
)
//go:embed style.css
var headscaleCSS string
//go:embed headscale.svg
var headscaleSVG string
// mdTypesetBody creates a body element with md-typeset styling
// that matches the official Headscale documentation design.
// Uses CSS classes with styles defined in headscaleCSS.
// Uses CSS classes with styles defined in assets.CSS.
func mdTypesetBody(children ...elem.Node) *elem.Element {
return elem.Body(attrs.Props{
attrs.Style: styles.Props{
@@ -41,7 +34,7 @@ func mdTypesetBody(children ...elem.Node) *elem.Element {
// Styled Element Wrappers
// These functions wrap elem-go elements using CSS classes.
// Styling is handled by the CSS in headscaleCSS.
// Styling is handled by the CSS in assets.CSS.
// H1 creates a H1 element styled by .md-typeset h1
func H1(children ...elem.Node) *elem.Element {
@@ -126,7 +119,7 @@ func contentContainer(children ...elem.Node) *elem.Element {
// The logo is styled by the .headscale-logo CSS class.
func headscaleLogo() elem.Node {
// Return the embedded SVG as-is
return elem.Raw(headscaleSVG)
return elem.Raw(assets.SVG)
}
// pageFooter creates a consistent footer for all pages.
@@ -198,7 +191,7 @@ func HtmlStructure(head, body *elem.Element) *elem.Element {
attrs.Href: "https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&family=Roboto+Mono:wght@400;700&display=swap",
}),
// Material for MkDocs CSS styles
elem.Style(attrs.Props{attrs.Type: "text/css"}, elem.Raw(headscaleCSS)),
elem.Style(attrs.Props{attrs.Type: "text/css"}, elem.Raw(assets.CSS)),
head,
),
body,