1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-27 02:54:45 +01:00

Match include, exclude on globs

This commit is contained in:
Oliver Steele 2017-07-14 11:38:14 -04:00
parent 2f3ed9a9d1
commit a6711722f1
2 changed files with 17 additions and 5 deletions

View File

@ -192,16 +192,13 @@ func (s *Site) URLPage(urlpath string) (p pages.Document, found bool) {
// Exclude returns a boolean indicating that the site excludes a file.
func (s *Site) Exclude(path string) bool {
// TODO exclude based on glob, not exact match
inclusionMap := utils.StringArrayToMap(s.config.Include)
exclusionMap := utils.StringArrayToMap(s.config.Exclude)
base := filepath.Base(path)
switch {
case path == ".":
return false
case inclusionMap[base]:
case utils.MatchList(s.config.Include, base):
return false
case exclusionMap[base]:
case utils.MatchList(s.config.Exclude, base):
return true
case strings.HasPrefix(base, "."), strings.HasPrefix(base, "_"):
return true

View File

@ -15,6 +15,21 @@ func FilenameDate(s string) (time.Time, bool) {
return t, err == nil
}
// MatchList reports whether any glob pattern matches the path.
// It panics with ErrBadPattern if any pattern is malformed.
func MatchList(patterns []string, name string) bool {
for _, p := range patterns {
match, err := filepath.Match(p, name)
if err != nil {
panic(err)
}
if match {
return true
}
}
return false
}
// MustAbs is like filepath.Abs, but panics instead of returning an error.
func MustAbs(path string) string {
abs, err := filepath.Abs(path)