1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00
mycorrhiza/web/search.go
Timur Ismagilov b4c4b3fbf0 API: Get rid of *-json URLs
I doubt anybody really used the two. They will make a comeback later.
2022-03-21 00:10:09 +03:00

39 lines
818 B
Go

package web
import (
"io"
"net/http"
"github.com/gorilla/mux"
"github.com/bouncepaw/mycorrhiza/l18n"
"github.com/bouncepaw/mycorrhiza/shroom"
"github.com/bouncepaw/mycorrhiza/user"
"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")
u = user.FromRequest(rq)
lc = l18n.FromRequest(rq)
)
w.WriteHeader(http.StatusOK)
_, _ = io.WriteString(
w,
views.BaseHTML(
lc.Get("ui.title_search_title", &l18n.Replacements{"query": query}),
views.TitleSearchHTML(query, shroom.YieldHyphaNamesContainingString, lc),
lc,
u,
),
)
}