mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-12-01 22:28:05 +00:00
Reimplement empty hypha notice with go templates
This commit is contained in:
@@ -2,7 +2,6 @@ package hypview
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||
"log"
|
||||
@@ -12,15 +11,49 @@ import (
|
||||
|
||||
var (
|
||||
//go:embed *.html
|
||||
fs embed.FS
|
||||
ruTranslation = ``
|
||||
chainNaviTitle viewutil.Chain
|
||||
fs embed.FS
|
||||
ruTranslation = `
|
||||
{{define "empty heading"}}Эта гифа не существует{{end}}
|
||||
{{define "empty no rights"}}У вас нет прав для создания новых гиф. Вы можете:{{end}}
|
||||
{{define "empty log in"}}Войти в свою учётную запись, если она у вас есть{{end}}
|
||||
{{define "empty register"}}Создать новую учётную запись{{end}}
|
||||
{{define "write a text"}}Написать текст{{end}}
|
||||
{{define "write a text tip"}}Напишите заметку, дневник, статью, рассказ или иной текст с помощью <a href="/help/en/mycomarkup" class="shy-link">микоразметки</a>. Сохраняется полная история правок документа.{{end}}
|
||||
{{define "write a text writing conventions"}}Не забывайте следовать правилам оформления этой вики, если они имеются.{{end}}
|
||||
{{define "write a text btn"}}Создать{{end}}
|
||||
{{define "upload a media"}}Загрузить медиа{{end}}
|
||||
{{define "upload a media tip"}}Загрузите изображение, видео или аудио. Распространённые форматы можно просматривать из браузера, остальные – просто скачать. Позже вы можете дописать пояснение к этому медиа.{{end}}
|
||||
{{define "upload a media btn"}}Загрузить{{end}}
|
||||
`
|
||||
chainNaviTitle viewutil.Chain
|
||||
chainEmptyHypha viewutil.Chain
|
||||
)
|
||||
|
||||
func Init() {
|
||||
chainNaviTitle = viewutil.
|
||||
En(viewutil.CopyEnWith(fs, "view_navititle.html")).
|
||||
Ru(template.Must(viewutil.CopyRuWith(fs, "view_navititle.html").Parse(ruTranslation)))
|
||||
Ru(viewutil.CopyRuWith(fs, "view_navititle.html")) // no text inside
|
||||
chainEmptyHypha = viewutil.
|
||||
En(viewutil.CopyEnWith(fs, "view_empty_hypha.html")).
|
||||
Ru(template.Must(viewutil.CopyRuWith(fs, "view_empty_hypha.html").Parse(ruTranslation)))
|
||||
}
|
||||
|
||||
type emptyHyphaData struct {
|
||||
HyphaName string
|
||||
AllowRegistration bool
|
||||
UseAuth bool
|
||||
}
|
||||
|
||||
func EmptyHypha(meta viewutil.Meta, hyphaName string) string {
|
||||
var buf strings.Builder
|
||||
if err := chainEmptyHypha.Get(meta).ExecuteTemplate(&buf, "empty hypha card", emptyHyphaData{
|
||||
HyphaName: hyphaName,
|
||||
AllowRegistration: cfg.AllowRegistration,
|
||||
UseAuth: cfg.UseAuth,
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type naviTitleData struct {
|
||||
@@ -57,6 +90,5 @@ func naviTitleify(hyphaName string) ([]string, []string) {
|
||||
partsWithParents = append(partsWithParents, prevAcc)
|
||||
}
|
||||
|
||||
fmt.Printf("%q — %q\n", parts, partsWithParents)
|
||||
return parts, partsWithParents
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user