From c58521b3becd016736a35019511934fb6f0826fb Mon Sep 17 00:00:00 2001 From: Thomas Freudenberg Date: Sun, 15 Nov 2015 14:07:54 +0100 Subject: [PATCH 1/2] added option only_frontmatter_categories --- .../Context/SiteContextGenerator.cs | 20 +++++++-- .../Context/SiteContextGeneratorTests.cs | 16 ++++++- .../Templating/Jekyll/LiquidEngineTests.cs | 43 +++++++++++++++++++ 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs index 9c7c022a7..ec03df975 100644 --- a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs +++ b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs @@ -290,10 +290,12 @@ private List ResolveCategories(SiteContext context, IDictionary(); - var postPath = page.File.Replace(context.SourceFolder, string.Empty); - string rawCategories = postPath.Replace(fileSystem.Path.GetFileName(page.File), string.Empty).Replace("_posts", string.Empty); - categories.AddRange(rawCategories.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries)); - + if (!IsOnlyFrontmatterCategories(context)) + { + var postPath = page.File.Replace(context.SourceFolder, string.Empty); + string rawCategories = postPath.Replace(fileSystem.Path.GetFileName(page.File), string.Empty).Replace("_posts", string.Empty); + categories.AddRange(rawCategories.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries)); + } if (header.ContainsKey("categories") && header["categories"] is IEnumerable) { categories.AddRange((IEnumerable)header["categories"]); @@ -306,6 +308,16 @@ private List ResolveCategories(SiteContext context, IDictionary + { + private SiteContext Context; + private const string ContentWithCategory = "---\r\n category: mycategory \r\n permalink: /:categories/:year/:month/:day/:title.html \r\n---\r\n{{ site.categories[0].name }}"; + private const string ExpectedPageContent = "

mycategory

"; + + public override LiquidEngine Given() + { + return new LiquidEngine(); + } + + public override void When() + { + FileSystem.AddFile(@"C:\website\_config.yml", new MockFileData(@"only_frontmatter_categories: true")); + FileSystem.AddFile(@"C:\website\oh\my\_posts\2015-02-02-post.md", new MockFileData(ContentWithCategory)); + var generator = GetSiteContextGenerator(FileSystem); + Context = generator.BuildContext(@"C:\website\", @"C:\website\_site\", false); + Subject.FileSystem = FileSystem; + Subject.Process(Context); + } + + [Fact] + public void Layout_With_Bad_Header_Should_Not_Throw_Exception() + { + Assert.Equal(Context.Posts.Count, 1); + var categories = Context.Posts[0].Categories.ToList(); + Assert.Equal(categories.Count, 1); + Assert.Equal(categories[0], "mycategory"); + } + + [Fact] + public void The_permalink_should_use_all_categories() + { + Assert.True(FileSystem.File.Exists(@"C:\website\_site\mycategory\2015\02\02\post.html")); + } + + [Fact] + public void The_first_alphabetically_category_must_appear_in_the_content() + { + Assert.Equal(ExpectedPageContent, FileSystem.File.ReadAllText(@"C:\website\_site\mycategory\2015\02\02\post.html").RemoveWhiteSpace()); + } + } + public class Given_Engine_Has_Custom_Tag : BakingEnvironment { private const string PageContent = "---\r\n \r\n---\r\n{% custom %}"; From 75718678a94ba9765599066c24c7173874793a1a Mon Sep 17 00:00:00 2001 From: Thomas Freudenberg Date: Sun, 15 Nov 2015 14:15:16 +0100 Subject: [PATCH 2/2] updated release notes --- ReleaseNotes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index b2a3d7c93..641dd9b3c 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -30,6 +30,7 @@ All existing plugins must be recompiled with referencing only Pretzel.Logic. - [#253](https://github.com/Code52/pretzel/pull/253) - Run on Mono contributed by Thiago 'Jedi' Abreu ([thiagoabreu](https://github.com/thiagoabreu)) - [#259](https://github.com/Code52/pretzel/pull/259) - Changed date guessing heuristic to use last modification time of posts instead of current time, if no better data is available. contributed by Gábor Gergely ([kodfodrasz](https://github.com/kodfodrasz)) - [#260](https://github.com/Code52/pretzel/pull/260) - Refactor logging contributed by Gábor Gergely ([kodfodrasz](https://github.com/kodfodrasz)) +- [#274](https://github.com/Code52/pretzel/pull/274) - Added option to only use categories found in posts's frontmatter by Thomas Freudenberg ([thoemmi](https://github.com/thoemmi)) ## Fixes - [#198](https://github.com/Code52/pretzel/issues/198) - Liquid tag/filter with underscore doesn't works in markdown files