aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Scholten2026-06-17 14:14:27 +1000
committerSam Scholten2026-06-17 14:14:27 +1000
commitf8f03e198712dffcf36f71267db759930eff06eb (patch)
tree30cff998f6644c18dc4c7e52aafbd29ce21f9f15
parentdecc46c876e7b5552f5f5ecac4ee4f1a64ad1d62 (diff)
downloadabvjt-f8f03e198712dffcf36f71267db759930eff06eb.tar.gz
abvjt-f8f03e198712dffcf36f71267db759930eff06eb.zip
Add --footer flag for custom HTML footer in web UI
Allows deploying with contextual links (e.g. homepage).
-rw-r--r--server.go11
-rw-r--r--templates/index.html1
2 files changed, 9 insertions, 3 deletions
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,
+ })
}
}
diff --git a/templates/index.html b/templates/index.html
index cccd378..5426164 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -100,6 +100,7 @@
<footer>
<a href="/api/health">health</a> &mdash;
data from <a href="https://wos-help.webofscience.com/WOKRS535R111/help/WOS/A_abrvjt.html">Web of Science</a>
+{{if .Footer}} &mdash; {{.Footer}}{{end}}
</footer>
<script>
const form = document.getElementById('searchForm');