hugolib: Fix output format handling of mix cased page kinds

Fixes #4528
This commit is contained in:
Bjørn Erik Pedersen
2019-08-05 10:19:55 +02:00
parent 9ef4dca361
commit de87624241
5 changed files with 85 additions and 23 deletions

View File

@@ -13,6 +13,8 @@
package page
import "strings"
const (
KindPage = "page"
@@ -23,3 +25,16 @@ const (
KindTaxonomy = "taxonomy"
KindTaxonomyTerm = "taxonomyTerm"
)
var kindMap = map[string]string{
strings.ToLower(KindPage): KindPage,
strings.ToLower(KindHome): KindHome,
strings.ToLower(KindSection): KindSection,
strings.ToLower(KindTaxonomy): KindTaxonomy,
strings.ToLower(KindTaxonomyTerm): KindTaxonomyTerm,
}
// GetKind gets the page kind given a string, empty if not found.
func GetKind(s string) string {
return kindMap[strings.ToLower(s)]
}

View File

@@ -28,4 +28,10 @@ func TestKind(t *testing.T) {
require.Equal(t, "taxonomy", KindTaxonomy)
require.Equal(t, "taxonomyTerm", KindTaxonomyTerm)
require.Equal(t, KindTaxonomyTerm, GetKind("TAXONOMYTERM"))
require.Equal(t, KindTaxonomy, GetKind("Taxonomy"))
require.Equal(t, KindPage, GetKind("Page"))
require.Equal(t, KindHome, GetKind("Home"))
require.Equal(t, KindSection, GetKind("SEction"))
}