1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-04-12 05:43:12 +00:00
mycorrhiza/web/search.go
2022-04-01 22:51:15 +03:00

37 lines
799 B
Go

package web
import (
"github.com/bouncepaw/mycorrhiza/viewutil"
"io"
"net/http"
"github.com/gorilla/mux"
"github.com/bouncepaw/mycorrhiza/l18n"
"github.com/bouncepaw/mycorrhiza/shroom"
"github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/views"
)
func initSearch(r *mux.Router) {
r.HandleFunc("/title-search/", handlerTitleSearch)
}
func handlerTitleSearch(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq)
_ = rq.ParseForm()
var (
query = rq.FormValue("q")
lc = l18n.FromRequest(rq)
)
w.WriteHeader(http.StatusOK)
_, _ = io.WriteString(
w,
views.Base(
viewutil.MetaFrom(w, rq),
lc.Get("ui.title_search_title", &l18n.Replacements{"query": query}),
views.TitleSearch(query, shroom.YieldHyphaNamesContainingString, lc),
),
)
}