mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-05-07 00:54:06 +00:00
Fix link resolution in some places
This commit is contained in:
parent
afba9b597a
commit
2b14fa8de1
4
go.mod
4
go.mod
@ -3,7 +3,7 @@ module github.com/bouncepaw/mycorrhiza
|
|||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bouncepaw/mycomarkup/v5 v5.0.1
|
github.com/bouncepaw/mycomarkup/v5 v5.0.2
|
||||||
github.com/go-ini/ini v1.63.2
|
github.com/go-ini/ini v1.63.2
|
||||||
github.com/gorilla/feeds v1.1.1
|
github.com/gorilla/feeds v1.1.1
|
||||||
github.com/gorilla/mux v1.8.0
|
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,
|
// Use this trick to test local Mycomarkup changes, replace the path with yours,
|
||||||
// but do not commit the change to the path:
|
// but do not commit the change to the path:
|
||||||
// replace github.com/bouncepaw/mycomarkup/v5 v5.0.1 => "/Users/bouncepaw/GolandProjects/mycomarkup"
|
// replace github.com/bouncepaw/mycomarkup/v5 v5.0.2 => "/Users/bouncepaw/GolandProjects/mycomarkup"
|
||||||
|
|
||||||
// Use this utility every time Mycomarkup gets a major update:
|
// Use this utility every time Mycomarkup gets a major update:
|
||||||
// https://github.com/marwan-at-work/mod
|
// https://github.com/marwan-at-work/mod
|
||||||
|
4
go.sum
4
go.sum
@ -1,7 +1,7 @@
|
|||||||
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
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/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||||
github.com/bouncepaw/mycomarkup/v5 v5.0.1 h1:FTSsyhvw3KRfpZTF4GkA033qtdf1uTzDLaPO7A2NZQY=
|
github.com/bouncepaw/mycomarkup/v5 v5.0.2 h1:QOO+L54OabPLtPQAFlqAQA8c/jQS6TGj0l6bzrnoICo=
|
||||||
github.com/bouncepaw/mycomarkup/v5 v5.0.1/go.mod h1:jyB/vxKe3X8SsN7FjjPf24IZwFM/H1C4LNvQ5UyXwjU=
|
github.com/bouncepaw/mycomarkup/v5 v5.0.2/go.mod h1:jyB/vxKe3X8SsN7FjjPf24IZwFM/H1C4LNvQ5UyXwjU=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-ini/ini v1.63.2 h1:kwN3umicd2HF3Tgvap4um1ZG52/WyKT9GGdPx0CJk6Y=
|
github.com/go-ini/ini v1.63.2 h1:kwN3umicd2HF3Tgvap4um1ZG52/WyKT9GGdPx0CJk6Y=
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
package cfg
|
package shroom
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bouncepaw/mycomarkup/v5"
|
"github.com/bouncepaw/mycomarkup/v5"
|
||||||
"github.com/bouncepaw/mycomarkup/v5/blocks"
|
"github.com/bouncepaw/mycomarkup/v5/blocks"
|
||||||
"github.com/bouncepaw/mycomarkup/v5/mycocontext"
|
"github.com/bouncepaw/mycomarkup/v5/mycocontext"
|
||||||
"github.com/bouncepaw/mycomarkup/v5/options"
|
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HeaderLinks is a list off current header links. Feel free to iterate it directly but do not modify it by yourself. Call ParseHeaderLinks if you need to set new header links.
|
|
||||||
var HeaderLinks []HeaderLink
|
|
||||||
|
|
||||||
// SetDefaultHeaderLinks sets the header links to the default list of: home hypha, recent changes, hyphae list, random hypha.
|
// SetDefaultHeaderLinks sets the header links to the default list of: home hypha, recent changes, hyphae list, random hypha.
|
||||||
func SetDefaultHeaderLinks() {
|
func SetDefaultHeaderLinks() {
|
||||||
HeaderLinks = []HeaderLink{
|
viewutil.HeaderLinks = []viewutil.HeaderLink{
|
||||||
{"/recent-changes", "Recent changes"},
|
{"/recent-changes", "Recent changes"},
|
||||||
{"/list", "All hyphae"},
|
{"/list", "All hyphae"},
|
||||||
{"/random", "Random"},
|
{"/random", "Random"},
|
||||||
@ -23,14 +20,14 @@ func SetDefaultHeaderLinks() {
|
|||||||
|
|
||||||
// ParseHeaderLinks extracts all rocketlinks from the given text and saves them as header links.
|
// ParseHeaderLinks extracts all rocketlinks from the given text and saves them as header links.
|
||||||
func ParseHeaderLinks(text string) {
|
func ParseHeaderLinks(text string) {
|
||||||
HeaderLinks = []HeaderLink{}
|
viewutil.HeaderLinks = []viewutil.HeaderLink{}
|
||||||
ctx, _ := mycocontext.ContextFromStringInput(text, options.Options{}.FillTheRest())
|
ctx, _ := mycocontext.ContextFromStringInput(text, MarkupOptions(""))
|
||||||
// We call for side-effects
|
// We call for side-effects
|
||||||
_ = mycomarkup.BlockTree(ctx, func(block blocks.Block) {
|
_ = mycomarkup.BlockTree(ctx, func(block blocks.Block) {
|
||||||
switch launchpad := block.(type) {
|
switch launchpad := block.(type) {
|
||||||
case blocks.LaunchPad:
|
case blocks.LaunchPad:
|
||||||
for _, rocket := range launchpad.Rockets {
|
for _, rocket := range launchpad.Rockets {
|
||||||
HeaderLinks = append(HeaderLinks, HeaderLink{
|
viewutil.HeaderLinks = append(viewutil.HeaderLinks, viewutil.HeaderLink{
|
||||||
Href: rocket.LinkHref(ctx),
|
Href: rocket.LinkHref(ctx),
|
||||||
Display: rocket.DisplayedText(),
|
Display: rocket.DisplayedText(),
|
||||||
})
|
})
|
||||||
@ -38,11 +35,3 @@ func ParseHeaderLinks(text string) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// HeaderLink represents a header link. Header links are the links shown in the top gray bar.
|
|
||||||
type HeaderLink struct {
|
|
||||||
// Href is the URL of the link. It goes <a href="here">...</a>.
|
|
||||||
Href string
|
|
||||||
// Display is what is shown when the link is rendered. It goes <a href="...">here</a>.
|
|
||||||
Display string
|
|
||||||
}
|
|
@ -40,14 +40,14 @@ func FetchTextFile(h hyphae.Hypha) (string, error) {
|
|||||||
func SetHeaderLinks() {
|
func SetHeaderLinks() {
|
||||||
switch userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha).(type) {
|
switch userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha).(type) {
|
||||||
case *hyphae.EmptyHypha:
|
case *hyphae.EmptyHypha:
|
||||||
cfg.SetDefaultHeaderLinks()
|
SetDefaultHeaderLinks()
|
||||||
case hyphae.ExistingHypha:
|
case hyphae.ExistingHypha:
|
||||||
contents, err := os.ReadFile(userLinksHypha.TextFilePath())
|
contents, err := os.ReadFile(userLinksHypha.TextFilePath())
|
||||||
if err != nil || len(contents) == 0 {
|
if err != nil || len(contents) == 0 {
|
||||||
cfg.SetDefaultHeaderLinks()
|
SetDefaultHeaderLinks()
|
||||||
} else {
|
} else {
|
||||||
text := string(contents)
|
text := string(contents)
|
||||||
cfg.ParseHeaderLinks(text)
|
ParseHeaderLinks(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,14 +88,14 @@ func localizedBaseWithWeirdBody(meta Meta) *template.Template {
|
|||||||
type BaseData struct {
|
type BaseData struct {
|
||||||
Meta Meta
|
Meta Meta
|
||||||
HeadElements []string
|
HeadElements []string
|
||||||
HeaderLinks []cfg.HeaderLink
|
HeaderLinks []HeaderLink
|
||||||
CommonScripts []string
|
CommonScripts []string
|
||||||
Addr string
|
Addr string
|
||||||
Title string // TODO: remove
|
Title string // TODO: remove
|
||||||
Body string // TODO: remove
|
Body string // TODO: remove
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bd *BaseData) withBaseValues(meta Meta, headerLinks []cfg.HeaderLink, commonScripts []string) {
|
func (bd *BaseData) withBaseValues(meta Meta, headerLinks []HeaderLink, commonScripts []string) {
|
||||||
bd.Meta = meta
|
bd.Meta = meta
|
||||||
bd.HeaderLinks = headerLinks
|
bd.HeaderLinks = headerLinks
|
||||||
bd.CommonScripts = commonScripts
|
bd.CommonScripts = commonScripts
|
||||||
@ -111,7 +111,7 @@ func Base(meta Meta, title, body string, headElements ...string) string {
|
|||||||
Meta: meta,
|
Meta: meta,
|
||||||
Title: title,
|
Title: title,
|
||||||
HeadElements: headElements,
|
HeadElements: headElements,
|
||||||
HeaderLinks: cfg.HeaderLinks,
|
HeaderLinks: HeaderLinks,
|
||||||
CommonScripts: cfg.CommonScripts,
|
CommonScripts: cfg.CommonScripts,
|
||||||
Body: body,
|
Body: body,
|
||||||
})
|
})
|
||||||
@ -136,10 +136,21 @@ func copyRuWith(fsys fs.FS, f string) *template.Template {
|
|||||||
|
|
||||||
// ExecutePage executes template page in the given chain with the given data that has BaseData nested. It also sets some common BaseData fields
|
// ExecutePage executes template page in the given chain with the given data that has BaseData nested. It also sets some common BaseData fields
|
||||||
func ExecutePage(meta Meta, chain Chain, data interface {
|
func ExecutePage(meta Meta, chain Chain, data interface {
|
||||||
withBaseValues(meta Meta, headerLinks []cfg.HeaderLink, commonScripts []string)
|
withBaseValues(meta Meta, headerLinks []HeaderLink, commonScripts []string)
|
||||||
}) {
|
}) {
|
||||||
data.withBaseValues(meta, cfg.HeaderLinks, cfg.CommonScripts)
|
data.withBaseValues(meta, HeaderLinks, cfg.CommonScripts)
|
||||||
if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", data); err != nil {
|
if err := chain.Get(meta).ExecuteTemplate(meta.W, "page", data); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HeaderLinks is a list off current header links. Feel free to iterate it directly but do not modify it by yourself. Call ParseHeaderLinks if you need to set new header links.
|
||||||
|
var HeaderLinks []HeaderLink
|
||||||
|
|
||||||
|
// HeaderLink represents a header link. Header links are the links shown in the top gray bar.
|
||||||
|
type HeaderLink struct {
|
||||||
|
// Href is the URL of the link. It goes <a href="here">...</a>.
|
||||||
|
Href string
|
||||||
|
// Display is what is shown when the link is rendered. It goes <a href="...">here</a>.
|
||||||
|
Display string
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user