diff --git a/site/site_test.go b/site/site_test.go index 074630d..2486a6b 100644 --- a/site/site_test.go +++ b/site/site_test.go @@ -197,7 +197,7 @@ tags: [software] // add a page (no date) content = `--- --- -{% for tag in site.tags %}

{{tag[0]}}

{% for post in tag[1] %} +{% for tag in site.tags | keys | sort %}

{{tag}}

{% for post in site.tags[tag] %} {{post.title}} {% endfor %} {% endfor %} diff --git a/templates/filters.go b/templates/filters.go index d08651a..3fd1c93 100644 --- a/templates/filters.go +++ b/templates/filters.go @@ -30,6 +30,7 @@ func loadJekyllFilters(e *liquid.Engine, siteUrl string, includesDir string) { e.RegisterFilter("group_by", groupByFilter) e.RegisterFilter("group_by_exp", groupByExpFilter) e.RegisterFilter("sort", sortFilter) + e.RegisterFilter("keys", keysFilter) e.RegisterFilter("where", whereFilter) e.RegisterFilter("where_exp", whereExpFilter) e.RegisterFilter("xml_escape", xml.Marshal) @@ -144,6 +145,16 @@ func groupByFilter(array []map[string]interface{}, property string) []map[string return result } +func keysFilter(m map[string]interface{}) []string { + keys := make([]string, len(m)) + i := 0 + for k := range m { + keys[i] = k + i++ + } + return keys +} + func sortFilter(array []interface{}, key interface{}, nilFirst func(bool) bool) []interface{} { nf := nilFirst(true) result := make([]interface{}, len(array))