feat: add source_url config option for footer source link
Thread source_url through: config.ServerConfig → Handler.sourceURL → PageData.SourceURL → template footer. Footer only shows Source link when source_url is set.
This commit is contained in:
parent
bb0b97820b
commit
805e7ffdc2
6 changed files with 18 additions and 9 deletions
|
|
@ -30,12 +30,14 @@ import (
|
|||
type Handler struct {
|
||||
searchSvc *search.Service
|
||||
autocompleteSvc func(ctx context.Context, query string) ([]string, error)
|
||||
sourceURL string
|
||||
}
|
||||
|
||||
func NewHandler(searchSvc *search.Service, autocompleteSuggestions func(ctx context.Context, query string) ([]string, error)) *Handler {
|
||||
func NewHandler(searchSvc *search.Service, autocompleteSuggestions func(ctx context.Context, query string) ([]string, error), sourceURL string) *Handler {
|
||||
return &Handler{
|
||||
searchSvc: searchSvc,
|
||||
autocompleteSvc: autocompleteSuggestions,
|
||||
sourceURL: sourceURL,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +53,7 @@ func (h *Handler) Index(w http.ResponseWriter, r *http.Request) {
|
|||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
if err := views.RenderIndex(w); err != nil {
|
||||
if err := views.RenderIndex(w, h.sourceURL); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
@ -80,7 +82,7 @@ func (h *Handler) Search(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
// For HTML, render error on the results page.
|
||||
if req.Format == contracts.FormatHTML || r.FormValue("format") == "html" {
|
||||
pd := views.PageData{Query: r.FormValue("q")}
|
||||
pd := views.PageData{SourceURL: h.sourceURL, Query: r.FormValue("q")}
|
||||
if views.IsHTMXRequest(r) {
|
||||
views.RenderSearchFragment(w, pd)
|
||||
} else {
|
||||
|
|
@ -95,7 +97,7 @@ func (h *Handler) Search(w http.ResponseWriter, r *http.Request) {
|
|||
resp, err := h.searchSvc.Search(r.Context(), req)
|
||||
if err != nil {
|
||||
if req.Format == contracts.FormatHTML {
|
||||
pd := views.PageData{Query: req.Query}
|
||||
pd := views.PageData{SourceURL: h.sourceURL, Query: req.Query}
|
||||
if views.IsHTMXRequest(r) {
|
||||
views.RenderSearchFragment(w, pd)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue