-
Notifications
You must be signed in to change notification settings - Fork 0
/
Content.cs
59 lines (49 loc) · 2.17 KB
/
Content.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
using Statiq.Common;
namespace ecoAPM.Site;
public static class Content
{
public static IEnumerable<IDocument> Software(IPipelineOutputs output)
=> Directory(output, "software");
public static IEnumerable<IDocument> Services(IPipelineOutputs output)
=> Directory(output, "services");
public static IEnumerable<IDocument> BlogPosts(IPipelineOutputs output)
=> Directory(output, "blog");
private static IEnumerable<IDocument> Directory(IPipelineOutputs output, string directory)
=> output.FromPipeline("Content")
.FilterSources($"{directory}/**/*.md")
.Where(d => d.GetBool("Show", true))
.OrderBy(d => CategoryOrder(d.GetString("Category")))
.ThenBy(Order)
.ToArray();
public static object JSON(IDocument doc)
=> "{" + string.Join(",", new[]
{
$@"name: ""{doc.GetString("Name")}""",
$@"org: ""{doc.GetString("GitHubOrganization") ?? "ecoAPM"}""",
!doc.GetString("Package").IsNullOrWhiteSpace() ? $@"package:""{doc.GetString("Package")}""" : null,
!doc.GetString("Type").IsNullOrWhiteSpace() ? $@"type:""{doc.GetString("Type")}""" : null,
!doc.GetString("CI").IsNullOrWhiteSpace() ? $@"CI:{doc.GetString("CI")}" : null,
!doc.GetString("Tests").IsNullOrWhiteSpace() ? $@"tests:{doc.GetString("Tests")}" : null,
!doc.GetString("Split").IsNullOrWhiteSpace() ? $@"split:{doc.GetString("Split")}" : null
}.Where(s => s != null)
)
+ "}";
public static IEnumerable<IGrouping<string, IDocument>> SoftwareCategories(IPipelineOutputs outputs)
=> Software(outputs)
.GroupBy(d => d.GetString("Category"))
.OrderBy(c => CategoryOrder(c.Key));
private static string Order(IDocument document)
=> document.GetInt(Keys.Order) > 0 ? document.GetInt(Keys.Order).ToString().PadLeft(2, '0')
: document.GetTitle().StartsWith("ecoAPM") ? $" {document.GetTitle()}"
: document.GetTitle();
private static byte CategoryOrder(string category)
=> category switch
{
"ecoAPM" => 0,
"OSS Tools" => 1,
"Community Service" => 2,
_ => byte.MaxValue
};
public static async Task<string> GetContent(IPipelineOutputs outputs, string key)
=> await outputs[key].First().GetContentStringAsync();
}