forked from dotnet-foundation/website
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
95 lines (87 loc) · 3.6 KB
/
Program.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Statiq.App;
using Statiq.Common;
using Statiq.Core;
using Statiq.Web;
namespace DotnetFoundationWeb
{
public static class Program
{
public static async Task<int> Main(string[] args)
{
Func<string, string> formatter = null;
if (!string.IsNullOrWhiteSpace(AppSettings.ServerUrl))
{
var formatterString = AppSettings.ServerUrl + "/{0}";
formatter = f => string.Format(formatterString, f);
}
var bootstrapper = Bootstrapper.Factory
.CreateWeb(args)
.AddSetting(WebKeys.InputFiles, new[] { "**/{!_,}*", "_redirects" })
.AddSetting(Keys.Host, "dotnetfoundation.org")
.AddSetting(Keys.LinksUseHttps, true)
.AddSetting(WebKeys.MirrorResources, true)
.AddSetting(WebKeys.ExcludedPaths, "api/node_modules");
// No IConfiguration so I'm looking at the environment variable
var environment = Environment.GetEnvironmentVariable("ASPNETCORE__ENVIRONMENT") ?? "Production";
if (environment == "Development" && AppSettings.SuppressProjects)
{
Console.WriteLine("Suppressing Project Generation ****SHOULD ONLY BE IN DEBUG***");
}
else
{
bootstrapper = AddProjectsPipeline(bootstrapper);
}
if (environment == "Development" && AppSettings.SuppressSpeakers)
{
Console.WriteLine("Suppressing Speakers Generation ****SHOULD ONLY BE IN DEBUG***");
}
else
{
bootstrapper = AddSpeakersPipeline(bootstrapper);
}
return await bootstrapper.RunAsync();
}
private static Bootstrapper AddSpeakersPipeline(Bootstrapper bootstrapper)
{
bootstrapper = bootstrapper.ModifyPipeline(
nameof(Statiq.Web.Pipelines.Content),
x => x.ProcessModules.Add(
// Modules for speakers
new ExecuteSources("community/speakers/*.md")
{
new GeocodeLocations(Config.FromSetting(SiteKeys.AzureMapsSubscriptionKey)),
new GetBlogFeeds(),
new SpeakerImage()
}
));
return bootstrapper;
}
private static Bootstrapper AddProjectsPipeline(Bootstrapper bootstrapper)
{
bootstrapper = bootstrapper.BuildPipeline(
"GenerateProjectsJson",
builder => builder
.WithDependencies(nameof(Statiq.Web.Pipelines.Content))
.WithProcessModules(
new ReplaceDocuments(nameof(Statiq.Web.Pipelines.Content)),
new FlattenTree(),
new FilterSources("projects/data/*.md"),
new ExecuteConfig(Config.FromContext(ctx =>
JsonSerializer.Serialize(ctx.Inputs.Select(x => new
{
Title = x.GetString(WebKeys.Title),
Keywords = x.GetString(SiteKeys.Keywords),
Link = x.GetLink(),
Content = x.GetContentStringAsync().GetAwaiter().GetResult()
})
)))
)
.WithOutputWriteFiles("projects/projects.json"));
return bootstrapper;
}
}
}