summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoah Campbell <noahcampbell@gmail.com>2013-08-13 10:46:05 -0700
committerspf13 <steve.francia@gmail.com>2013-08-17 23:45:03 -0400
commit8eca8f8aa08d5d95386c34979f653a5b5463c8c9 (patch)
tree13f67c8d359beb27bbcb4540d1563d8907bfd8f9
parente66ba5d2a7dd1a043a24bf86a271a5440b7b1385 (diff)
Detect missed index from front matter
-rw-r--r--hugolib/indexing_test.go18
-rw-r--r--hugolib/site.go20
2 files changed, 38 insertions, 0 deletions
diff --git a/hugolib/indexing_test.go b/hugolib/indexing_test.go
new file mode 100644
index 000000000..4d7d04f31
--- /dev/null
+++ b/hugolib/indexing_test.go
@@ -0,0 +1,18 @@
+package hugolib
+
+import (
+ "testing"
+ "strings"
+)
+
+func TestSitePossibleIndexes(t *testing.T) {
+ site := new(Site)
+ page, _ := ReadFrom(strings.NewReader(PAGE_YAML_WITH_INDEXES_A), "path/to/page")
+ site.Pages = append(site.Pages, page)
+ indexes := site.possibleIndexes()
+ if !compareStringSlice(indexes, []string{"tags", "categories"}) {
+ t.Fatalf("possible indexes do not match [tags categories]. Got: %s", indexes)
+ }
+}
+
+
diff --git a/hugolib/site.go b/hugolib/site.go
index 966208f92..5011cf6b2 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -390,6 +390,26 @@ func (s *Site) BuildSiteMeta() (err error) {
return
}
+func (s *Site) possibleIndexes() (indexes []string) {
+ for _, p := range s.Pages {
+ for k, _ := range p.Params {
+ if !inStringArray(indexes, k) {
+ indexes = append(indexes, k)
+ }
+ }
+ }
+ return
+}
+
+func inStringArray(arr []string, el string) bool {
+ for _, v := range arr {
+ if v == el {
+ return true
+ }
+ }
+ return false
+}
+
func (s *Site) RenderAliases() error {
for i, p := range s.Pages {
for _, a := range p.Aliases {