mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-04 18:19:54 +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
|
||||
|
||||
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/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/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:
|
||||
// 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.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/bouncepaw/mycomarkup/v5 v5.0.1 h1:FTSsyhvw3KRfpZTF4GkA033qtdf1uTzDLaPO7A2NZQY=
|
||||
github.com/bouncepaw/mycomarkup/v5 v5.0.1/go.mod h1:jyB/vxKe3X8SsN7FjjPf24IZwFM/H1C4LNvQ5UyXwjU=
|
||||
github.com/bouncepaw/mycomarkup/v5 v5.0.2 h1:QOO+L54OabPLtPQAFlqAQA8c/jQS6TGj0l6bzrnoICo=
|
||||
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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-ini/ini v1.63.2 h1:kwN3umicd2HF3Tgvap4um1ZG52/WyKT9GGdPx0CJk6Y=
|
||||
|
@ -1,18 +1,15 @@
|
||||
package cfg
|
||||
package shroom
|
||||
|
||||
import (
|
||||
"github.com/bouncepaw/mycomarkup/v5"
|
||||
"github.com/bouncepaw/mycomarkup/v5/blocks"
|
||||
"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.
|
||||
func SetDefaultHeaderLinks() {
|
||||
HeaderLinks = []HeaderLink{
|
||||
viewutil.HeaderLinks = []viewutil.HeaderLink{
|
||||
{"/recent-changes", "Recent changes"},
|
||||
{"/list", "All hyphae"},
|
||||
{"/random", "Random"},
|
||||
@ -23,14 +20,14 @@ func SetDefaultHeaderLinks() {
|
||||
|
||||
// ParseHeaderLinks extracts all rocketlinks from the given text and saves them as header links.
|
||||
func ParseHeaderLinks(text string) {
|
||||
HeaderLinks = []HeaderLink{}
|
||||
ctx, _ := mycocontext.ContextFromStringInput(text, options.Options{}.FillTheRest())
|
||||
viewutil.HeaderLinks = []viewutil.HeaderLink{}
|
||||
ctx, _ := mycocontext.ContextFromStringInput(text, MarkupOptions(""))
|
||||
// We call for side-effects
|
||||
_ = mycomarkup.BlockTree(ctx, func(block blocks.Block) {
|
||||
switch launchpad := block.(type) {
|
||||
case blocks.LaunchPad:
|
||||
for _, rocket := range launchpad.Rockets {
|
||||
HeaderLinks = append(HeaderLinks, HeaderLink{
|
||||
viewutil.HeaderLinks = append(viewutil.HeaderLinks, viewutil.HeaderLink{
|
||||
Href: rocket.LinkHref(ctx),
|
||||
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() {
|
||||
switch userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha).(type) {
|
||||
case *hyphae.EmptyHypha:
|
||||
cfg.SetDefaultHeaderLinks()
|
||||
SetDefaultHeaderLinks()
|
||||
case hyphae.ExistingHypha:
|
||||
contents, err := os.ReadFile(userLinksHypha.TextFilePath())
|
||||
if err != nil || len(contents) == 0 {
|
||||
cfg.SetDefaultHeaderLinks()
|
||||
SetDefaultHeaderLinks()
|
||||
} else {
|
||||
text := string(contents)
|
||||
cfg.ParseHeaderLinks(text)
|
||||
ParseHeaderLinks(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,14 +88,14 @@ func localizedBaseWithWeirdBody(meta Meta) *template.Template {
|
||||
type BaseData struct {
|
||||
Meta Meta
|
||||
HeadElements []string
|
||||
HeaderLinks []cfg.HeaderLink
|
||||
HeaderLinks []HeaderLink
|
||||
CommonScripts []string
|
||||
Addr string
|
||||
Title 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.HeaderLinks = headerLinks
|
||||
bd.CommonScripts = commonScripts
|
||||
@ -111,7 +111,7 @@ func Base(meta Meta, title, body string, headElements ...string) string {
|
||||
Meta: meta,
|
||||
Title: title,
|
||||
HeadElements: headElements,
|
||||
HeaderLinks: cfg.HeaderLinks,
|
||||
HeaderLinks: HeaderLinks,
|
||||
CommonScripts: cfg.CommonScripts,
|
||||
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
|
||||
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 {
|
||||
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…
Reference in New Issue
Block a user