@@ 18,6 18,7 @@ type Page struct {
Title string `yaml:"title"`
Template string `yaml:"template"`
Date time.Time `yaml:"date"`
+ Tags []string `yaml:"tags"`
Draft bool `yaml:"draft"`
Content string `fm:"content"`
UrlFormat string `yaml:"url-format"`
@@ 15,6 15,25 @@ import (
"git.sr.ht/~srivathsan/blaze/config"
)
+func listPages(path string, config *config.BlazeConfig) []*Page {
+ fullpath := filepath.Join(config.ContentDir(), path)
+ pages, err := GetPages(fullpath, config)
+ if err != nil {
+ return nil
+ }
+
+ for _, p := range pages {
+ p.Content = ToHTML(p.Content)
+ }
+
+ // Sort descending order of the date
+ sort.Slice(pages, func(i, j int) bool {
+ return pages[j].Date.Before(pages[i].Date)
+ })
+
+ return pages
+}
+
func getTemplateFuncs(config *config.BlazeConfig) template.FuncMap {
return template.FuncMap{
"isRoot": func(url string) bool {
@@ 35,22 54,18 @@ func getTemplateFuncs(config *config.BlazeConfig) template.FuncMap {
return string(partial)
},
"listPages": func(path string) []*Page {
- fullpath := filepath.Join(config.ContentDir(), path)
- pages, err := GetPages(fullpath, config)
- if err != nil {
- return nil
- }
-
+ return listPages(path, config)
+ },
+ "getTagMap": func(path string) map[string][]*Page {
+ pages := listPages(path, config)
+ tagMap := make(map[string][]*Page)
for _, p := range pages {
- p.Content = ToHTML(p.Content)
+ for _, t := range p.Tags {
+ tagMap[t] = append(tagMap[t], p)
+ }
}
- // Sort descending order of the date
- sort.Slice(pages, func(i, j int) bool {
- return pages[j].Date.Before(pages[i].Date)
- })
-
- return pages
+ return tagMap
},
"escapeHTML": func(content string) string {
return html.EscapeString(content)