/
views.go
63 lines (55 loc) · 1.75 KB
/
views.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package misc
import (
"embed"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/viewutil"
)
var (
//go:embed *html
fs embed.FS
chainList, chainTitleSearch viewutil.Chain
ruTranslation = `
{{define "list of hyphae"}}Список гиф{{end}}
{{define "search:"}}Поиск: {{.}}{{end}}
{{define "search results for"}}Результаты поиска для «{{.}}»{{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}}
`
)
func initViews() {
chainList = viewutil.CopyEnRuWith(fs, "view_list.html", ruTranslation)
chainTitleSearch = viewutil.CopyEnRuWith(fs, "view_title_search.html", ruTranslation)
}
type listDatum struct {
Name string
Ext string
}
type listData struct {
*viewutil.BaseData
Entries []listDatum
HyphaCount int
}
func viewList(meta viewutil.Meta, entries []listDatum) {
viewutil.ExecutePage(meta, chainList, listData{
BaseData: &viewutil.BaseData{},
Entries: entries,
HyphaCount: hyphae.Count(),
})
}
type titleSearchData struct {
*viewutil.BaseData
Query string
Results []string
MatchedHyphaName string
HasExactMatch bool
}
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,
MatchedHyphaName: hyphaName,
HasExactMatch: hasExactMatch,
})
}