diff --git a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs index 442cdd7be..471d8f762 100644 --- a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs +++ b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs @@ -44,20 +44,13 @@ public SiteContext BuildContext(string path, string destinationPath, bool includ config.Add("permalink", "date"); } - if (config.ContainsKey("pretzel")) + if (config.ContainsKey("include")) { - var pretzelSettings = config["pretzel"] as Dictionary; - if (pretzelSettings != null) - { - if (pretzelSettings.ContainsKey("include") && includes.Count == 0) - { - includes.AddRange((IEnumerable)pretzelSettings["include"]); - } - if (pretzelSettings.ContainsKey("exclude") && excludes.Count == 0) - { - excludes.AddRange((IEnumerable)pretzelSettings["exclude"]); - } - } + includes.AddRange((IEnumerable)config["include"]); + } + if (config.ContainsKey("exclude")) + { + excludes.AddRange((IEnumerable)config["exclude"]); } var context = new SiteContext @@ -193,14 +186,24 @@ private bool ContainsYamlFrontMatter(string file) return postFirstLine != null && postFirstLine.StartsWith("---"); } + private bool IsExcludedPath(string relativePath) + { + return excludes.Contains(relativePath) || excludes.Any(e => relativePath.StartsWith(e)); + } + + private bool IsIncludedPath(string relativePath) + { + return includes.Contains(relativePath) || includes.Any(e => relativePath.StartsWith(e)); + } + public bool CanBeIncluded(string relativePath) { - if (excludes.Count > 0 && excludes.Contains(relativePath)) + if (excludes.Count > 0 && IsExcludedPath(relativePath)) { return false; } - if (includes.Count > 0 && includes.Contains(relativePath)) + if (includes.Count > 0 && IsIncludedPath(relativePath)) { return true; } diff --git a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs index b96bfabad..7b631e91e 100644 --- a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs +++ b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs @@ -399,8 +399,7 @@ public void CanBeIncluded_Scenarios_Include() // arrange Func function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: - include: [_folder, .something-else, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] +include: [_folder, .something-else, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] ---")); // act var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); @@ -418,6 +417,8 @@ public void CanBeIncluded_Scenarios_Include() Assert.False(function("some-file.TMP")); Assert.True(function("another-file.bar")); + Assert.True(function("_folder\file.txt")); + Assert.True(function(@"test\somefile.txt")); Assert.True(function(@"subfolder\childfolder")); Assert.True(function(@"anotherfolder\tempfile.tmp")); @@ -429,14 +430,14 @@ public void CanBeIncluded_Scenarios_Exclude() // arrange Func function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: - exclude: [folder, .htaccess, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] +exclude: [folder, .htaccess, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] ---")); // act var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.False(function("folder")); + Assert.False(function("folder\file.txt")); Assert.False(function("_folder")); // .htaccess is excluded @@ -459,9 +460,8 @@ public void CanBeIncluded_Scenarios_IncludeExclude() // arrange Func function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: - include: [_folder, .something-else] - exclude: [folder, test\somefile.txt] +include: [_folder, .something-else] +exclude: [folder, test\somefile.txt] ---")); // act var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false);