1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00
mycorrhiza/cfg/header_links.go

49 lines
1.6 KiB
Go
Raw Normal View History

2021-05-11 08:33:00 +00:00
package cfg
import (
"github.com/bouncepaw/mycomarkup/v5"
"github.com/bouncepaw/mycomarkup/v5/blocks"
"github.com/bouncepaw/mycomarkup/v5/mycocontext"
"github.com/bouncepaw/mycomarkup/v5/options"
2021-05-11 08:33:00 +00:00
)
// 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{
{"/recent-changes", "Recent changes"},
{"/list", "All hyphae"},
{"/random", "Random"},
2021-07-24 19:16:49 +00:00
{"/help", "Help"},
{"/category", "Categories"},
2021-05-11 08:33:00 +00:00
}
}
// ParseHeaderLinks extracts all rocketlinks from the given text and saves them as header links.
func ParseHeaderLinks(text string) {
2022-01-08 21:16:09 +00:00
HeaderLinks = []HeaderLink{}
2022-04-07 17:17:59 +00:00
ctx, _ := mycocontext.ContextFromStringInput(text, options.Options{}.FillTheRest())
// 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{
Href: rocket.LinkHref(ctx),
Display: rocket.DisplayedText(),
})
}
2021-05-11 08:33:00 +00:00
}
})
2021-05-11 08:33:00 +00:00
}
// 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
}