mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-05 17:40:26 +00:00
Interwiki: Make it work!
Interwiki links interwiki links. Still rough, but works sometimes.
This commit is contained in:
parent
79e79c6efd
commit
4b9038c00b
2
go.mod
2
go.mod
@ -23,7 +23,7 @@ require (
|
||||
|
||||
// Use this trick to test local Mycomarkup changes, replace the path with yours,
|
||||
// but do not commit the change to the path:
|
||||
// replace github.com/bouncepaw/mycomarkup/v4 v4.3.0 => "/Users/bouncepaw/GolandProjects/mycomarkup"
|
||||
replace github.com/bouncepaw/mycomarkup/v4 v4.3.0 => "/Users/bouncepaw/GolandProjects/mycomarkup"
|
||||
|
||||
// Use this utility every time Mycomarkup gets a major update:
|
||||
// https://github.com/marwan-at-work/mod
|
||||
|
@ -32,9 +32,16 @@ func Init() {
|
||||
|
||||
func HrefLinkFormatFor(prefix string) string {
|
||||
if wiki, ok := theMap.byName[prefix]; ok {
|
||||
return wiki.LinkFormat
|
||||
return wiki.LinkHrefFormat
|
||||
}
|
||||
return "{NAME}"
|
||||
return "{NAME}" // TODO: error
|
||||
}
|
||||
|
||||
func ImgSrcFormatFor(prefix string) string {
|
||||
if wiki, ok := theMap.byName[prefix]; ok {
|
||||
return wiki.ImgSrcFormat
|
||||
}
|
||||
return "{NAME}" // TODO: error
|
||||
}
|
||||
|
||||
func readInterwiki() ([]Wiki, error) {
|
||||
|
@ -48,12 +48,12 @@ type Wiki struct {
|
||||
// URL is the address of the wiki.
|
||||
URL string `json:"url"`
|
||||
|
||||
// LinkFormat is a format string for incoming interwiki links. The format strings should look like this:
|
||||
// http://wiki.example.org/view/%s
|
||||
// where %s is where text will be inserted. No other % instructions are supported yet. They will be added once we learn of their use cases.
|
||||
// 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>/%s; for Mycorrhiza wikis, it is automatically set to <URL>/hypha/%s.
|
||||
LinkFormat string `json:"link_format"`
|
||||
// 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}}.
|
||||
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"`
|
||||
@ -95,12 +95,21 @@ func (w *Wiki) canonize() {
|
||||
w.Names[i] = util.CanonicalName(prefix)
|
||||
}
|
||||
|
||||
if w.LinkFormat == "" {
|
||||
if w.LinkHrefFormat == "" {
|
||||
switch w.Engine {
|
||||
case Mycorrhiza:
|
||||
w.LinkFormat = fmt.Sprintf("%s/hypha/%%s", w.URL)
|
||||
w.LinkHrefFormat = fmt.Sprintf("%s/hypha/{NAME}", w.URL)
|
||||
default:
|
||||
w.LinkFormat = fmt.Sprintf("%s/%%s", w.URL)
|
||||
w.LinkHrefFormat = fmt.Sprintf("%s/{NAME}", w.URL)
|
||||
}
|
||||
}
|
||||
|
||||
if w.ImgSrcFormat == "" {
|
||||
switch w.Engine {
|
||||
case Mycorrhiza:
|
||||
w.ImgSrcFormat = fmt.Sprintf("%s/binary/{NAME}", w.URL)
|
||||
default:
|
||||
w.ImgSrcFormat = fmt.Sprintf("%s/{NAME}", w.URL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,6 @@ func MarkupOptions(hyphaName string) options.Options {
|
||||
return "/binary/" + util.CanonicalName(hyphaName)
|
||||
},
|
||||
LinkHrefFormatForInterwikiPrefix: interwiki.HrefLinkFormatFor,
|
||||
ImgSrcFormatForInterwikiPrefix: interwiki.HrefLinkFormatFor, // TODO: dewrong
|
||||
ImgSrcFormatForInterwikiPrefix: interwiki.ImgSrcFormatFor,
|
||||
}.FillTheRest()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user