-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomePipeline.cs
60 lines (55 loc) · 3.28 KB
/
HomePipeline.cs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Statiq.Common;
using Statiq.Core;
using Statiq.Razor;
using Statiq.Yaml;
namespace StatiqTutorial
{
/// <summary>
/// Pipeline responsible for getting and processing home markdown file from the input directory into the Home HTML document using Razor template.
/// </summary>
public class HomePipeline : Pipeline
{
public HomePipeline()
{
InputModules = new ModuleList
{
// Reads the content of files from the file system into the content of new documents.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/core/Statiq.Core/Modules/IO/ReadFiles.cs">ReadFiles</see>
new ReadFiles("content/home.md")
};
ProcessModules = new ModuleList {
// Extracts the first part of the content for each document and sends it to a child module for processing.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/core/Statiq.Core/Modules/Control/ExtractFrontMatter.cs">ExtractFrontMatter</see>
new ExtractFrontMatter(
// Parses YAML content for each input document and stores the result in it's metadata.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/extensions/Statiq.Yaml/ParseYaml.cs">ParseYaml</see>
new ParseYaml()
),
// Loads Razor template to IDocument content.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/core/Statiq.Core/Modules/Content/MergeContent.cs">MergeContent</see>.
// <see href="https://statiq.dev/web/content-and-data/content/">Content propery of IDocument</see>
new MergeContent(new ReadFiles(patterns: "Home.cshtml")),
// Render HTML file from Razor template and document typed as HomeViewModel model.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/extensions/Statiq.Razor/RenderRazor.cs">RenderRazor</see>
new RenderRazor().WithModel(Config.FromDocument((document, context) =>
{
var title = document.GetString("Title");
var content = document.GetString("Content");
return new HomeViewModel(title, content);
})),
// Set file system destination for the document.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/core/Statiq.Core/Modules/IO/SetDestination.cs">SetDestination</see>
new SetDestination(Config.FromDocument((doc, ctx) => {
// Provides properties and instance methods for working with paths.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/core/Statiq.Common/IO/NormalizedPath.css">NormalizedPath</see>
return new NormalizedPath("index.html");
}))
};
OutputModules = new ModuleList {
// Flush to the output.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/core/Statiq.Core/Modules/IO/WriteFiles.cs">WriteFiles</see>.
new WriteFiles()
};
}
}
}