2022-08-06 11:35:17 +00:00
|
|
|
|
package misc
|
2022-02-26 17:46:21 +00:00
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/l18n"
|
|
|
|
|
"github.com/bouncepaw/mycorrhiza/user"
|
2022-08-17 08:21:54 +00:00
|
|
|
|
"github.com/bouncepaw/mycorrhiza/version"
|
2022-02-26 17:46:21 +00:00
|
|
|
|
"log"
|
|
|
|
|
"strings"
|
|
|
|
|
"text/template" // sic!
|
|
|
|
|
)
|
|
|
|
|
|
2022-08-06 11:35:17 +00:00
|
|
|
|
type L10nEntry struct {
|
2022-02-26 17:46:21 +00:00
|
|
|
|
_en string
|
|
|
|
|
_ru string
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 11:35:17 +00:00
|
|
|
|
func En(v string) L10nEntry {
|
|
|
|
|
return L10nEntry{_en: v}
|
2022-02-26 17:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 11:35:17 +00:00
|
|
|
|
func (e L10nEntry) Ru(v string) L10nEntry {
|
2022-02-26 17:46:21 +00:00
|
|
|
|
e._ru = v
|
|
|
|
|
return e
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 11:35:17 +00:00
|
|
|
|
func (e L10nEntry) Get(lang string) string {
|
2022-02-26 17:46:21 +00:00
|
|
|
|
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-08-17 08:21:54 +00:00
|
|
|
|
<dd>{{ .Version }}</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-05-17 13:43:03 +00:00
|
|
|
|
{{if .Cfg.RegistrationLimit}}
|
|
|
|
|
<dt>{{get .L.RegistrationLimit}}</dt>
|
|
|
|
|
<dd>{{.RegistrationLimit}}</dd>
|
|
|
|
|
{{end}}
|
2022-04-21 14:56:18 +00:00
|
|
|
|
|
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 {
|
2022-08-06 11:35:17 +00:00
|
|
|
|
L map[string]L10nEntry
|
2022-08-17 08:21:54 +00:00
|
|
|
|
Version string
|
2022-05-17 13:43:03 +00:00
|
|
|
|
Cfg map[string]interface{}
|
|
|
|
|
Admins []string
|
|
|
|
|
UserCount uint64
|
|
|
|
|
RegistrationLimit uint64
|
2022-02-26 17:46:21 +00:00
|
|
|
|
}{
|
2022-08-06 11:35:17 +00:00
|
|
|
|
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("Администраторы"),
|
2022-04-21 14:56:18 +00:00
|
|
|
|
|
2022-08-06 11:35:17 +00:00
|
|
|
|
"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 {
|
2022-08-06 11:35:17 +00:00
|
|
|
|
get := func(e L10nEntry) string {
|
|
|
|
|
return e.Get(lc.Locale)
|
2022-02-26 17:46:21 +00:00
|
|
|
|
}
|
|
|
|
|
temp, err := template.New("about wiki").Funcs(template.FuncMap{"get": get}).Parse(aboutTemplateString)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalln(err)
|
|
|
|
|
}
|
|
|
|
|
data := aboutData
|
2022-09-14 07:38:36 +00:00
|
|
|
|
data.Version = version.Short
|
2022-02-26 17:46:21 +00:00
|
|
|
|
data.Admins = user.ListUsersWithGroup("admin")
|
|
|
|
|
data.UserCount = user.Count()
|
2022-05-17 13:43:03 +00:00
|
|
|
|
data.RegistrationLimit = cfg.RegistrationLimit
|
2022-02-26 17:46:21 +00:00
|
|
|
|
data.Cfg = map[string]interface{}{
|
2022-05-17 13:43:03 +00:00
|
|
|
|
"UseAuth": cfg.UseAuth,
|
|
|
|
|
"WikiName": cfg.WikiName,
|
|
|
|
|
"HomeHypha": cfg.HomeHypha,
|
|
|
|
|
"TelegramEnabled": cfg.TelegramEnabled,
|
|
|
|
|
"RegistrationLimit": cfg.RegistrationLimit,
|
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()
|
|
|
|
|
}
|