1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-05 17:40:26 +00:00

Misc: Port /list to the new approach

This commit is contained in:
Timur Ismagilov 2022-04-02 10:10:32 +03:00
parent f8fbc23202
commit 9eb92cfa6e
7 changed files with 235 additions and 298 deletions

View File

@ -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 {

View File

@ -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.

21
misc/view_list.html Normal file
View File

@ -0,0 +1,21 @@
{{define "list of hyphae"}}List of hyphae{{end}}
{{define "title"}}{{template "list of hyphae"}}{{end}}
{{define "body"}}
<div class="layout">
<main class="main-width">
<h1>{{template "list of hyphae"}}</h1>
<ol class="hypha-list">
{{range .Entries}}
<li class="hypha-list__entry">
<a class="hypha-list__link" href="/hypha/{{.Name}}">
{{beautifulName .Name}}
</a>
{{if .Ext}}
<span class="hypha-list__amnt-type">{{.Ext}}</span>
{{end}}
</li>
{{end}}
</ol>
</main>
</div>
{{end}}

69
misc/views.go Normal file
View File

@ -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)
}
}

View File

@ -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 @@
<p>{%s lc.Get("help.empty_error_line_2a") %} <a class="wikilink wikilink_external wikilink_https" href="https://github.com/bouncepaw/mycorrhiza">{%s lc.Get("help.empty_error_link") %}</a> {%s lc.Get("help.empty_error_line_2b") %}</p>
{% endfunc %}
{% func HyphaList(lc *l18n.Localizer) %}
<div class="layout">
<main class="main-width">
<h1>{%s lc.Get("ui.list_heading") %}</h1>
<p>{%s lc.GetPlural("ui.list_desc", hyphae.Count()) %}</p>
<ul class="hypha-list">
{% 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) %}
<li class="hypha-list__entry">
<a class="hypha-list__link" href="/hypha/{%s h.CanonicalName() %}">
{%s util.BeautifulName(h.CanonicalName()) %}
</a>
{% switch h := h.(type) %}
{% case *hyphae.MediaHypha %}
<span class="hypha-list__amnt-type">
{%s filepath.Ext(h.MediaFilePath())[1:] %}
</span>
{% endswitch %}
</li>
{% endfor %}
</ul>
</main>
</div>
{% endfunc %}
{% func commonScripts() %}
{% for _, scriptPath := range cfg.CommonScripts %}
<script src="{%s scriptPath %}"></script>

View File

@ -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(`
<div class="layout">
<main class="main-width title-search">
<h1>`)
//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(`</h1>
<p>`)
//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(`</p>
<ul class="title-search__results">
`)
//line views/stuff.qtpl:15
//line views/stuff.qtpl:13
for hyphaName := range generator(query) {
//line views/stuff.qtpl:15
//line views/stuff.qtpl:13
qw422016.N().S(`
<li class="title-search__entry">
<a class="title-search__link wikilink" href="/hypha/`)
//line views/stuff.qtpl:17
//line views/stuff.qtpl:15
qw422016.E().S(hyphaName)
//line views/stuff.qtpl:17
//line views/stuff.qtpl:15
qw422016.N().S(`">`)
//line views/stuff.qtpl:17
//line views/stuff.qtpl:15
qw422016.E().S(util.BeautifulName(hyphaName))
//line views/stuff.qtpl:17
//line views/stuff.qtpl:15
qw422016.N().S(`</a>
</li>
`)
//line views/stuff.qtpl:19
//line views/stuff.qtpl:17
}
//line views/stuff.qtpl:19
//line views/stuff.qtpl:17
qw422016.N().S(`
</main>
</div>
`)
//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(`
<div class="layout">
<main class="main-width backlinks">
<h1>`)
//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(`</h1>
<p>`)
//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(`</p>
<ul class="backlinks__list">
`)
//line views/stuff.qtpl:39
//line views/stuff.qtpl:37
for hyphaName := range generator(hyphaName) {
//line views/stuff.qtpl:39
//line views/stuff.qtpl:37
qw422016.N().S(`
<li class="backlinks__entry">
<a class="backlinks__link wikilink" href="/hypha/`)
//line views/stuff.qtpl:41
//line views/stuff.qtpl:39
qw422016.E().S(hyphaName)
//line views/stuff.qtpl:41
//line views/stuff.qtpl:39
qw422016.N().S(`">`)
//line views/stuff.qtpl:41
//line views/stuff.qtpl:39
qw422016.E().S(util.BeautifulName(hyphaName))
//line views/stuff.qtpl:41
//line views/stuff.qtpl:39
qw422016.N().S(`</a>
</li>
`)
//line views/stuff.qtpl:43
//line views/stuff.qtpl:41
}
//line views/stuff.qtpl:43
//line views/stuff.qtpl:41
qw422016.N().S(`
</ul>
</main>
</div>
`)
//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(`
<div class="layout">
<main class="main-width help">
<article>
`)
//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(`
</article>
</main>
`)
//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(`
</div>
`)
//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(`
<h1>`)
//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(`</h1>
<p>`)
//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(`</p>
<p>`)
//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(` <a class="wikilink wikilink_external wikilink_https" href="https://github.com/bouncepaw/mycorrhiza">`)
//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(`</a> `)
//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(`</p>
`)
//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(`
<div class="layout">
<main class="main-width">
<h1>`)
//line views/stuff.qtpl:69
qw422016.E().S(lc.Get("ui.list_heading"))
//line views/stuff.qtpl:69
qw422016.N().S(`</h1>
<p>`)
//line views/stuff.qtpl:70
qw422016.E().S(lc.GetPlural("ui.list_desc", hyphae.Count()))
//line views/stuff.qtpl:70
qw422016.N().S(`</p>
<ul class="hypha-list">
`)
//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(`
<li class="hypha-list__entry">
<a class="hypha-list__link" href="/hypha/`)
//line views/stuff.qtpl:83
qw422016.E().S(h.CanonicalName())
//line views/stuff.qtpl:83
qw422016.N().S(`">
`)
//line views/stuff.qtpl:84
qw422016.E().S(util.BeautifulName(h.CanonicalName()))
//line views/stuff.qtpl:84
qw422016.N().S(`
</a>
`)
//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(`
<span class="hypha-list__amnt-type">
`)
//line views/stuff.qtpl:89
qw422016.E().S(filepath.Ext(h.MediaFilePath())[1:])
//line views/stuff.qtpl:89
qw422016.N().S(`
</span>
`)
//line views/stuff.qtpl:91
}
//line views/stuff.qtpl:91
qw422016.N().S(`
</li>
`)
//line views/stuff.qtpl:93
}
//line views/stuff.qtpl:93
qw422016.N().S(`
</ul>
</main>
</div>
`)
//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(`
<script src="`)
//line views/stuff.qtpl:101
//line views/stuff.qtpl:66
qw422016.E().S(scriptPath)
//line views/stuff.qtpl:101
//line views/stuff.qtpl:66
qw422016.N().S(`"></script>
`)
//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
}

View File

@ -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))
}