2022-04-02 07:10:32 +00:00
|
|
|
package misc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2022-07-11 09:03:07 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
2022-04-02 07:10:32 +00:00
|
|
|
"github.com/bouncepaw/mycorrhiza/viewutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
//go:embed *html
|
2022-04-02 08:00:10 +00:00
|
|
|
fs embed.FS
|
|
|
|
chainList, chainTitleSearch viewutil.Chain
|
|
|
|
ruTranslation = `
|
2022-04-02 07:10:32 +00:00
|
|
|
{{define "list of hyphae"}}Список гиф{{end}}
|
2023-01-02 19:47:14 +00:00
|
|
|
{{define "search:"}}Поиск: {{.}}{{end}}
|
2022-04-02 08:00:10 +00:00
|
|
|
{{define "search results for"}}Результаты поиска для «{{.}}»{{end}}
|
2022-12-09 15:27:47 +00:00
|
|
|
{{define "search no results"}}Ничего не найдено.{{end}}
|
2022-07-11 09:03:07 +00:00
|
|
|
{{define "x total"}}{{.}} всего.{{end}}
|
2022-12-09 15:27:47 +00:00
|
|
|
{{define "go to hypha"}}Перейти к гифе <a class="wikilink{{if .HasExactMatch | not}} wikilink_new{{end}}" href="/hypha/{{.MatchedHyphaName}}">{{beautifulName .MatchedHyphaName}}</a>.{{end}}
|
2022-04-02 07:10:32 +00:00
|
|
|
`
|
|
|
|
)
|
|
|
|
|
|
|
|
func initViews() {
|
2022-05-18 16:58:24 +00:00
|
|
|
chainList = viewutil.CopyEnRuWith(fs, "view_list.html", ruTranslation)
|
|
|
|
chainTitleSearch = viewutil.CopyEnRuWith(fs, "view_title_search.html", ruTranslation)
|
2022-04-02 07:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type listDatum struct {
|
|
|
|
Name string
|
|
|
|
Ext string
|
|
|
|
}
|
|
|
|
|
|
|
|
type listData struct {
|
2022-05-18 16:46:01 +00:00
|
|
|
*viewutil.BaseData
|
2022-07-11 09:03:07 +00:00
|
|
|
Entries []listDatum
|
|
|
|
HyphaCount int
|
2022-04-02 07:10:32 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 16:46:01 +00:00
|
|
|
func viewList(meta viewutil.Meta, entries []listDatum) {
|
|
|
|
viewutil.ExecutePage(meta, chainList, listData{
|
2022-07-11 09:03:07 +00:00
|
|
|
BaseData: &viewutil.BaseData{},
|
|
|
|
Entries: entries,
|
|
|
|
HyphaCount: hyphae.Count(),
|
2022-05-18 16:46:01 +00:00
|
|
|
})
|
2022-04-02 07:10:32 +00:00
|
|
|
}
|
2022-04-02 08:00:10 +00:00
|
|
|
|
|
|
|
type titleSearchData struct {
|
2022-05-18 16:46:01 +00:00
|
|
|
*viewutil.BaseData
|
2022-12-09 15:27:47 +00:00
|
|
|
Query string
|
|
|
|
Results []string
|
|
|
|
MatchedHyphaName string
|
|
|
|
HasExactMatch bool
|
2022-04-02 08:00:10 +00:00
|
|
|
}
|
|
|
|
|
2022-12-09 15:27:47 +00:00
|
|
|
func viewTitleSearch(meta viewutil.Meta, query string, hyphaName string, hasExactMatch bool, results []string) {
|
2022-05-18 16:46:01 +00:00
|
|
|
viewutil.ExecutePage(meta, chainTitleSearch, titleSearchData{
|
2022-12-09 15:27:47 +00:00
|
|
|
BaseData: &viewutil.BaseData{},
|
|
|
|
Query: query,
|
|
|
|
Results: results,
|
|
|
|
MatchedHyphaName: hyphaName,
|
|
|
|
HasExactMatch: hasExactMatch,
|
2022-05-18 16:46:01 +00:00
|
|
|
})
|
2022-04-02 08:00:10 +00:00
|
|
|
}
|