1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-08-09 23:33:46 +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 title"}}История «{{.}}»{{end}}
{{define "history of heading"}}История <a href="/hypha/{{.}}">{{beautifulName .}}</a>{{end}} {{define "history of heading"}}История <a href="/hypha/{{.}}">{{beautifulName .}}</a>{{end}}
{{define "diff for at title"}}Разница для {{beautifulName .HyphaName}} для {{.Hash}}{{end}} {{define "diff for at title"}}Разница для {{beautifulName .MatchedHyphaName}} для {{.Hash}}{{end}}
{{define "diff for at heading"}}Разница для <a href="/hypha/{{.HyphaName}}">{{beautifulName .HyphaName}}</a> для {{.Hash}}{{end}} {{define "diff for at heading"}}Разница для <a href="/hypha/{{.MatchedHyphaName}}">{{beautifulName .MatchedHyphaName}}</a> для {{.Hash}}{{end}}
{{define "no text diff available"}}Нет текстовой разницы.{{end}} {{define "no text diff available"}}Нет текстовой разницы.{{end}}
{{define "count pre"}}Отобразить{{end}} {{define "count pre"}}Отобразить{{end}}

View File

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

View File

@ -172,12 +172,14 @@ func handlerTitleSearch(w http.ResponseWriter, rq *http.Request) {
util.PrepareRq(rq) util.PrepareRq(rq)
_ = rq.ParseForm() _ = rq.ParseForm()
var ( var (
query = rq.FormValue("q") query = rq.FormValue("q")
results []string hyphaName = util.CanonicalName(query)
_, nameFree = hyphae.AreFreeNames(hyphaName)
results []string
) )
for hyphaName := range shroom.YieldHyphaNamesContainingString(query) { for hyphaName := range shroom.YieldHyphaNamesContainingString(query) {
results = append(results, hyphaName) results = append(results, hyphaName)
} }
w.WriteHeader(http.StatusOK) 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"}} {{define "body"}}
<main class="main-width"> <main class="main-width">
<h1>{{block "search results for" .Query}}Search results for {{.}}{{end}}</h1> <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}} {{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> <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> <ol>

View File

@ -15,8 +15,9 @@ var (
{{define "search:"}}Поиск:{{end}} {{define "search:"}}Поиск:{{end}}
{{define "search results for"}}Результаты поиска для «{{.}}»{{end}} {{define "search results for"}}Результаты поиска для «{{.}}»{{end}}
{{define "search desc"}}Название каждой из существующих гиф сопоставлено с запросом. Подходящие гифы приведены ниже.{{end}} {{define "search desc"}}Название каждой из существующих гиф сопоставлено с запросом. Подходящие гифы приведены ниже.{{end}}
{{define "search no results"}}Ничего не найдено{{end}} {{define "search no results"}}Ничего не найдено.{{end}}
{{define "x total"}}{{.}} всего.{{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 { type titleSearchData struct {
*viewutil.BaseData *viewutil.BaseData
Query string Query string
Results []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{ viewutil.ExecutePage(meta, chainTitleSearch, titleSearchData{
BaseData: &viewutil.BaseData{}, BaseData: &viewutil.BaseData{},
Query: query, Query: query,
Results: results, Results: results,
MatchedHyphaName: hyphaName,
HasExactMatch: hasExactMatch,
}) })
} }