1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Search: Add go to hypha section

This commit is contained in:
Timur Ismagilov 2022-12-09 18:27:47 +03:00
parent 2dab26dafa
commit b29042a52c
5 changed files with 24 additions and 14 deletions

View File

@ -124,8 +124,8 @@ var (
{{define "history of title"}}История «{{.}}»{{end}}
{{define "history of heading"}}История <a href="/hypha/{{.}}">{{beautifulName .}}</a>{{end}}
{{define "diff for at title"}}Разница для {{beautifulName .HyphaName}} для {{.Hash}}{{end}}
{{define "diff for at heading"}}Разница для <a href="/hypha/{{.HyphaName}}">{{beautifulName .HyphaName}}</a> для {{.Hash}}{{end}}
{{define "diff for at title"}}Разница для {{beautifulName .MatchedHyphaName}} для {{.Hash}}{{end}}
{{define "diff for at heading"}}Разница для <a href="/hypha/{{.MatchedHyphaName}}">{{beautifulName .MatchedHyphaName}}</a> для {{.Hash}}{{end}}
{{define "no text diff available"}}Нет текстовой разницы.{{end}}
{{define "count pre"}}Отобразить{{end}}

View File

@ -74,8 +74,8 @@ var (
{{define "leave redirection"}}Оставить перенаправление{{end}}
{{define "remove media from x?"}}Убрать медиа у {{beautifulName .}}?{{end}}
{{define "remove media from [[x]]?"}}Убрать медиа у <a href="/hypha/{{.HyphaName}}">{{beautifulName .HyphaName}}</a>?{{end}}
{{define "remove media for real?"}}Вы точно хотите убрать медиа у гифы «{{beautifulName .HyphaName}}»?{{end}}
{{define "remove media from [[x]]?"}}Убрать медиа у <a href="/hypha/{{.MatchedHyphaName}}">{{beautifulName .MatchedHyphaName}}</a>?{{end}}
{{define "remove media for real?"}}Вы точно хотите убрать медиа у гифы «{{beautifulName .MatchedHyphaName}}»?{{end}}
`
chainNaviTitle viewutil.Chain
chainEditHypha viewutil.Chain

View File

@ -172,12 +172,14 @@ func handlerTitleSearch(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq)
_ = rq.ParseForm()
var (
query = rq.FormValue("q")
results []string
query = rq.FormValue("q")
hyphaName = util.CanonicalName(query)
_, nameFree = hyphae.AreFreeNames(hyphaName)
results []string
)
for hyphaName := range shroom.YieldHyphaNamesContainingString(query) {
results = append(results, hyphaName)
}
w.WriteHeader(http.StatusOK)
viewTitleSearch(viewutil.MetaFrom(w, rq), query, results)
viewTitleSearch(viewutil.MetaFrom(w, rq), query, hyphaName, !nameFree, results)
}

View File

@ -3,6 +3,9 @@
{{define "body"}}
<main class="main-width">
<h1>{{block "search results for" .Query}}Search results for {{.}}{{end}}</h1>
{{if .MatchedHyphaName}}
<p>{{block "go to hypha" .}}Go to hypha <a class="wikilink{{if .HasExactMatch | not}} wikilink_new{{end}}" href="/hypha/{{.MatchedHyphaName}}">{{beautifulName .MatchedHyphaName}}</a>.{{end}}</p>
{{end}}
{{if len .Results}}
<p>{{block "search desc" .}}Every hypha name has been compared with the query. Hyphae that have matched the query are listed below.{{end}}</p>
<ol>

View File

@ -15,8 +15,9 @@ var (
{{define "search:"}}Поиск:{{end}}
{{define "search results for"}}Результаты поиска для «{{.}}»{{end}}
{{define "search desc"}}Название каждой из существующих гиф сопоставлено с запросом. Подходящие гифы приведены ниже.{{end}}
{{define "search no results"}}Ничего не найдено{{end}}
{{define "search no results"}}Ничего не найдено.{{end}}
{{define "x total"}}{{.}} всего.{{end}}
{{define "go to hypha"}}Перейти к гифе <a class="wikilink{{if .HasExactMatch | not}} wikilink_new{{end}}" href="/hypha/{{.MatchedHyphaName}}">{{beautifulName .MatchedHyphaName}}</a>.{{end}}
`
)
@ -46,14 +47,18 @@ func viewList(meta viewutil.Meta, entries []listDatum) {
type titleSearchData struct {
*viewutil.BaseData
Query string
Results []string
Query string
Results []string
MatchedHyphaName string
HasExactMatch bool
}
func viewTitleSearch(meta viewutil.Meta, query string, results []string) {
func viewTitleSearch(meta viewutil.Meta, query string, hyphaName string, hasExactMatch bool, results []string) {
viewutil.ExecutePage(meta, chainTitleSearch, titleSearchData{
BaseData: &viewutil.BaseData{},
Query: query,
Results: results,
BaseData: &viewutil.BaseData{},
Query: query,
Results: results,
MatchedHyphaName: hyphaName,
HasExactMatch: hasExactMatch,
})
}