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

Interwiki: Start migrating to new API

Come to think of it, it is a breaking API change out there, right? Gotta bump Mycomarkup to v5 one day.
This commit is contained in:
Timur Ismagilov 2022-05-28 20:05:22 +03:00 committed by Timur Ismagilov
parent b5093b0b76
commit 79e79c6efd
6 changed files with 52 additions and 37 deletions

View File

@ -31,8 +31,8 @@ func ParseHeaderLinks(text string) {
case blocks.LaunchPad:
for _, rocket := range launchpad.Rockets {
HeaderLinks = append(HeaderLinks, HeaderLink{
Href: rocket.Href(),
Display: rocket.Display(),
Href: rocket.LinkHref(ctx),
Display: rocket.DisplayedText(),
})
}
}

4
go.mod
View File

@ -3,7 +3,7 @@ module github.com/bouncepaw/mycorrhiza
go 1.18
require (
github.com/bouncepaw/mycomarkup/v4 v4.2.0
github.com/bouncepaw/mycomarkup/v4 v4.3.0
github.com/go-ini/ini v1.63.2
github.com/gorilla/feeds v1.1.1
github.com/gorilla/mux v1.8.0
@ -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.0.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

4
go.sum
View File

@ -1,7 +1,7 @@
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bouncepaw/mycomarkup/v4 v4.2.0 h1:YpxVL3I9X94T7B/2R/5/u1McfVXomlPdXcX/x+Ur3kI=
github.com/bouncepaw/mycomarkup/v4 v4.2.0/go.mod h1:y0b8U6Xfnh3KfNUpG3QuAXRJwqFPPpmS2kYvLzaf688=
github.com/bouncepaw/mycomarkup/v4 v4.3.0 h1:Sj2spSzNbd/o5AKOi/Y/vRPpebaz5s9HOKP42UDA9Dg=
github.com/bouncepaw/mycomarkup/v4 v4.3.0/go.mod h1:y0b8U6Xfnh3KfNUpG3QuAXRJwqFPPpmS2kYvLzaf688=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ini/ini v1.63.2 h1:kwN3umicd2HF3Tgvap4um1ZG52/WyKT9GGdPx0CJk6Y=

View File

@ -30,6 +30,13 @@ func Init() {
log.Printf("Loaded %d interwiki entries\n", len(theMap.list))
}
func HrefLinkFormatFor(prefix string) string {
if wiki, ok := theMap.byName[prefix]; ok {
return wiki.LinkFormat
}
return "{NAME}"
}
func readInterwiki() ([]Wiki, error) {
var (
record []Wiki

View File

@ -5,42 +5,49 @@ import (
"github.com/bouncepaw/mycomarkup/v4/options"
"github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/interwiki"
"github.com/bouncepaw/mycorrhiza/util"
"github.com/bouncepaw/mycorrhiza/views"
)
func MarkupOptions(hyphaName string) options.Options {
return fillMycomarkupOptions(options.Options{
return options.Options{
HyphaName: hyphaName,
WebSiteURL: cfg.URL,
TransclusionSupported: true,
})
}
func fillMycomarkupOptions(opts options.Options) options.Options {
opts.HyphaExists = func(hyphaName string) bool {
switch hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
return false
default:
return true
}
}
opts.HyphaHTMLData = func(hyphaName string) (rawText, binaryBlock string, err error) {
switch h := hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
err = errors.New("Hypha " + hyphaName + " does not exist")
case *hyphae.TextualHypha:
rawText, err = FetchTextFile(h)
case *hyphae.MediaHypha:
rawText, err = FetchTextFile(h)
binaryBlock = views.MediaRaw(h)
}
return
}
opts.IterateHyphaNamesWith = func(λ func(string)) {
for h := range hyphae.YieldExistingHyphae() {
λ(h.CanonicalName())
}
}
return opts.FillTheRest()
RedLinksSupported: true,
HyphaExists: func(hyphaName string) bool {
switch hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
return false
default:
return true
}
},
IterateHyphaNamesWith: func(λ func(string)) {
for h := range hyphae.YieldExistingHyphae() {
λ(h.CanonicalName())
}
},
HyphaHTMLData: func(hyphaName string) (rawText, binaryBlock string, err error) {
switch h := hyphae.ByName(hyphaName).(type) {
case *hyphae.EmptyHypha:
err = errors.New("Hypha " + hyphaName + " does not exist")
case *hyphae.TextualHypha:
rawText, err = FetchTextFile(h)
case *hyphae.MediaHypha:
rawText, err = FetchTextFile(h)
binaryBlock = views.MediaRaw(h)
}
return
},
LocalLinkHref: func(hyphaName string) string {
return "/hypha/" + util.CanonicalName(hyphaName)
},
LocalImgSrc: func(hyphaName string) string {
return "/binary/" + util.CanonicalName(hyphaName)
},
LinkHrefFormatForInterwikiPrefix: interwiki.HrefLinkFormatFor,
ImgSrcFormatForInterwikiPrefix: interwiki.HrefLinkFormatFor, // TODO: dewrong
}.FillTheRest()
}

View File

@ -242,6 +242,7 @@ main { background-color: white; }
.shy-link { color: black; }
blockquote { border-left: 2px #999 solid; }
.wikilink_interwiki {color:#080;}
.wikilink_new {color:#a55858;}
.transclusion code, .transclusion .codeblock {background-color:#ddd;}
.transclusion__link { color: black; }