diff --git a/categories/view_list.html b/categories/view_list.html index fdd21db..53754b3 100644 --- a/categories/view_list.html +++ b/categories/view_list.html @@ -1,4 +1,5 @@ -{{define "title"}}Category list{{end}} +{{define "category list"}}Category list{{end}} +{{define "title"}}{{template "category list"}}{{end}} {{define "body"}}

{{template "title"}}

diff --git a/categories/view_page.html b/categories/view_page.html index 569df58..a250d38 100644 --- a/categories/view_page.html +++ b/categories/view_page.html @@ -1,4 +1,5 @@ -{{define "title"}}Category {{.CatName | beautifulName}}{{end}} +{{define "category x"}}Category {{. | beautifulName}}{{end}} +{{define "title"}}{{template "category x" .CatName}}{{end}} {{define "body"}} {{$catName := .CatName}}
diff --git a/categories/views.go b/categories/views.go index dcb4609..87c6111 100644 --- a/categories/views.go +++ b/categories/views.go @@ -9,7 +9,7 @@ import ( "text/template" // TODO: Fight ) -const categoriesRu = ` +const ruTranslation = ` {{define "empty cat"}}Эта категория пуста.{{end}} {{define "add hypha"}}Добавить в категорию{{end}} {{define "cat"}}Категория{{end}} @@ -18,7 +18,7 @@ const categoriesRu = ` {{define "placeholder"}}Имя категории...{{end}} {{define "remove from category title"}}Убрать гифу из этой категории{{end}} {{define "add to category title"}}Добавить гифу в эту категорию{{end}} -{{define "category list heading"}}Список категорий{{end}} +{{define "category list"}}Список категорий{{end}} {{define "no categories"}}В этой вики нет категорий.{{end}} {{define "category x"}}Категория {{. | beautifulName}}{{end}} ` @@ -26,31 +26,29 @@ const categoriesRu = ` var ( //go:embed *.html fs embed.FS - m = template.Must - baseEn, baseRu *template.Template viewListChain, viewPageChain, viewCardChain viewutil.Chain ) func prepareViews() { - - baseEn = m(viewutil.BaseEn.Clone()) - baseRu = m(viewutil.BaseRu.Clone()) + var ( + m = template.Must + copyEnWith = func(f string) *template.Template { + return m(m(viewutil.BaseEn.Clone()).ParseFS(fs, f)) + } + copyRuWith = func(f string) *template.Template { + return m(m(viewutil.BaseRu.Clone()).ParseFS(fs, f)) + } + ) viewCardChain = viewutil. - En( - m(m(baseEn.Clone()).ParseFS(fs, "view_card.html"))). - Ru( - m(m(m(baseRu.Clone()).ParseFS(fs, "view_card.html")).Parse(categoriesRu))) + En(copyEnWith("view_card.html")). + Ru(m(copyRuWith("view_card.html").Parse(ruTranslation))) viewListChain = viewutil. - En( - m(m(baseEn.Clone()).ParseFS(fs, "view_list.html"))). - Ru( - m(m(m(baseRu.Clone()).ParseFS(fs, "view_list.html")).Parse(categoriesRu))) + En(copyEnWith("view_list.html")). + Ru(m(copyRuWith("view_list.html").Parse(ruTranslation))) viewPageChain = viewutil. - En( - m(m(baseEn.Clone()).ParseFS(fs, "view_page.html"))). - Ru( - m(m(m(baseRu.Clone()).ParseFS(fs, "view_page.html")).Parse(categoriesRu))) + En(copyEnWith("view_page.html")). + Ru(m(copyRuWith("view_page.html").Parse(ruTranslation))) } type cardData struct { @@ -59,6 +57,7 @@ type cardData struct { GivenPermissionToModify bool } +// CategoryCard is the little sidebar that is shown nearby the hypha view. func CategoryCard(meta viewutil.Meta, hyphaName string) string { var buf strings.Builder err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{