1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00
mycorrhiza/mycoopts/mycoopts.go
Timur Ismagilov 5f751cca07 Move Mycomarkup to SourceHut
Les Arbres didn't work in the end
2022-08-22 01:52:10 +05:00

55 lines
1.6 KiB
Go

package mycoopts
import (
"errors"
"git.sr.ht/~bouncepaw/mycomarkup/v5/options"
"github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/interwiki"
"github.com/bouncepaw/mycorrhiza/util"
)
func MarkupOptions(hyphaName string) options.Options {
return options.Options{
HyphaName: hyphaName,
WebSiteURL: cfg.URL,
TransclusionSupported: true,
RedLinksSupported: true,
InterwikiSupported: 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 = hyphae.FetchMycomarkupFile(h)
case *hyphae.MediaHypha:
rawText, err = hyphae.FetchMycomarkupFile(h)
binaryBlock = mediaRaw(h)
}
return
},
LocalTargetCanonicalName: util.CanonicalName,
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.ImgSrcFormatFor,
}.FillTheRest()
}