feat: HTMX + Go Templates HTML frontend

- Add internal/views/ package with embedded templates and static files
- Go html/template with SearXNG-compatible CSS class names
- Dark mode via prefers-color-scheme, responsive layout, print styles
- HTMX integration:
  - Debounced instant search (500ms) on the search input
  - Form submission targets #results via hx-post
  - Pagination buttons are HTMX-powered (swap results div only)
  - HX-Request header detection for fragment vs full page rendering
- Template structure:
  - base.html: full page layout with HTMX script, favicon, CSS
  - index.html: homepage with centered search box
  - results.html: full results page (wraps base + results_inner)
  - results_inner.html: results fragment (HTMX partial + sidebar + pagination)
  - result_item.html: reusable result article partial
- Smart format detection: browser requests (Accept: text/html) default to HTML,
  API clients default to JSON
- Static files served at /static/ from embedded FS (CSS, favicon SVG)
- Index route at GET /
- Empty query on HTML format redirects to homepage
- Custom CSS (gosearch.css): clean, minimal, privacy-respecting aesthetic
  with light/dark mode, responsive breakpoints, print stylesheet
- Add views package tests
This commit is contained in:
Franz Kafka 2026-03-21 16:10:42 +00:00
parent ebeaeeef21
commit 28b61ff251
12 changed files with 1013 additions and 8 deletions

View file

@ -18,11 +18,13 @@ func ParseSearchRequest(r *http.Request) (SearchRequest, error) {
format := strings.ToLower(r.FormValue("format"))
switch OutputFormat(format) {
case FormatJSON, FormatCSV, FormatRSS:
case FormatJSON, FormatCSV, FormatRSS, FormatHTML:
// explicit format — use as-is
default:
// MVP: treat everything else as json, except `html` which we accept for compatibility.
if format == string(FormatHTML) {
// accepted, but not implemented by the server yet
// No format specified: default to HTML for browser requests, JSON for API clients.
accept := r.Header.Get("Accept")
if strings.Contains(accept, "text/html") {
format = string(FormatHTML)
} else {
format = string(FormatJSON)
}