-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathApplyLayoutPipeline.cs
More file actions
41 lines (40 loc) · 1.58 KB
/
ApplyLayoutPipeline.cs
File metadata and controls
41 lines (40 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Linq;
using Statiq.Common;
using Statiq.Core;
using Statiq.Feeds;
using Statiq.Handlebars;
namespace site.Pipelines
{
public abstract class ApplyLayoutPipeline : Pipeline
{
protected ApplyLayoutPipeline()
{
PostProcessModules = new ModuleList
{
new SetMetadata("template", Config.FromContext(async ctx => await ctx.Outputs
.FromPipeline(nameof(LayoutPipeline))
.First(x => x.Source.FileName == "layout.hbs")
.GetContentStringAsync())),
new RenderHandlebars("template")
.Configure(async (context, document, handlebars) =>
{
foreach (var partial in context.Outputs
.FromPipeline(nameof(LayoutPipeline)).WhereContainsKey("partial"))
{
handlebars.RegisterTemplate(
partial.GetString("partial"),
await partial.GetContentStringAsync());
}
}).WithModel(Config.FromDocument(async (doc, ctx) => new
{
title = doc.GetString(Keys.Title),
body = await doc.GetContentStringAsync(),
link = ctx.GetLink(doc),
year = ctx.Settings.GetString(FeedKeys.Copyright)
})),
new SetContent(Config.FromDocument(x => x.GetString("template")))
};
}
}
}