mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-04-21 10:13:15 +00:00
Migrate to mycomarkup/links module
This commit is contained in:
parent
a1852d363e
commit
171e9e2bac
3
go.mod
3
go.mod
@ -5,12 +5,13 @@ go 1.14
|
||||
require (
|
||||
git.sr.ht/~adnano/go-gemini v0.1.13
|
||||
github.com/adrg/xdg v0.2.2
|
||||
github.com/bouncepaw/mycomarkup v0.0.0-20210511092446-956f169b1499
|
||||
github.com/go-ini/ini v1.62.0
|
||||
github.com/gorilla/feeds v1.1.1
|
||||
github.com/kr/pretty v0.2.1 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
github.com/valyala/quicktemplate v1.6.3
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
)
|
||||
|
27
go.sum
27
go.sum
@ -3,6 +3,10 @@ git.sr.ht/~adnano/go-gemini v0.1.13/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3V
|
||||
github.com/adrg/xdg v0.2.2 h1:A7ZHKRz5KGOLJX/bg7IPzStryhvCzAE1wX+KWawPiAo=
|
||||
github.com/adrg/xdg v0.2.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ=
|
||||
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/bouncepaw/mycomarkup v0.0.0-20210502065108-4ddae294864d h1:H20wX93QMeQhQbXYdhofRrsFwn8jJ41zmJk5jr/1VOA=
|
||||
github.com/bouncepaw/mycomarkup v0.0.0-20210502065108-4ddae294864d/go.mod h1:fx0FBKaCaV1fofgCQOu2lNIVB/5EoDg/83i8BgBdgpc=
|
||||
github.com/bouncepaw/mycomarkup v0.0.0-20210511092446-956f169b1499 h1:RLKVj992QuayqjpIJ7M2csRjfhAnu9EO2r1Bm4D/WlU=
|
||||
github.com/bouncepaw/mycomarkup v0.0.0-20210511092446-956f169b1499/go.mod h1:fx0FBKaCaV1fofgCQOu2lNIVB/5EoDg/83i8BgBdgpc=
|
||||
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.62.0 h1:7VJT/ZXjzqSrvtraFp4ONq80hTcRQth1c9ZnQ3uNQvU=
|
||||
@ -37,15 +41,36 @@ github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl
|
||||
github.com/valyala/quicktemplate v1.6.3 h1:O7EuMwuH7Q94U2CXD6sOX8AYHqQqWtmIk690IhmpkKA=
|
||||
github.com/valyala/quicktemplate v1.6.3/go.mod h1:fwPzK2fHuYEODzJ9pkw0ipCPNHZ2tD5KW4lOuSdPKzY=
|
||||
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.1-0.20210319172145-bda8f5cee399/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
||||
|
138
link/link.go
138
link/link.go
@ -1,138 +0,0 @@
|
||||
package link
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
)
|
||||
|
||||
// LinkType tells what type the given link is.
|
||||
type LinkType int
|
||||
|
||||
const (
|
||||
LinkInvalid LinkType = iota
|
||||
// LinkLocalRoot is a link like "/list", "/user-list", etc.
|
||||
LinkLocalRoot
|
||||
// LinkLocalHypha is a link like "test", "../test", etc.
|
||||
LinkLocalHypha
|
||||
// LinkExternal is an external link with specified protocol.
|
||||
LinkExternal
|
||||
// LinkInterwiki is currently unused.
|
||||
LinkInterwiki
|
||||
)
|
||||
|
||||
// Link is an abstraction for universal representation of links, be they links in mycomarkup links or whatever.
|
||||
type Link struct {
|
||||
// Address is what the link points to.
|
||||
Address string
|
||||
// Display is what gets nested into the <a> tag.
|
||||
Display string
|
||||
Kind LinkType
|
||||
DestinationUnknown bool
|
||||
|
||||
// #...
|
||||
Anchor string
|
||||
Protocol string
|
||||
// How the link address looked originally in source text.
|
||||
SrcAddress string
|
||||
// How the link display text looked originally in source text. May be empty.
|
||||
SrcDisplay string
|
||||
// RelativeTo is hypha name to which the link is relative to.
|
||||
RelativeTo string
|
||||
}
|
||||
|
||||
// DoubtExistence sets DestinationUnknown to true if the link is local hypha link.
|
||||
func (l *Link) DoubtExistence() {
|
||||
if l.Kind == LinkLocalHypha {
|
||||
l.DestinationUnknown = true
|
||||
}
|
||||
}
|
||||
|
||||
// Classes returns CSS class string for given link.
|
||||
func (l *Link) Classes() string {
|
||||
if l.Kind == LinkExternal {
|
||||
return fmt.Sprintf("wikilink wikilink_external wikilink_%s", l.Protocol)
|
||||
}
|
||||
classes := "wikilink wikilink_internal"
|
||||
if l.DestinationUnknown {
|
||||
classes += " wikilink_new"
|
||||
}
|
||||
return classes
|
||||
}
|
||||
|
||||
// Href returns content for the href attrubite for hyperlink. You should always use it.
|
||||
func (l *Link) Href() string {
|
||||
switch l.Kind {
|
||||
case LinkExternal, LinkLocalRoot:
|
||||
return l.Address + l.Anchor
|
||||
default:
|
||||
return "/hypha/" + l.Address + l.Anchor
|
||||
}
|
||||
}
|
||||
|
||||
// ImgSrc returns content for src attribute of img tag. Used with `img{}`.
|
||||
func (l *Link) ImgSrc() string {
|
||||
switch l.Kind {
|
||||
case LinkExternal, LinkLocalRoot:
|
||||
return l.Address
|
||||
default:
|
||||
return "/binary/" + l.Address
|
||||
}
|
||||
}
|
||||
|
||||
// From returns a Link object given these `address` and `display` on relative to given `hyphaName`.
|
||||
func From(address, display, hyphaName string) *Link {
|
||||
address = strings.TrimSpace(address)
|
||||
link := Link{
|
||||
SrcAddress: address,
|
||||
SrcDisplay: display,
|
||||
RelativeTo: hyphaName,
|
||||
}
|
||||
|
||||
if display == "" {
|
||||
link.Display = address
|
||||
} else {
|
||||
link.Display = strings.TrimSpace(display)
|
||||
}
|
||||
|
||||
if pos := strings.IndexRune(address, '#'); pos != -1 && pos != 0 {
|
||||
link.Anchor = address[pos:]
|
||||
address = address[:pos]
|
||||
}
|
||||
|
||||
switch {
|
||||
case strings.ContainsRune(address, ':'):
|
||||
pos := strings.IndexRune(address, ':')
|
||||
link.Protocol = address[:pos]
|
||||
link.Kind = LinkExternal
|
||||
|
||||
if display == "" {
|
||||
link.Display = address[pos+1:]
|
||||
if strings.HasPrefix(link.Display, "//") && len(link.Display) > 2 {
|
||||
link.Display = link.Display[2:]
|
||||
}
|
||||
link.Display += link.Anchor
|
||||
}
|
||||
link.Address = address
|
||||
case strings.HasPrefix(address, "#"):
|
||||
link.Kind = LinkLocalHypha
|
||||
link.Address = util.CanonicalName(hyphaName)
|
||||
link.Anchor = address
|
||||
case strings.HasPrefix(address, "/"):
|
||||
link.Address = address
|
||||
link.Kind = LinkLocalRoot
|
||||
case strings.HasPrefix(address, "./"):
|
||||
link.Kind = LinkLocalHypha
|
||||
link.Address = util.CanonicalName(path.Join(hyphaName, address[2:]))
|
||||
case strings.HasPrefix(address, "../"):
|
||||
link.Kind = LinkLocalHypha
|
||||
link.Address = util.CanonicalName(path.Join(path.Dir(hyphaName), address[3:]))
|
||||
default:
|
||||
link.Kind = LinkLocalHypha
|
||||
link.Address = util.CanonicalName(address)
|
||||
}
|
||||
|
||||
return &link
|
||||
}
|
@ -5,7 +5,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/link"
|
||||
"github.com/bouncepaw/mycomarkup/links"
|
||||
)
|
||||
|
||||
var imgRe = regexp.MustCompile(`^img\s+{`)
|
||||
@ -33,8 +33,8 @@ type Img struct {
|
||||
|
||||
func (img *Img) pushEntry() {
|
||||
if strings.TrimSpace(img.currEntry.path.String()) != "" {
|
||||
img.currEntry.srclink = link.From(img.currEntry.path.String(), "", img.hyphaName)
|
||||
img.currEntry.srclink.DoubtExistence()
|
||||
img.currEntry.srclink = links.From(img.currEntry.path.String(), "", img.hyphaName)
|
||||
// img.currEntry.srclink.DoubtExistence()
|
||||
img.entries = append(img.entries, img.currEntry)
|
||||
img.currEntry = imgEntry{}
|
||||
img.currEntry.path.Reset()
|
||||
@ -164,7 +164,7 @@ func parseDimensions(dimensions string) (sizeW, sizeH string) {
|
||||
func (img *Img) markExistenceOfSrcLinks() {
|
||||
HyphaIterate(func(hn string) {
|
||||
for _, entry := range img.entries {
|
||||
if hn == entry.srclink.Address {
|
||||
if hn == entry.srclink.Address() {
|
||||
entry.srclink.DestinationUnknown = false
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ package markup
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/link"
|
||||
"github.com/bouncepaw/mycomarkup/links"
|
||||
)
|
||||
|
||||
type imgEntry struct {
|
||||
srclink *link.Link
|
||||
srclink *links.Link
|
||||
path strings.Builder
|
||||
sizeW strings.Builder
|
||||
sizeH strings.Builder
|
||||
|
@ -3,7 +3,7 @@ package markup
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/link"
|
||||
"github.com/bouncepaw/mycomarkup/links"
|
||||
)
|
||||
|
||||
// LinkParts determines what href, text and class should resulting <a> have based on mycomarkup's addr, display and hypha name.
|
||||
@ -12,11 +12,11 @@ import (
|
||||
// [[addr|display]]
|
||||
// TODO: deprecate
|
||||
func LinkParts(addr, display, hyphaName string) (href, text, class string) {
|
||||
l := link.From(addr, display, hyphaName)
|
||||
if l.Kind == link.LinkLocalHypha && !HyphaExists(l.Address) {
|
||||
l := links.From(addr, display, hyphaName)
|
||||
if l.OfKind(links.LinkLocalHypha) && !HyphaExists(l.Address()) {
|
||||
l.DestinationUnknown = true
|
||||
}
|
||||
return l.Href(), l.Display, l.Classes()
|
||||
return l.Href(), l.Display(), l.Classes()
|
||||
}
|
||||
|
||||
// Parse markup line starting with "=>" according to wikilink rules.
|
||||
|
@ -3,12 +3,13 @@ package markup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"html"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/link"
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
|
||||
"github.com/bouncepaw/mycomarkup/links"
|
||||
)
|
||||
|
||||
// A Mycomarkup-formatted document
|
||||
@ -83,7 +84,7 @@ func (md *MycoDoc) ogFillVars() *MycoDoc {
|
||||
case Img:
|
||||
if !foundImg && len(v.entries) > 0 {
|
||||
md.firstImageURL = v.entries[0].srclink.ImgSrc()
|
||||
if v.entries[0].srclink.Kind != link.LinkExternal {
|
||||
if !v.entries[0].srclink.OfKind(links.LinkExternal) {
|
||||
md.firstImageURL = cfg.URL + md.firstImageURL
|
||||
}
|
||||
foundImg = true
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/link"
|
||||
"github.com/bouncepaw/mycomarkup/links"
|
||||
)
|
||||
|
||||
// OutLinks returns a channel of names of hyphae this mycodocument links.
|
||||
@ -50,8 +50,8 @@ func extractLinks(html string, ch chan string) {
|
||||
|
||||
func extractImageLinks(img Img, ch chan string) {
|
||||
for _, entry := range img.entries {
|
||||
if entry.srclink.Kind == link.LinkLocalHypha {
|
||||
ch <- entry.srclink.Address
|
||||
if entry.srclink.OfKind(links.LinkLocalHypha) {
|
||||
ch <- entry.srclink.Address()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
// "github.com/bouncepaw/mycorrhiza/util"
|
||||
)
|
||||
|
||||
var tableRe = regexp.MustCompile(`^table\s+{`)
|
||||
|
@ -18,7 +18,7 @@
|
||||
<header>
|
||||
<nav class="header-links main-width">
|
||||
<ul class="header-links__list">
|
||||
{%- for _, link := range util.HeaderLinks -%}
|
||||
{%- for _, link := range cfg.HeaderLinks -%}
|
||||
<li class="header-links__entry"><a class="header-links__link" href="{%s link.Href %}">{%s link.Display %}</a></li>
|
||||
{%- endfor -%}
|
||||
{%s= UserMenuHTML(u) %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user