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:
parent
2f3ed9a9d1
commit
a6711722f1
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user