Last active
September 13, 2019 09:13
-
-
Save jackcallister/3d36af46d7f906bd7ea92c761bf5d9b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
crumbs := func(c *leaf.Compiler) { | |
c.TemplateFuncs["Breadcrumbs"] = func(d leaf.Document) template.HTML { | |
var links []string | |
var link string | |
var anchor string | |
crumbs := strings.Split(d.Anchor, string(os.PathSeparator)) | |
for idx, _ := range crumbs { | |
if idx == 0 { | |
anchor = "/" | |
} else { | |
anchor = strings.Join(crumbs[0:idx+1], "/") | |
} | |
doc := WhereAnchorIs(c.Documents, anchor) | |
link = fmt.Sprintf("<a href='%s'>%s</a>", doc.Anchor, doc.Title) | |
if idx == len(crumbs) - 1 { | |
link = doc.Title | |
} | |
links = append(links, link) | |
} | |
return template.HTML(strings.Join(links, " / ")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment