mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	
				
					committed by
					
						
						Bjørn Erik Pedersen
					
				
			
			
				
	
			
			
			
						parent
						
							a7d182cea1
						
					
				
				
					commit
					d1109f590a
				
			@@ -17,11 +17,10 @@ import (
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
 | 
			
		||||
	"github.com/gohugoio/hugo/common/maps"
 | 
			
		||||
	"github.com/gohugoio/hugo/hugofs/glob"
 | 
			
		||||
	"github.com/mitchellh/mapstructure"
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// A PageMatcher can be used to match a Page with Glob patterns.
 | 
			
		||||
@@ -114,8 +113,16 @@ func DecodePageMatcher(m interface{}, v *PageMatcher) error {
 | 
			
		||||
 | 
			
		||||
	v.Kind = strings.ToLower(v.Kind)
 | 
			
		||||
	if v.Kind != "" {
 | 
			
		||||
		if _, found := kindMap[v.Kind]; !found {
 | 
			
		||||
			return errors.Errorf("%q is not a valid Page Kind", v.Kind)
 | 
			
		||||
		g, _ := glob.GetGlob(v.Kind)
 | 
			
		||||
		found := false
 | 
			
		||||
		for _, k := range kindMap {
 | 
			
		||||
			if g.Match(k) {
 | 
			
		||||
				found = true
 | 
			
		||||
				break
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if !found {
 | 
			
		||||
			return errors.Errorf("%q did not match a valid Page Kind", v.Kind)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,12 @@ func TestPageMatcher(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	c.Run("Decode", func(c *qt.C) {
 | 
			
		||||
		var v PageMatcher
 | 
			
		||||
		c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "foo"}, &v), qt.Not((qt.IsNil)))
 | 
			
		||||
		c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "foo"}, &v), qt.Not(qt.IsNil))
 | 
			
		||||
		c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "{foo,bar}"}, &v), qt.Not(qt.IsNil))
 | 
			
		||||
		c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "taxonomy"}, &v), qt.IsNil)
 | 
			
		||||
		c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "{taxonomy,foo}"}, &v), qt.IsNil)
 | 
			
		||||
		c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "{taxonomy,term}"}, &v), qt.IsNil)
 | 
			
		||||
		c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "*"}, &v), qt.IsNil)
 | 
			
		||||
		c.Assert(DecodePageMatcher(map[string]interface{}{"kind": "home", "path": filepath.FromSlash("/a/b/**")}, &v), qt.IsNil)
 | 
			
		||||
		c.Assert(v, qt.Equals, PageMatcher{Kind: "home", Path: "/a/b/**"})
 | 
			
		||||
	})
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user