1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 14:00:25 +00:00
mycorrhiza/misc/views.go

64 lines
1.8 KiB
Go
Raw Normal View History

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
fs embed.FS
chainList, chainTitleSearch viewutil.Chain
ruTranslation = `
2022-04-02 07:10:32 +00:00
{{define "list of hyphae"}}Список гиф{{end}}
{{define "search:"}}Поиск: {{.}}{{end}}
{{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() {
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 {
*viewutil.BaseData
2022-07-11 09:03:07 +00:00
Entries []listDatum
HyphaCount int
2022-04-02 07:10:32 +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-04-02 07:10:32 +00:00
}
type titleSearchData struct {
*viewutil.BaseData
2022-12-09 15:27:47 +00:00
Query string
Results []string
MatchedHyphaName string
HasExactMatch bool
}
2022-12-09 15:27:47 +00:00
func viewTitleSearch(meta viewutil.Meta, query string, hyphaName string, hasExactMatch bool, results []string) {
viewutil.ExecutePage(meta, chainTitleSearch, titleSearchData{
2022-12-09 15:27:47 +00:00
BaseData: &viewutil.BaseData{},
Query: query,
Results: results,
MatchedHyphaName: hyphaName,
HasExactMatch: hasExactMatch,
})
}