mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 22:51:32 -05:00
Detect missed index from front matter
This commit is contained in:
parent
e66ba5d2a7
commit
8eca8f8aa0
2 changed files with 38 additions and 0 deletions
18
hugolib/indexing_test.go
Normal file
18
hugolib/indexing_test.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue