From f8f03e198712dffcf36f71267db759930eff06eb Mon Sep 17 00:00:00 2001 From: Sam Scholten Date: Wed, 17 Jun 2026 14:14:27 +1000 Subject: Add --footer flag for custom HTML footer in web UI Allows deploying with contextual links (e.g. homepage). --- server.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'server.go') diff --git a/server.go b/server.go index eeaa42e..1fe9522 100644 --- a/server.go +++ b/server.go @@ -28,6 +28,7 @@ type ServeCommand struct { Port int DBPath string RateLimit int + Footer string } func (c *ServeCommand) Name() string { return "serve" } @@ -37,6 +38,7 @@ func (c *ServeCommand) Init(args []string) error { fs.IntVar(&c.Port, "port", 8080, "Port to listen on") fs.StringVar(&c.DBPath, "db", "data/abvjt.db", "Path to SQLite database") fs.IntVar(&c.RateLimit, "rate-limit", 30, "Max requests per minute per IP") + fs.StringVar(&c.Footer, "footer", "", "Custom HTML footer for the web interface") if err := fs.Parse(args); err != nil { if errors.Is(err, flag.ErrHelp) { fs.Usage() @@ -54,7 +56,7 @@ func (c *ServeCommand) Run(stdin io.Reader, stdout io.Writer) error { } defer db.Close() - http.HandleFunc("/", handleRoot()) + http.HandleFunc("/", handleRoot(c.Footer)) http.HandleFunc("/api/search", handleSearch(db, c.RateLimit)) http.HandleFunc("/api/health", handleHealth(db, c.RateLimit)) @@ -99,18 +101,21 @@ func (c *ServeCommand) Run(stdin io.Reader, stdout io.Writer) error { return nil } -func handleRoot() http.HandlerFunc { +func handleRoot(footer string) http.HandlerFunc { tmpl, err := template.New("index").Parse(indexHTML) if err != nil { panic(fmt.Sprintf("failed to parse template: %v", err)) } + footerHTML := template.HTML(footer) return func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { http.NotFound(w, r) return } w.Header().Set("Content-Type", "text/html; charset=utf-8") - tmpl.Execute(w, nil) + tmpl.Execute(w, map[string]interface{}{ + "Footer": footerHTML, + }) } } -- cgit v1.2.3