-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeaturesListingRazorPipeline.cs
More file actions
84 lines (77 loc) · 4.33 KB
/
Copy pathFeaturesListingRazorPipeline.cs
File metadata and controls
84 lines (77 loc) · 4.33 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System.Collections.Generic;
using Statiq.Common;
using Statiq.Core;
using Statiq.Razor;
using Statiq.Yaml;
namespace StatiqTutorial
{
/// <summary>
/// Pipeline responsible for processing features markdown files into features listing HTML documents using Razor templates.
/// </summary>
public class FeaturesListingRazorPipeline : Pipeline
{
public FeaturesListingRazorPipeline()
{
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(pattern: "content/features/*.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()
),
// Replaces documents in the current pipeline.
// <see href="https://github.com/statiqdev/Statiq.Framework/blob/main/src/core/Statiq.Core/Modules/Control/ReplaceDocuments.cs">ReplaceDocuments</see>
new ReplaceDocuments(
Config.FromContext(context =>
{
return (IEnumerable<IDocument>) new []
{
context.CreateDocument(
// 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>
new NormalizedPath("features-razor.html"),
new[]
{
new KeyValuePair<string, object>(Keys.Children, context.Inputs)
}
)
};
})
),
};
OutputModules = new ModuleList
{
// Load 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("FeaturesListing.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 featureDocuments = document.GetChildren();
List<Feature> features = new List<Feature>();
foreach (var featureDocument in featureDocuments)
{
var featureTitle = featureDocument.GetString("Title");
var featureDescription = featureDocument.GetString("Description");
var slug = featureDocument.Source.FileNameWithoutExtension.ToString();
features.Add(new Feature(featureTitle, featureDescription, slug));
}
return new FeaturesListingViewModel(features);
})),
// 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()
};
}
}
}