1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

Interwiki: Implement /interwiki

It just shown what entries there are. It will let administrators modify it later.
This commit is contained in:
Timur Ismagilov 2022-05-27 16:43:40 +03:00
parent 38ab54b8c3
commit b7d524880f
7 changed files with 110 additions and 4 deletions

View File

@ -16,6 +16,7 @@ func Init() {
log.Fatalln(err)
}
for _, wiki := range record {
wiki := wiki // This line is required
wiki.canonize()
theMap.list = append(theMap.list, &wiki)
for _, prefix := range wiki.Names {

View File

@ -0,0 +1,34 @@
{{define "interwiki map"}}Interwiki map{{end}}
{{define "title"}}{{template "interwiki map"}}{{end}}
{{define "body"}}
<main class="main-width">
<h1>{{template "interwiki map"}}</h1>{{$emojies := .Emojies}}
{{if len .Entries}}
<ul>
{{range $i, $wiki := .Entries}}
<li>
<dl>
<dt>Names</dt>
{{range .Names}}<dd>{{.}}</dd>{{end}}
<dt>Description</dt>
<dd>{{.Description}}</dd>
<dt>Engine</dt>
<dd>{{index $emojies $i}}</dd>
<dt>URL</dt>
<dd><a href="{{.URL}}">{{.URL}}</a></dd>
<dt>Link format</dt>
<dd>{{.LinkFormat}}</dd>
</dl>
</li>
{{end}}
</ul>
{{else}}
<p>No interwiki map set.</p>
{{end}}
</main>
{{end}}

48
interwiki/web.go Normal file
View File

@ -0,0 +1,48 @@
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
}

View File

@ -20,6 +20,26 @@ const (
Generic
)
// EmojiWithName returns a Unicode emoji that kinda represents the engine and the engine name. One day we might move to actual images. OK for now.
func (we WikiEngine) EmojiWithName() string {
switch we {
case Mycorrhiza:
return "🍄 Mycorrhiza"
case OddMuse:
return "🐫 OddMuse"
case MediaWiki:
return "🌻 MediaWiki"
case MoinMoin1:
return "Ⓜ️ MoinMoin 1.9"
case MoinMoin2:
return "Ⓜ️ MoinMoin 2.*"
case DokuWiki:
return "📝 DokuWiki"
default:
return "🌐 Generic"
}
}
// Wiki is an entry in the interwiki map.
type Wiki struct {
// Names is a slice of link prefices that correspond to this wiki.

View File

@ -7,6 +7,7 @@ package main
import (
"github.com/bouncepaw/mycorrhiza/backlinks"
"github.com/bouncepaw/mycorrhiza/categories"
"github.com/bouncepaw/mycorrhiza/interwiki"
"github.com/bouncepaw/mycorrhiza/migration"
"github.com/bouncepaw/mycorrhiza/viewutil"
"log"
@ -51,7 +52,7 @@ func main() {
migration.MigrateHeadingsMaybe()
shroom.SetHeaderLinks()
categories.Init()
// interwiki.Init()
interwiki.Init()
// Static files:
static.InitFS(files.StaticFiles())

View File

@ -857,11 +857,11 @@ kbd {
}
/*
* About page
* Definition list
*/
.about-page dt {
dt {
font-weight: bold;
}
.about-page dd + dt {
dd + dt {
margin-top: .5rem;
}

View File

@ -8,6 +8,7 @@ import (
"github.com/bouncepaw/mycorrhiza/help"
"github.com/bouncepaw/mycorrhiza/history/histweb"
"github.com/bouncepaw/mycorrhiza/hypview"
"github.com/bouncepaw/mycorrhiza/interwiki"
"github.com/bouncepaw/mycorrhiza/misc"
"io"
"net/http"
@ -56,6 +57,7 @@ func Handler() http.Handler {
misc.InitHandlers(wikiRouter)
hypview.Init()
histweb.InitHandlers(wikiRouter)
interwiki.InitHandlers(wikiRouter)
// Admin routes.
if cfg.UseAuth {