From 9eb92cfa6e86861d586ba846c42e1fb81eacf8c4 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sat, 2 Apr 2022 10:10:32 +0300 Subject: [PATCH] Misc: Port /list to the new approach --- categories/views.go | 22 +- misc/{misc.go => handlers.go} | 8 +- misc/view_list.html | 21 ++ misc/views.go | 69 +++++++ views/stuff.qtpl | 35 ---- views/stuff.qtpl.go | 365 ++++++++++++---------------------- viewutil/viewutil.go | 13 +- 7 files changed, 235 insertions(+), 298 deletions(-) rename misc/{misc.go => handlers.go} (95%) create mode 100644 misc/view_list.html create mode 100644 misc/views.go diff --git a/categories/views.go b/categories/views.go index 87c6111..3401f2d 100644 --- a/categories/views.go +++ b/categories/views.go @@ -30,25 +30,17 @@ var ( ) func prepareViews() { - 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)) - } - ) + m := template.Must viewCardChain = viewutil. - En(copyEnWith("view_card.html")). - Ru(m(copyRuWith("view_card.html").Parse(ruTranslation))) + En(viewutil.CopyEnWith(fs, "view_card.html")). + Ru(m(viewutil.CopyRuWith(fs, "view_card.html").Parse(ruTranslation))) viewListChain = viewutil. - En(copyEnWith("view_list.html")). - Ru(m(copyRuWith("view_list.html").Parse(ruTranslation))) + En(viewutil.CopyEnWith(fs, "view_list.html")). + Ru(m(viewutil.CopyRuWith(fs, "view_list.html").Parse(ruTranslation))) viewPageChain = viewutil. - En(copyEnWith("view_page.html")). - Ru(m(copyRuWith("view_page.html").Parse(ruTranslation))) + En(viewutil.CopyEnWith(fs, "view_page.html")). + Ru(m(viewutil.CopyRuWith(fs, "view_page.html").Parse(ruTranslation))) } type cardData struct { diff --git a/misc/misc.go b/misc/handlers.go similarity index 95% rename from misc/misc.go rename to misc/handlers.go index 2f9b44e..ea96760 100644 --- a/misc/misc.go +++ b/misc/handlers.go @@ -28,17 +28,13 @@ func InitHandlers(rtr *mux.Router) { rtr.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) { http.Redirect(w, rq, "/static/favicon.ico", http.StatusSeeOther) }) + initViews() } // handlerList shows a list of all hyphae in the wiki in random order. func handlerList(w http.ResponseWriter, rq *http.Request) { - var lc = l18n.FromRequest(rq) util.PrepareRq(rq) - util.HTTP200Page(w, views.Base( - viewutil.MetaFrom(w, rq), - lc.Get("ui.list_title"), - views.HyphaList(lc), - )) + viewList(viewutil.MetaFrom(w, rq)) } // handlerReindex reindexes all hyphae by checking the wiki storage directory anew. diff --git a/misc/view_list.html b/misc/view_list.html new file mode 100644 index 0000000..0b99b5b --- /dev/null +++ b/misc/view_list.html @@ -0,0 +1,21 @@ +{{define "list of hyphae"}}List of hyphae{{end}} +{{define "title"}}{{template "list of hyphae"}}{{end}} +{{define "body"}} +
+
+

{{template "list of hyphae"}}

+
    + {{range .Entries}} +
  1. + + {{beautifulName .Name}} + + {{if .Ext}} + {{.Ext}} + {{end}} +
  2. + {{end}} +
+
+
+{{end}} \ No newline at end of file diff --git a/misc/views.go b/misc/views.go new file mode 100644 index 0000000..79f5242 --- /dev/null +++ b/misc/views.go @@ -0,0 +1,69 @@ +package misc + +import ( + "embed" + "github.com/bouncepaw/mycorrhiza/cfg" + "github.com/bouncepaw/mycorrhiza/hyphae" + "github.com/bouncepaw/mycorrhiza/viewutil" + "log" + "path/filepath" + "text/template" +) + +var ( + //go:embed *html + fs embed.FS + chainList viewutil.Chain + ruTranslation = ` +{{define "list of hyphae"}}Список гиф{{end}} +` +) + +func initViews() { + m := template.Must + chainList = viewutil. + En(viewutil.CopyEnWith(fs, "view_list.html")). + Ru(m(viewutil.CopyRuWith(fs, "view_list.html").Parse(ruTranslation))) +} + +type listDatum struct { + Name string + Ext string +} + +type listData struct { + viewutil.BaseData + Entries []listDatum +} + +func viewList(meta viewutil.Meta) { + // TODO: make this better, there are too many loops and vars + var ( + hyphaNames = make(chan string) + sortedHypha = hyphae.PathographicSort(hyphaNames) + data []listDatum + ) + for hypha := range hyphae.YieldExistingHyphae() { + hyphaNames <- hypha.CanonicalName() + } + close(hyphaNames) + for hyphaName := range sortedHypha { + switch h := hyphae.ByName(hyphaName).(type) { + case *hyphae.TextualHypha: + data = append(data, listDatum{h.CanonicalName(), ""}) + case *hyphae.MediaHypha: + data = append(data, listDatum{h.CanonicalName(), filepath.Ext(h.MediaFilePath())[1:]}) + } + } + + if err := chainList.Get(meta).ExecuteTemplate(meta.W, "page", listData{ + BaseData: viewutil.BaseData{ + Meta: meta, + HeaderLinks: cfg.HeaderLinks, + CommonScripts: cfg.CommonScripts, + }, + Entries: data, + }); err != nil { + log.Println(err) + } +} diff --git a/views/stuff.qtpl b/views/stuff.qtpl index 9536c04..37151c4 100644 --- a/views/stuff.qtpl +++ b/views/stuff.qtpl @@ -1,8 +1,6 @@ {% import "fmt" %} -{% import "path/filepath" %} {% import "github.com/bouncepaw/mycorrhiza/cfg" %} -{% import "github.com/bouncepaw/mycorrhiza/hyphae" %} {% import "github.com/bouncepaw/mycorrhiza/util" %} {% import "github.com/bouncepaw/mycorrhiza/l18n" %} @@ -63,39 +61,6 @@

{%s lc.Get("help.empty_error_line_2a") %} {%s lc.Get("help.empty_error_link") %} {%s lc.Get("help.empty_error_line_2b") %}

{% endfunc %} -{% func HyphaList(lc *l18n.Localizer) %} -
-
-

{%s lc.Get("ui.list_heading") %}

-

{%s lc.GetPlural("ui.list_desc", hyphae.Count()) %}

-
    - {% code - hyphaNames := make(chan string) - sortedHypha := hyphae.PathographicSort(hyphaNames) - for hypha := range hyphae.YieldExistingHyphae() { - hyphaNames <- hypha.CanonicalName() - } - close(hyphaNames) - %} - {% for hyphaName := range sortedHypha %} - {% code h := hyphae.ByName(hyphaName) %} -
  • - - {%s util.BeautifulName(h.CanonicalName()) %} - - {% switch h := h.(type) %} - {% case *hyphae.MediaHypha %} - - {%s filepath.Ext(h.MediaFilePath())[1:] %} - - {% endswitch %} -
  • - {% endfor %} -
-
-
-{% endfunc %} - {% func commonScripts() %} {% for _, scriptPath := range cfg.CommonScripts %} diff --git a/views/stuff.qtpl.go b/views/stuff.qtpl.go index 043876f..31ae9ff 100644 --- a/views/stuff.qtpl.go +++ b/views/stuff.qtpl.go @@ -7,112 +7,106 @@ package views //line views/stuff.qtpl:1 import "fmt" -//line views/stuff.qtpl:2 -import "path/filepath" - -//line views/stuff.qtpl:4 +//line views/stuff.qtpl:3 import "github.com/bouncepaw/mycorrhiza/cfg" -//line views/stuff.qtpl:5 -import "github.com/bouncepaw/mycorrhiza/hyphae" - -//line views/stuff.qtpl:6 +//line views/stuff.qtpl:4 import "github.com/bouncepaw/mycorrhiza/util" -//line views/stuff.qtpl:7 +//line views/stuff.qtpl:5 import "github.com/bouncepaw/mycorrhiza/l18n" -//line views/stuff.qtpl:9 +//line views/stuff.qtpl:7 import ( qtio422016 "io" qt422016 "github.com/valyala/quicktemplate" ) -//line views/stuff.qtpl:9 +//line views/stuff.qtpl:7 var ( _ = qtio422016.Copy _ = qt422016.AcquireByteBuffer ) -//line views/stuff.qtpl:9 +//line views/stuff.qtpl:7 func StreamTitleSearch(qw422016 *qt422016.Writer, query string, generator func(string) <-chan string, lc *l18n.Localizer) { -//line views/stuff.qtpl:9 +//line views/stuff.qtpl:7 qw422016.N().S(`

`) -//line views/stuff.qtpl:12 +//line views/stuff.qtpl:10 qw422016.E().S(lc.Get("ui.search_results_query", &l18n.Replacements{"query": query})) -//line views/stuff.qtpl:12 +//line views/stuff.qtpl:10 qw422016.N().S(`

`) -//line views/stuff.qtpl:13 +//line views/stuff.qtpl:11 qw422016.E().S(lc.Get("ui.search_results_desc")) -//line views/stuff.qtpl:13 +//line views/stuff.qtpl:11 qw422016.N().S(`

`) -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 } -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 func WriteTitleSearch(qq422016 qtio422016.Writer, query string, generator func(string) <-chan string, lc *l18n.Localizer) { -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 StreamTitleSearch(qw422016, query, generator, lc) -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 } -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 func TitleSearch(query string, generator func(string) <-chan string, lc *l18n.Localizer) string { -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 WriteTitleSearch(qb422016, query, generator, lc) -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 return qs422016 -//line views/stuff.qtpl:22 +//line views/stuff.qtpl:20 } -//line views/stuff.qtpl:24 +//line views/stuff.qtpl:22 func StreamBacklinks(qw422016 *qt422016.Writer, hyphaName string, generator func(string) <-chan string, lc *l18n.Localizer) { -//line views/stuff.qtpl:24 +//line views/stuff.qtpl:22 qw422016.N().S(`

`) -//line views/stuff.qtpl:27 +//line views/stuff.qtpl:25 qw422016.N().S(lc.Get( "ui.backlinks_heading", &l18n.Replacements{ @@ -123,329 +117,220 @@ func StreamBacklinks(qw422016 *qt422016.Writer, hyphaName string, generator func ), }, )) -//line views/stuff.qtpl:36 +//line views/stuff.qtpl:34 qw422016.N().S(`

`) -//line views/stuff.qtpl:37 +//line views/stuff.qtpl:35 qw422016.E().S(lc.Get("ui.backlinks_desc")) -//line views/stuff.qtpl:37 +//line views/stuff.qtpl:35 qw422016.N().S(`

`) -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 } -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 func WriteBacklinks(qq422016 qtio422016.Writer, hyphaName string, generator func(string) <-chan string, lc *l18n.Localizer) { -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 StreamBacklinks(qw422016, hyphaName, generator, lc) -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 } -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 func Backlinks(hyphaName string, generator func(string) <-chan string, lc *l18n.Localizer) string { -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 WriteBacklinks(qb422016, hyphaName, generator, lc) -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 return qs422016 -//line views/stuff.qtpl:47 +//line views/stuff.qtpl:45 } -//line views/stuff.qtpl:49 +//line views/stuff.qtpl:47 func StreamHelp(qw422016 *qt422016.Writer, content, lang string, lc *l18n.Localizer) { -//line views/stuff.qtpl:49 +//line views/stuff.qtpl:47 qw422016.N().S(`
`) -//line views/stuff.qtpl:53 +//line views/stuff.qtpl:51 qw422016.N().S(content) -//line views/stuff.qtpl:53 +//line views/stuff.qtpl:51 qw422016.N().S(`
`) -//line views/stuff.qtpl:56 +//line views/stuff.qtpl:54 qw422016.N().S(helpTopics(lang, lc)) -//line views/stuff.qtpl:56 +//line views/stuff.qtpl:54 qw422016.N().S(`
`) -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 } -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 func WriteHelp(qq422016 qtio422016.Writer, content, lang string, lc *l18n.Localizer) { -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 StreamHelp(qw422016, content, lang, lc) -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 } -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 func Help(content, lang string, lc *l18n.Localizer) string { -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 WriteHelp(qb422016, content, lang, lc) -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 return qs422016 -//line views/stuff.qtpl:58 +//line views/stuff.qtpl:56 } -//line views/stuff.qtpl:60 +//line views/stuff.qtpl:58 func StreamHelpEmptyError(qw422016 *qt422016.Writer, lc *l18n.Localizer) { -//line views/stuff.qtpl:60 +//line views/stuff.qtpl:58 qw422016.N().S(`

`) -//line views/stuff.qtpl:61 +//line views/stuff.qtpl:59 qw422016.E().S(lc.Get("help.empty_error_title")) -//line views/stuff.qtpl:61 +//line views/stuff.qtpl:59 qw422016.N().S(`

`) -//line views/stuff.qtpl:62 +//line views/stuff.qtpl:60 qw422016.E().S(lc.Get("help.empty_error_line_1")) -//line views/stuff.qtpl:62 +//line views/stuff.qtpl:60 qw422016.N().S(`

`) -//line views/stuff.qtpl:63 +//line views/stuff.qtpl:61 qw422016.E().S(lc.Get("help.empty_error_line_2a")) -//line views/stuff.qtpl:63 +//line views/stuff.qtpl:61 qw422016.N().S(` `) -//line views/stuff.qtpl:63 +//line views/stuff.qtpl:61 qw422016.E().S(lc.Get("help.empty_error_link")) -//line views/stuff.qtpl:63 +//line views/stuff.qtpl:61 qw422016.N().S(` `) -//line views/stuff.qtpl:63 +//line views/stuff.qtpl:61 qw422016.E().S(lc.Get("help.empty_error_line_2b")) -//line views/stuff.qtpl:63 +//line views/stuff.qtpl:61 qw422016.N().S(`

`) -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 } -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 func WriteHelpEmptyError(qq422016 qtio422016.Writer, lc *l18n.Localizer) { -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 StreamHelpEmptyError(qw422016, lc) -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 } -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 func HelpEmptyError(lc *l18n.Localizer) string { -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 WriteHelpEmptyError(qb422016, lc) -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:64 +//line views/stuff.qtpl:62 return qs422016 +//line views/stuff.qtpl:62 +} + //line views/stuff.qtpl:64 -} - -//line views/stuff.qtpl:66 -func StreamHyphaList(qw422016 *qt422016.Writer, lc *l18n.Localizer) { -//line views/stuff.qtpl:66 - qw422016.N().S(` -
-
-

`) -//line views/stuff.qtpl:69 - qw422016.E().S(lc.Get("ui.list_heading")) -//line views/stuff.qtpl:69 - qw422016.N().S(`

-

`) -//line views/stuff.qtpl:70 - qw422016.E().S(lc.GetPlural("ui.list_desc", hyphae.Count())) -//line views/stuff.qtpl:70 - qw422016.N().S(`

-
    - `) -//line views/stuff.qtpl:73 - hyphaNames := make(chan string) - sortedHypha := hyphae.PathographicSort(hyphaNames) - for hypha := range hyphae.YieldExistingHyphae() { - hyphaNames <- hypha.CanonicalName() - } - close(hyphaNames) - -//line views/stuff.qtpl:79 - qw422016.N().S(` - `) -//line views/stuff.qtpl:80 - for hyphaName := range sortedHypha { -//line views/stuff.qtpl:80 - qw422016.N().S(` - `) -//line views/stuff.qtpl:81 - h := hyphae.ByName(hyphaName) - -//line views/stuff.qtpl:81 - qw422016.N().S(` -
  • - - `) -//line views/stuff.qtpl:84 - qw422016.E().S(util.BeautifulName(h.CanonicalName())) -//line views/stuff.qtpl:84 - qw422016.N().S(` - - `) -//line views/stuff.qtpl:86 - switch h := h.(type) { -//line views/stuff.qtpl:87 - case *hyphae.MediaHypha: -//line views/stuff.qtpl:87 - qw422016.N().S(` - - `) -//line views/stuff.qtpl:89 - qw422016.E().S(filepath.Ext(h.MediaFilePath())[1:]) -//line views/stuff.qtpl:89 - qw422016.N().S(` - - `) -//line views/stuff.qtpl:91 - } -//line views/stuff.qtpl:91 - qw422016.N().S(` -
  • - `) -//line views/stuff.qtpl:93 - } -//line views/stuff.qtpl:93 - qw422016.N().S(` -
-
-
-`) -//line views/stuff.qtpl:97 -} - -//line views/stuff.qtpl:97 -func WriteHyphaList(qq422016 qtio422016.Writer, lc *l18n.Localizer) { -//line views/stuff.qtpl:97 - qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:97 - StreamHyphaList(qw422016, lc) -//line views/stuff.qtpl:97 - qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:97 -} - -//line views/stuff.qtpl:97 -func HyphaList(lc *l18n.Localizer) string { -//line views/stuff.qtpl:97 - qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:97 - WriteHyphaList(qb422016, lc) -//line views/stuff.qtpl:97 - qs422016 := string(qb422016.B) -//line views/stuff.qtpl:97 - qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:97 - return qs422016 -//line views/stuff.qtpl:97 -} - -//line views/stuff.qtpl:99 func streamcommonScripts(qw422016 *qt422016.Writer) { -//line views/stuff.qtpl:99 +//line views/stuff.qtpl:64 qw422016.N().S(` `) -//line views/stuff.qtpl:100 +//line views/stuff.qtpl:65 for _, scriptPath := range cfg.CommonScripts { -//line views/stuff.qtpl:100 +//line views/stuff.qtpl:65 qw422016.N().S(` `) -//line views/stuff.qtpl:102 +//line views/stuff.qtpl:67 } -//line views/stuff.qtpl:102 +//line views/stuff.qtpl:67 qw422016.N().S(` `) -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 } -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 func writecommonScripts(qq422016 qtio422016.Writer) { -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 streamcommonScripts(qw422016) -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 qt422016.ReleaseWriter(qw422016) -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 } -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 func commonScripts() string { -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 qb422016 := qt422016.AcquireByteBuffer() -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 writecommonScripts(qb422016) -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 qs422016 := string(qb422016.B) -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 qt422016.ReleaseByteBuffer(qb422016) -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 return qs422016 -//line views/stuff.qtpl:103 +//line views/stuff.qtpl:68 } diff --git a/viewutil/viewutil.go b/viewutil/viewutil.go index af37550..6fd71e6 100644 --- a/viewutil/viewutil.go +++ b/viewutil/viewutil.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/util" + "io/fs" "log" "strings" "text/template" // TODO: save the world @@ -13,7 +14,7 @@ import ( var ( //go:embed *.html - fs embed.FS + fsys embed.FS BaseEn *template.Template BaseRu *template.Template m = template.Must @@ -33,7 +34,7 @@ func Init() { BaseEn = m(m(template.New(""). Funcs(template.FuncMap{ "beautifulName": util.BeautifulName, - }).ParseFS(fs, "base.html")). + }).ParseFS(fsys, "base.html")). Parse(dataText)) if !cfg.UseAuth { m(BaseEn.Parse(`{{define "auth"}}{{end}}`)) @@ -85,3 +86,11 @@ func Base(meta Meta, title, body string, headElements ...string) string { } return w.String() } + +func CopyEnWith(fsys fs.FS, f string) *template.Template { + return m(m(BaseEn.Clone()).ParseFS(fsys, f)) +} + +func CopyRuWith(fsys fs.FS, f string) *template.Template { + return m(m(BaseRu.Clone()).ParseFS(fsys, f)) +}