From 79e79c6efd3bb842aa26307c22582bebb73c57b7 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sat, 28 May 2022 20:05:22 +0300 Subject: [PATCH] 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. --- cfg/header_links.go | 4 +-- go.mod | 4 +-- go.sum | 4 +-- interwiki/interwiki.go | 7 ++++ shroom/mycomarkup_options.go | 69 ++++++++++++++++++++---------------- static/default.css | 1 + 6 files changed, 52 insertions(+), 37 deletions(-) diff --git a/cfg/header_links.go b/cfg/header_links.go index fcb51c8..7995a57 100644 --- a/cfg/header_links.go +++ b/cfg/header_links.go @@ -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(), }) } } diff --git a/go.mod b/go.mod index f299211..bfbc6cb 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 634b860..9b885a0 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/interwiki/interwiki.go b/interwiki/interwiki.go index b266efe..da622a7 100644 --- a/interwiki/interwiki.go +++ b/interwiki/interwiki.go @@ -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 diff --git a/shroom/mycomarkup_options.go b/shroom/mycomarkup_options.go index 05595e0..a5ed126 100644 --- a/shroom/mycomarkup_options.go +++ b/shroom/mycomarkup_options.go @@ -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() } diff --git a/static/default.css b/static/default.css index 0c69515..6d1c230 100644 --- a/static/default.css +++ b/static/default.css @@ -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; }