diff --git a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs index ec03df975..83069ebdd 100644 --- a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs +++ b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs @@ -184,12 +184,12 @@ private bool ContainsYamlFrontMatter(string file) return postFirstLine != null && postFirstLine.StartsWith("---"); } - private bool IsExcludedPath(string relativePath) + public bool IsExcludedPath(string relativePath) { return excludes.Contains(relativePath) || excludes.Any(e => relativePath.StartsWith(e)); } - private bool IsIncludedPath(string relativePath) + public bool IsIncludedPath(string relativePath) { return includes.Contains(relativePath) || includes.Any(e => relativePath.StartsWith(e)); } diff --git a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs index 8df436851..fca1e9197 100644 --- a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs +++ b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs @@ -435,6 +435,66 @@ public void CanBeIncluded_Scenarios_IncludeExclude() Assert.True(function(@"anotherfolder\textfile.txt")); } + [Fact] + public void SiteContextGenerator_IsIncludedPath() { + // arrange + var fs = new MockFileSystem(new Dictionary()); + var gen = new SiteContextGenerator(fs, new LinkHelper()); + Func function = gen.IsIncludedPath; + fs.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- +include: [_folder, .something-else] +exclude: [folder, test\somefile.txt, .git] +---")); + + // act + var siteContext = gen.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); + + // include entires and subentries are included + Assert.True(function("_folder")); + Assert.True(function("_folder/somefile")); + Assert.True(function(".something-else")); + + // exluded entries are not included + Assert.False(function("folder")); + Assert.False(function("folder/somefile")); + Assert.False(function(@"test\somefile.txt")); + Assert.False(function(".git")); + + // other entries are not included + Assert.False(function("test")); + Assert.False(function("asdf")); + } + + [Fact] + public void SiteContextGenerator_IsExcludedPath() { + // arrange + var fs = new MockFileSystem(new Dictionary()); + var gen = new SiteContextGenerator(fs, new LinkHelper()); + Func function = gen.IsExcludedPath; + fs.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- +include: [_folder, .something-else] +exclude: [folder, test\somefile.txt, .git] +---")); + + // act + var siteContext = gen.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); + + // include entires and subentries are not excluded + Assert.False(function("_folder")); + Assert.False(function("_folder/somefile")); + Assert.False(function(".something-else")); + + // exluded entries are exluded + Assert.True(function("folder")); + Assert.True(function("folder/somefile")); + Assert.True(function(@"test\somefile.txt")); + Assert.True(function(".git")); + + // other entries are not excluded + Assert.False(function("test")); + Assert.False(function("asdf")); + } + [Fact] public void permalink_with_numbered_category() { diff --git a/src/Pretzel/Commands/TasteCommand.cs b/src/Pretzel/Commands/TasteCommand.cs index f64c86085..4182c32f1 100644 --- a/src/Pretzel/Commands/TasteCommand.cs +++ b/src/Pretzel/Commands/TasteCommand.cs @@ -118,6 +118,15 @@ public void Execute(IEnumerable arguments) private void WatcherOnChanged(string file) { + if(file.StartsWith(parameters.Path)) + { + var relativeFile = file.Substring(parameters.Path.Length).ToRelativeFile(); + if (Generator.IsExcludedPath(relativeFile)) + { + return; + } + } + Tracing.Info(string.Format("File change: {0}", file)); var context = Generator.BuildContext(parameters.Path, parameters.DestinationPath, parameters.IncludeDrafts);