diff --git a/src/Pretzel.Logic/Extensibility/IBeforeProcessingTransform.cs b/src/Pretzel.Logic/Extensibility/IBeforeProcessingTransform.cs
new file mode 100644
index 000000000..69c055876
--- /dev/null
+++ b/src/Pretzel.Logic/Extensibility/IBeforeProcessingTransform.cs
@@ -0,0 +1,9 @@
+using System.ComponentModel.Composition;
+using Pretzel.Logic.Templating.Context;
+
+namespace Pretzel.Logic.Extensibility {
+ [InheritedExport]
+ public interface IBeforeProcessingTransform {
+ void Transform(SiteContext context);
+ }
+}
diff --git a/src/Pretzel.Logic/Pretzel.Logic.csproj b/src/Pretzel.Logic/Pretzel.Logic.csproj
index 5a6f1aba8..7a4ff334a 100644
--- a/src/Pretzel.Logic/Pretzel.Logic.csproj
+++ b/src/Pretzel.Logic/Pretzel.Logic.csproj
@@ -102,6 +102,7 @@
+
diff --git a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs
index 7ce95d16b..2237185cf 100644
--- a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs
+++ b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs
@@ -7,6 +7,7 @@
using System.IO.Abstractions;
using System.Linq;
using System.Text;
+using Pretzel.Logic.Extensibility;
namespace Pretzel.Logic.Templating.Context
{
@@ -21,6 +22,9 @@ public class SiteContextGenerator
private readonly LinkHelper linkHelper;
private readonly IConfiguration _config;
+ [ImportMany]
+ public IEnumerable BeforeProcessingTransforms;
+
[ImportingConstructor]
public SiteContextGenerator(IFileSystem fileSystem, LinkHelper linkHelper, IConfiguration config)
{
@@ -58,6 +62,14 @@ public SiteContext BuildContext(string path, string destinationPath, bool includ
context.Pages = BuildPages(_config, context).ToList();
+ if (BeforeProcessingTransforms != null)
+ {
+ foreach (var transform in BeforeProcessingTransforms)
+ {
+ transform.Transform(context);
+ }
+ }
+
return context;
}
finally
diff --git a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs
index 447eb78c3..4522d814e 100644
--- a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs
+++ b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs
@@ -11,6 +11,7 @@
using System.Linq;
using System.Text;
using System.Threading;
+using Pretzel.Logic.Extensibility;
using Xunit;
namespace Pretzel.Tests.Templating.Context
@@ -1079,5 +1080,30 @@ public void permalink_is_well_formatted(string permalink, string expectedUrl, st
var firstPost = siteContext.Posts.First();
Assert.Equal(expectedUrl, firstPost.Url);
}
+
+ private class BeforeProcessingTransformMock : IBeforeProcessingTransform
+ {
+ public int PostCount = 0;
+ public void Transform(SiteContext context)
+ {
+ PostCount = context.Posts.Count;
+ }
+ }
+
+ [Fact]
+ public void are_beforeprocessingtransforms_called()
+ {
+ // arrange
+ var pageTransformMock = new BeforeProcessingTransformMock();
+ generator.BeforeProcessingTransforms = new[] { pageTransformMock };
+ fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-SomeFile.md", new MockFileData(ToPageContent("# Some File")));
+ fileSystem.AddFile(@"C:\TestSite\_posts\2012-01-01-AnotherFile.md", new MockFileData(ToPageContent("# Another File")));
+
+ // act
+ generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false);
+
+ // assert
+ Assert.Equal(2, pageTransformMock.PostCount);
+ }
}
}