mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
hugolib: Fix output format handling of mix cased page kinds
Fixes #4528
This commit is contained in:
@@ -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)]
|
||||
}
|
||||
|
@@ -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"))
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user