1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-03-11 14:08:20 +00:00
mycorrhiza/misc/about.go
Timur Ismagilov 41733c50bd
New templates #117 (#236)
Didn't have the chance to migrate //all// templates just yet. We'll get there.

* Implement yet another template system

* Move orphans to the new system and fix a bug in it

* Link orphans in the admin panel

* Move the backlink handlers to the web package

* Move auth routing to web

* Move /user-list to the new system

* Move change password and translate it

* Move stuff

* Move admin-related stuff to the web

* Move a lot of files into internal dir

Outside of it are web and stuff that needs further refactoring

* Fix static not loading and de-qtpl tree

* Move tree to internal

* Keep the globe on the same line #230

* Revert "Keep the globe on the same line #230"

This reverts commit ae78e5e459b1e980ba89bf29e61f75c0625ed2c7.

* Migrate templates from hypview: delete, edit, start empty and existing WIP

The delete media view was removed, I didn't even know it still existed as a GET. A rudiment.

* Make views multi-file and break compilation

* Megarefactoring of hypha views

* Auth-related stuffs

* Fix some of those weird imports

* Migrate cat views

* Fix cat js

* Lower standards

* Internalize trauma
2024-09-07 21:22:41 +03:00

119 lines
3.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package misc
import (
"github.com/bouncepaw/mycorrhiza/internal/cfg"
"github.com/bouncepaw/mycorrhiza/internal/user"
"github.com/bouncepaw/mycorrhiza/internal/version"
"github.com/bouncepaw/mycorrhiza/l18n"
"log"
"strings"
"text/template" // sic!
)
type L10nEntry struct {
_en string
_ru string
}
func En(v string) L10nEntry {
return L10nEntry{_en: v}
}
func (e L10nEntry) Ru(v string) L10nEntry {
e._ru = v
return e
}
func (e L10nEntry) Get(lang string) string {
if lang == "ru" && e._ru != "" {
return e._ru
}
return e._en
}
const aboutTemplateString = `
<main class="main-width">
<section class="about-page">
<h1>{{ printf (get .L.Title) .Cfg.WikiName }}</h1>
<dl>
<dt>{{ get .L.Version }}</dt>
<dd>{{ .Version }}</dd>
{{ if .Cfg.UseAuth }}
<dt>{{ get .L.HomeHypha }}</dt>
<dd><a href="/">{{ .Cfg.HomeHypha }}</a></dd>
<dt>{{get .L.Auth}}</dt>
<dd>{{ get .L.AuthOn }}</dd>
{{if .Cfg.TelegramEnabled}}<dd>{{get .L.TelegramOn}}</dd>{{end}}
<dt>{{ get .L.UserCount }}</dt>
<dd>{{ .UserCount }}</dd>
{{if .Cfg.RegistrationLimit}}
<dt>{{get .L.RegistrationLimit}}</dt>
<dd>{{.RegistrationLimit}}</dd>
{{end}}
<dt>{{ get .L.Admins }}</dt>
{{$cfg := .Cfg}}{{ range $i, $username := .Admins }}
<dd><a href="/hypha/{{ $cfg.UserHypha }}/{{ $username }}">{{ $username }}</a></dd>
{{ end }}
{{ else }}
<dt>{{get .L.Auth}}</dt>
<dd>{{ get .L.AuthOff }}</dd>
{{ end }}
</dl>
</section>
</main>`
var aboutData = struct {
L map[string]L10nEntry
Version string
Cfg map[string]interface{}
Admins []string
UserCount uint64
RegistrationLimit uint64
}{
L: map[string]L10nEntry{
"Title": En("About %s").Ru("О %s"),
"Version": En("<a href=\"https://mycorrhiza.wiki\">Mycorrhiza Wiki</a> version").Ru("Версия <a href=\"https://mycorrhiza.wiki\">Микоризы</a>"),
"UserCount": En("User count").Ru("Число пользователей"),
"HomeHypha": En("Home hypha").Ru("Домашняя гифа"),
"RegistrationLimit": En("RegistrationLimit").Ru("Максимум пользователей"),
"Admins": En("Administrators").Ru("Администраторы"),
"Auth": En("Authentication").Ru("Аутентификация"),
"AuthOn": En("Authentication is on").Ru("Аутентификация включена"),
"AuthOff": En("Authentication is off").Ru("Аутентификация не включена"),
"TelegramOn": En("Telegram authentication is on").Ru("Вход через Телеграм включён"),
},
}
func AboutHTML(lc *l18n.Localizer) string {
get := func(e L10nEntry) string {
return e.Get(lc.Locale)
}
temp, err := template.New("about wiki").Funcs(template.FuncMap{"get": get}).Parse(aboutTemplateString)
if err != nil {
log.Fatalln(err)
}
data := aboutData
data.Version = version.Short
data.Admins = user.ListUsersWithGroup("admin")
data.UserCount = user.Count()
data.RegistrationLimit = cfg.RegistrationLimit
data.Cfg = map[string]interface{}{
"UseAuth": cfg.UseAuth,
"WikiName": cfg.WikiName,
"HomeHypha": cfg.HomeHypha,
"TelegramEnabled": cfg.TelegramEnabled,
"RegistrationLimit": cfg.RegistrationLimit,
}
var out strings.Builder
err = temp.Execute(&out, data)
if err != nil {
log.Println(err)
}
return out.String()
}