2022-02-26 17:46:21 +00:00
|
|
|
|
package views
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/l18n"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/user"
|
|
|
|
|
"log"
|
|
|
|
|
"strings"
|
|
|
|
|
"text/template" // sic!
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type l10nEntry struct {
|
|
|
|
|
_en string
|
|
|
|
|
_ru string
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-27 10:44:47 +00:00
|
|
|
|
func en(v string) l10nEntry {
|
2022-04-21 14:56:18 +00:00
|
|
|
|
return l10nEntry{_en: v}
|
2022-02-26 17:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 16:05:17 +00:00
|
|
|
|
const aboutTemplateString = `
|
2022-02-26 17:46:21 +00:00
|
|
|
|
<main class="main-width">
|
2022-04-21 14:56:18 +00:00
|
|
|
|
<section class="about-page">
|
2022-02-26 17:46:21 +00:00
|
|
|
|
<h1>{{ printf (get .L.Title) .Cfg.WikiName }}</h1>
|
2022-04-21 14:19:43 +00:00
|
|
|
|
<dl>
|
|
|
|
|
<dt>{{ get .L.Version }}</dt>
|
2022-04-21 14:39:23 +00:00
|
|
|
|
<dd>1.10.0</dd>
|
2022-02-26 17:46:21 +00:00
|
|
|
|
{{ if .Cfg.UseAuth }}
|
2022-04-21 14:19:43 +00:00
|
|
|
|
<dt>{{ get .L.HomeHypha }}</dt>
|
|
|
|
|
<dd><a href="/">{{ .Cfg.HomeHypha }}</a></dd>
|
|
|
|
|
|
2022-04-21 14:56:18 +00:00
|
|
|
|
<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>
|
|
|
|
|
|
2022-04-21 14:19:43 +00:00
|
|
|
|
<dt>{{ get .L.Admins }}</dt>
|
|
|
|
|
{{$cfg := .Cfg}}{{ range $i, $username := .Admins }}
|
|
|
|
|
<dd><a href="/hypha/{{ $cfg.UserHypha }}/{{ $username }}">{{ $username }}</a></dd>
|
|
|
|
|
{{ end }}
|
|
|
|
|
|
2022-02-26 17:46:21 +00:00
|
|
|
|
{{ else }}
|
2022-04-21 14:19:43 +00:00
|
|
|
|
<dt>{{get .L.Auth}}</dt>
|
2022-04-21 14:56:18 +00:00
|
|
|
|
<dd>{{ get .L.AuthOff }}</dd>
|
2022-02-26 17:46:21 +00:00
|
|
|
|
{{ end }}
|
2022-04-21 14:19:43 +00:00
|
|
|
|
</dl>
|
2022-02-26 17:46:21 +00:00
|
|
|
|
</section>
|
2022-04-21 16:05:17 +00:00
|
|
|
|
</main>`
|
2022-02-26 17:46:21 +00:00
|
|
|
|
|
|
|
|
|
var aboutData = struct {
|
|
|
|
|
L map[string]l10nEntry
|
|
|
|
|
Cfg map[string]interface{}
|
|
|
|
|
Admins []string
|
|
|
|
|
UserCount uint64
|
|
|
|
|
}{
|
|
|
|
|
L: map[string]l10nEntry{
|
2022-04-21 14:56:18 +00:00
|
|
|
|
"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("Домашняя гифа"),
|
|
|
|
|
"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("Вход через Телеграм включён"),
|
2022-02-26 17:46:21 +00:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.Admins = user.ListUsersWithGroup("admin")
|
|
|
|
|
data.UserCount = user.Count()
|
|
|
|
|
data.Cfg = map[string]interface{}{
|
2022-04-21 14:56:18 +00:00
|
|
|
|
"UseAuth": cfg.UseAuth,
|
|
|
|
|
"WikiName": cfg.WikiName,
|
|
|
|
|
"HomeHypha": cfg.HomeHypha,
|
|
|
|
|
"TelegramEnabled": cfg.TelegramEnabled,
|
2022-02-26 17:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
var out strings.Builder
|
|
|
|
|
err = temp.Execute(&out, data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
return out.String()
|
|
|
|
|
}
|