Skip to content

Instantly share code, notes, and snippets.

@jackcallister
Last active September 13, 2019 09:13
Show Gist options
  • Save jackcallister/3d36af46d7f906bd7ea92c761bf5d9b1 to your computer and use it in GitHub Desktop.
Save jackcallister/3d36af46d7f906bd7ea92c761bf5d9b1 to your computer and use it in GitHub Desktop.
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