diff --git a/misc/handlers.go b/misc/handlers.go
index 629ce07..cdf81c1 100644
--- a/misc/handlers.go
+++ b/misc/handlers.go
@@ -34,6 +34,7 @@ func InitHandlers(rtr *mux.Router) {
rtr.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) {
http.Redirect(w, rq, "/static/favicon.ico", http.StatusSeeOther)
})
+ rtr.HandleFunc("/title-search/", handlerTitleSearch)
initViews()
}
@@ -142,3 +143,17 @@ func handlerRobotsTxt(w http.ResponseWriter, rq *http.Request) {
}
_ = file.Close()
}
+
+func handlerTitleSearch(w http.ResponseWriter, rq *http.Request) {
+ util.PrepareRq(rq)
+ _ = rq.ParseForm()
+ var (
+ query = rq.FormValue("q")
+ results []string
+ )
+ for hyphaName := range shroom.YieldHyphaNamesContainingString(query) {
+ results = append(results, hyphaName)
+ }
+ w.WriteHeader(http.StatusOK)
+ viewTitleSearch(viewutil.MetaFrom(w, rq), query, results)
+}
diff --git a/misc/view_title_search.html b/misc/view_title_search.html
new file mode 100644
index 0000000..0ce4872
--- /dev/null
+++ b/misc/view_title_search.html
@@ -0,0 +1,16 @@
+{{define "search:"}}Search: {{.}}{{end}}
+{{define "title"}}{{template "search:" .Query}}{{end}}
+{{define "body"}}
+
+ {{block "search results for" .Query}}Search results for ‘{{.}}’{{end}}
+ {{block "search desc" .}}Every hypha name has been compared with the query. Hyphae that have matched the query are listed below.{{end}}
+
+
+
+{{end}}
\ No newline at end of file
diff --git a/misc/views.go b/misc/views.go
index 870d8e3..e288067 100644
--- a/misc/views.go
+++ b/misc/views.go
@@ -12,10 +12,13 @@ import (
var (
//go:embed *html
- fs embed.FS
- chainList viewutil.Chain
- ruTranslation = `
+ fs embed.FS
+ chainList, chainTitleSearch viewutil.Chain
+ ruTranslation = `
{{define "list of hyphae"}}Список гиф{{end}}
+{{define "search:"}}Поиск:{{end}}
+{{define "search results for"}}Результаты поиска для «{{.}}»{{end}}
+{{define "search desc"}}Название каждой из существующих гиф сопоставлено с запросом. Подходящие гифы приведены ниже.{{end}}
`
)
@@ -24,6 +27,9 @@ func initViews() {
chainList = viewutil.
En(viewutil.CopyEnWith(fs, "view_list.html")).
Ru(m(viewutil.CopyRuWith(fs, "view_list.html").Parse(ruTranslation)))
+ chainTitleSearch = viewutil.
+ En(viewutil.CopyEnWith(fs, "view_title_search.html")).
+ Ru(m(viewutil.CopyRuWith(fs, "view_title_search.html").Parse(ruTranslation)))
}
type listDatum struct {
@@ -67,3 +73,23 @@ func viewList(meta viewutil.Meta) {
log.Println(err)
}
}
+
+type titleSearchData struct {
+ viewutil.BaseData
+ Query string
+ Results []string
+}
+
+func viewTitleSearch(meta viewutil.Meta, query string, results []string) {
+ if err := chainTitleSearch.Get(meta).ExecuteTemplate(meta.W, "page", titleSearchData{
+ BaseData: viewutil.BaseData{
+ Meta: meta,
+ HeaderLinks: cfg.HeaderLinks,
+ CommonScripts: cfg.CommonScripts,
+ },
+ Query: query,
+ Results: results,
+ }); err != nil {
+ log.Println(err)
+ }
+}
diff --git a/shroom/search.go b/shroom/search.go
index 6f6e902..4387abf 100644
--- a/shroom/search.go
+++ b/shroom/search.go
@@ -7,7 +7,7 @@ import (
"github.com/bouncepaw/mycorrhiza/util"
)
-// YieldHyphaNamesContainingString picks hyphae with have a string in their title, sorts and iterates over them.
+// YieldHyphaNamesContainingString picks hyphae with have a string in their title, sorts and iterates over them in alphabetical order.
func YieldHyphaNamesContainingString(query string) <-chan string {
query = util.CanonicalName(strings.TrimSpace(query))
out := make(chan string)
diff --git a/views/auth.qtpl b/views/auth.qtpl
index 619d2fd..fc94ec5 100644
--- a/views/auth.qtpl
+++ b/views/auth.qtpl
@@ -1,6 +1,8 @@
{% import "net/http" %}
+{% import "sort" %}
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
+{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% func Register(rq *http.Request) %}
{% code
@@ -148,3 +150,63 @@ Telegram auth widget was requested by Yogurt. As you can see, we don't offer use