diff --git a/go.mod b/go.mod
index f8761a6..b162016 100644
--- a/go.mod
+++ b/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
diff --git a/go.sum b/go.sum
index 92ea874..7376950 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/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=
diff --git a/cfg/header_links.go b/shroom/header_links.go
similarity index 53%
rename from cfg/header_links.go
rename to shroom/header_links.go
index 147b0bc..a4c6065 100644
--- a/cfg/header_links.go
+++ b/shroom/header_links.go
@@ -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 ....
- Href string
- // Display is what is shown when the link is rendered. It goes here.
- Display string
-}
diff --git a/shroom/view.go b/shroom/view.go
index c1ef63b..2f0e94d 100644
--- a/shroom/view.go
+++ b/shroom/view.go
@@ -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)
}
}
}
diff --git a/viewutil/viewutil.go b/viewutil/viewutil.go
index 3fff9a6..c22de16 100644
--- a/viewutil/viewutil.go
+++ b/viewutil/viewutil.go
@@ -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 ....
+ Href string
+ // Display is what is shown when the link is rendered. It goes here.
+ Display string
+}