From 1fb409b4a806526a1e0654c6095798f6b5e6ddb7 Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Wed, 26 Jul 2017 12:47:31 -0400 Subject: [PATCH] more accurate file change detection --- site/rebuild.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/site/rebuild.go b/site/rebuild.go index d7c3e12..5351a61 100644 --- a/site/rebuild.go +++ b/site/rebuild.go @@ -3,6 +3,7 @@ package site import ( "fmt" "os" + "path/filepath" "strings" "time" @@ -129,7 +130,7 @@ loop: switch { case s.config.IsConfigPath(path): // break - case s.Exclude(path): + case !s.fileAffectsBuild(path): continue loop case seen[path]: continue loop @@ -140,6 +141,25 @@ loop: return result } +// Returns true if the file or a parent directory is excluded. +// Cf. Site.Exclude. +func (s *Site) fileAffectsBuild(rel string) bool { + for rel != "" { + switch { + case rel == ".": + return true + case utils.MatchList(s.config.Include, rel): + return true + case utils.MatchList(s.config.Exclude, rel): + return false + case strings.HasPrefix(rel, "."): + return false + } + rel = filepath.Dir(rel) + } + return true +} + // returns true if changes to the site-relative paths invalidate doc func (s *Site) invalidatesDoc(paths map[string]bool, d pages.Document) bool { rel := utils.MustRel(s.SourceDir(), d.SourcePath())