1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-13 05:50:27 +00:00
mycorrhiza/interwiki/web.go
Timur Ismagilov b7d524880f Interwiki: Implement /interwiki
It just shown what entries there are. It will let administrators modify it later.
2022-05-27 16:43:40 +03:00

49 lines
1.1 KiB
Go

package interwiki
import (
"embed"
"github.com/bouncepaw/mycorrhiza/viewutil"
"github.com/gorilla/mux"
"net/http"
)
var (
//go:embed *html
fs embed.FS
ruTranslation = ``
chainInterwiki viewutil.Chain
)
func InitHandlers(rtr *mux.Router) {
chainInterwiki = viewutil.CopyEnRuWith(fs, "view_interwiki.html", ruTranslation)
rtr.HandleFunc("/interwiki", handlerInterwiki)
}
func handlerInterwiki(w http.ResponseWriter, rq *http.Request) {
viewInterwiki(viewutil.MetaFrom(w, rq))
}
type interwikiData struct {
*viewutil.BaseData
Entries []*Wiki
// Emojies contains emojies that represent wiki engines. Emojies[i] is an emoji for Entries[i].Engine
Emojies []string
CanEdit bool
}
func viewInterwiki(meta viewutil.Meta) {
viewutil.ExecutePage(meta, chainInterwiki, interwikiData{
BaseData: &viewutil.BaseData{},
Entries: theMap.list,
Emojies: emojiesForEngines(theMap.list),
CanEdit: meta.U.Group == "admin",
})
}
func emojiesForEngines(list []*Wiki) (emojies []string) {
for _, entry := range list {
emojies = append(emojies, entry.Engine.EmojiWithName())
}
return emojies
}