mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-20 15:32:52 +00:00
Interwiki: Change the fields of the entries
This commit is contained in:
parent
ee9602c745
commit
8c52e1efee
@ -20,11 +20,11 @@ func Init() {
|
||||
wiki := wiki // This line is required
|
||||
wiki.canonize()
|
||||
theMap.list = append(theMap.list, &wiki)
|
||||
for _, prefix := range wiki.Names {
|
||||
if _, found := theMap.byName[prefix]; found {
|
||||
log.Fatalf("There are multiple uses of the same prefix ‘%s’\n", prefix)
|
||||
for _, name := range append(wiki.Aliases, wiki.Name) {
|
||||
if _, found := theMap.byName[name]; found {
|
||||
log.Fatalf("There are multiple uses of the same name ‘%s’\n", name)
|
||||
} else {
|
||||
theMap.byName[prefix] = &wiki
|
||||
theMap.byName[name] = &wiki
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,23 @@
|
||||
{{define "interwiki map"}}Interwiki map{{end}}
|
||||
{{define "title"}}{{template "interwiki map"}}{{end}}
|
||||
|
||||
{{define "static map"}}{{$emojies := .Emojies}}
|
||||
{{define "static map"}}
|
||||
{{if len .Entries}}
|
||||
<ul>
|
||||
{{range $i, $wiki := .Entries}}
|
||||
<li>
|
||||
<dl>
|
||||
<dt>Names</dt>
|
||||
{{range .Names}}<dd>{{.}}</dd>{{end}}
|
||||
<dt>Name</dt>
|
||||
<dd>{{.Name}}</dd>
|
||||
|
||||
<dt>Aliases</dt>
|
||||
{{range .Aliases}}<dd>{{.}}</dd>{{end}}
|
||||
|
||||
<dt>Description</dt>
|
||||
<dd>{{.Description}}</dd>
|
||||
|
||||
<dt>Engine</dt>
|
||||
<dd>{{index $emojies $i}}</dd>
|
||||
<dd>{{.Engine}}</dd>
|
||||
|
||||
<dt>URL</dt>
|
||||
<dd><a href="{{.URL}}">{{.URL}}</a></dd>
|
||||
@ -37,14 +40,22 @@
|
||||
{{if .Error}}
|
||||
<p class="error">{{.Error}}</p>
|
||||
{{end}}
|
||||
{{template "static map" .}}
|
||||
{{if len .Entries}}
|
||||
{{range $i, $wiki := .Entries}}
|
||||
<!-- todo -->
|
||||
{{end}}
|
||||
{{end}}
|
||||
<form method="post" action="/interwiki/add-entry">
|
||||
<h2>Add interwiki entry</h2>
|
||||
<p><a href="/help/en/interwiki">Documentation.</a></p>
|
||||
<p>
|
||||
<label for="names" class="required-field">Names (separated by commas):</label>
|
||||
<input type="text" id="names" name="names" required
|
||||
placeholder="home_wiki, hw">
|
||||
<label for="name" class="required-field">Name:</label>
|
||||
<input type="text" id="name" name="name" required
|
||||
placeholder="home_wiki">
|
||||
</p>
|
||||
<p>
|
||||
<label for="aliases">Aliases (separated by commas):</label>
|
||||
<input type="text" id="aliases" name="aliases"
|
||||
placeholder="homewiki, hw">
|
||||
</p>
|
||||
<p>
|
||||
<label for="url" class="required-field">URL:</label>
|
||||
@ -77,6 +88,7 @@
|
||||
{{define "body"}}
|
||||
<main class="main-width">
|
||||
<h1>{{template "interwiki map"}}</h1>
|
||||
<p><a href="/help/en/interwiki">Documentation.</a></p>
|
||||
{{if .CanEdit}}
|
||||
{{template "authorized map" .}}
|
||||
{{else}}
|
||||
|
@ -26,8 +26,6 @@ func handlerInterwiki(w http.ResponseWriter, rq *http.Request) {
|
||||
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
|
||||
Error string
|
||||
}
|
||||
@ -36,15 +34,7 @@ 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",
|
||||
Error: "",
|
||||
})
|
||||
}
|
||||
|
||||
func emojiesForEngines(list []*Wiki) (emojies []string) {
|
||||
for _, entry := range list {
|
||||
emojies = append(emojies, entry.Engine.EmojiWithName())
|
||||
}
|
||||
return emojies
|
||||
}
|
||||
|
@ -7,93 +7,69 @@ import (
|
||||
)
|
||||
|
||||
// WikiEngine is an enumeration of supported interwiki targets.
|
||||
type WikiEngine int
|
||||
type WikiEngine string
|
||||
|
||||
const (
|
||||
Mycorrhiza WikiEngine = iota
|
||||
Agora
|
||||
Mycorrhiza WikiEngine = "mycorrhiza"
|
||||
Agora WikiEngine = "agora"
|
||||
// Generic is any website.
|
||||
Generic
|
||||
Generic WikiEngine = "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.
|
||||
// TODO: reconsider
|
||||
func (we WikiEngine) EmojiWithName() string {
|
||||
func (we WikiEngine) Valid() bool {
|
||||
switch we {
|
||||
case Mycorrhiza:
|
||||
return "🍄 Mycorrhiza"
|
||||
case Agora:
|
||||
return "ἀ Agora"
|
||||
/*case OddMuse: Might return them in the future
|
||||
return "🐫 OddMuse"
|
||||
case MediaWiki:
|
||||
return "🌻 MediaWiki"
|
||||
case MoinMoin1:
|
||||
return "Ⓜ️ MoinMoin 1.9"
|
||||
case MoinMoin2:
|
||||
return "Ⓜ️ MoinMoin 2.*"
|
||||
case DokuWiki:
|
||||
return "📝 DokuWiki"*/
|
||||
default:
|
||||
return "🌐 Generic"
|
||||
case Mycorrhiza, Agora, Generic:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Wiki is an entry in the interwiki map.
|
||||
type Wiki struct {
|
||||
// Names is a slice of link prefices that correspond to this wiki.
|
||||
Names []string `json:"names"`
|
||||
// Name is the name of the wiki, and is also one of the possible prefices.
|
||||
Name string `json:"name"`
|
||||
|
||||
// Aliases are alternative prefices you can use instead of Name. This slice can be empty.
|
||||
Aliases []string `json:"aliases,omitempty"`
|
||||
|
||||
// URL is the address of the wiki.
|
||||
URL string `json:"url"`
|
||||
|
||||
// LinkHrefFormat is a format string for interwiki links. See Mycomarkup internal docs hidden deep inside for more information.
|
||||
//
|
||||
// This field is optional. For other wikis, it is automatically set to <URL>/{NAME}; for Mycorrhiza wikis, it is automatically set to <URL>/hypha/{NAME}}.
|
||||
// This field is optional. If it is not set, it is derived from other data. See the code.
|
||||
LinkHrefFormat string `json:"link_href_format"`
|
||||
|
||||
ImgSrcFormat string `json:"img_src_format"`
|
||||
|
||||
// Description is a plain-text description of the wiki.
|
||||
Description string `json:"description"`
|
||||
// Description is a plain-text description of the wiki. Can be empty.
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// Engine is the engine of the wiki. This field is not set in JSON.
|
||||
Engine WikiEngine `json:"-"`
|
||||
|
||||
// EngineString is a string name of the engine. It is then converted to Engine. See the code to learn the supported values. All other values will result in an error.
|
||||
EngineString string `json:"engine"`
|
||||
}
|
||||
|
||||
var wikiEnginesLookup = map[string]WikiEngine{
|
||||
"mycorrhiza": Mycorrhiza,
|
||||
"agora": Agora,
|
||||
"generic": Generic,
|
||||
// Engine is the engine of the wiki. Invalid values will result in a start-up error.
|
||||
Engine WikiEngine `json:"engine"`
|
||||
}
|
||||
|
||||
func (w *Wiki) canonize() {
|
||||
if engine, ok := wikiEnginesLookup[w.EngineString]; ok {
|
||||
w.Engine = engine
|
||||
w.EngineString = "" // Ain't gonna need it anymore
|
||||
} else {
|
||||
log.Fatalf("Unknown engine ‘%s’\n", w.EngineString)
|
||||
}
|
||||
|
||||
if len(w.Names) == 0 {
|
||||
switch {
|
||||
case w.Name == "":
|
||||
log.Fatalln("Cannot have a wiki in the interwiki map with no name")
|
||||
case w.URL == "":
|
||||
log.Fatalf("Wiki ‘%s’ has no URL\n", w.Name)
|
||||
case !w.Engine.Valid():
|
||||
log.Fatalf("Unknown engine ‘%s’ for wiki ‘%s’\n", w.Engine, w.Name)
|
||||
}
|
||||
|
||||
if w.URL == "" {
|
||||
log.Fatalf("Wiki ‘%s’ has no URL\n", w.Names[0])
|
||||
}
|
||||
|
||||
for i, prefix := range w.Names {
|
||||
w.Names[i] = util.CanonicalName(prefix)
|
||||
w.Name = util.CanonicalName(w.Name)
|
||||
for i, alias := range w.Aliases {
|
||||
w.Aliases[i] = util.CanonicalName(alias)
|
||||
}
|
||||
|
||||
if w.LinkHrefFormat == "" {
|
||||
switch w.Engine {
|
||||
case Mycorrhiza:
|
||||
w.LinkHrefFormat = fmt.Sprintf("%s/hypha/{NAME}", w.URL)
|
||||
case Agora:
|
||||
w.LinkHrefFormat = fmt.Sprintf("%s/node/{NAME}", w.URL)
|
||||
default:
|
||||
w.LinkHrefFormat = fmt.Sprintf("%s/{NAME}", w.URL)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user