Skip to content

Commit fbe4112

Browse files
committed
Fix buggy RSS feed & comments section
1 parent 59fca1a commit fbe4112

File tree

5 files changed

+90
-22
lines changed

5 files changed

+90
-22
lines changed

src/Website/Silk.NET.Statiq.TableOfContents/ProcessModules/BakeTocIntoDocuments.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ IExecutionContext context
4545
}
4646

4747
// find a toc in which the document has a matching entry in its map.
48-
var matchingToc = _tocs?.SelectMany(x => x.Object.TocMap)
49-
.FirstOrDefault(x => _pathMatcher(x.Key, input.Source.GetRelativeInputPath()));
48+
var matchingToc = input.Source.IsNull
49+
? null
50+
: _tocs?.SelectMany(x => x.Object.TocMap)
51+
.FirstOrDefault(x => _pathMatcher(x.Key, input.Source.GetRelativeInputPath()));
5052
if (matchingToc?.Value.Value is null) // would be matchingToc is null but FirstOrDefault is strange...
5153
{
5254
if (_anyIfNotFound)

src/Website/Silk.NET.Statiq/Program.cs

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Globalization;
56
using System.Threading.Tasks;
67
using Silk.NET.Statiq;
8+
using Silk.NET.Statiq.TableOfContents;
79
using Silk.NET.Statiq.TableOfContents.ProcessModules;
810
using Statiq.App;
911
using Statiq.Common;
@@ -54,15 +56,24 @@ public static async Task<int> Main(string[] args)
5456
.WithProcessModules
5557
(
5658
new ExtractFrontMatter(new ParseJson()),
57-
new ForAllMatching().WithFilterPatterns("**/*.md").WithExecuteModules(new RenderMarkdown()),
58-
new AddTableOfContents
59-
(
60-
(tocPath, docPath) => tocPath == docPath.ChangeExtension(".html"),
61-
"**/toc.json"
62-
),
63-
new RenderRazor(),
64-
new ProcessShortcodes(),
65-
new SetDestination(".html"),
59+
new ForAllMatching()
60+
.WithFilterPatterns("**/*.md")
61+
.WithExecuteModules
62+
(
63+
new RenderMarkdown(),
64+
new SetDestination(".html"),
65+
new ProcessShortcodes()
66+
),
67+
new ForAllMatching()
68+
.WithFilterPatterns("**/*.{md,html,cshtml}")
69+
.WithExecuteModules
70+
(
71+
new AddTableOfContents
72+
(
73+
(tocPath, docPath) => tocPath == docPath.ChangeExtension(".html"),
74+
"**/toc.json"
75+
)
76+
),
6677
new ForAllMatching(true)
6778
.WithFilterPatterns("blog/{**/*,!index.cshtml}")
6879
.WithExecuteModules
@@ -72,8 +83,45 @@ public static async Task<int> Main(string[] args)
7283
(
7384
Config.FromDocument
7485
(
75-
(y, z)
76-
=> new Uri(new("https://dotnet.github.io/Silk.NET"), z.GetLink(y, true))
86+
(y, z) => new Uri(z.GetLink(y, true))
87+
)
88+
)
89+
.WithItemAuthor
90+
(
91+
Config.FromDocument
92+
(
93+
(y, _) => y.GetToc()?
94+
.Node?
95+
.Metadata?
96+
.TryGetValue("AuthorGitHub", out var val) ?? false
97+
? val
98+
: "Team Silk.NET"
99+
)
100+
)
101+
.WithItemPublished
102+
(
103+
Config.FromDocument<DateTime?>
104+
(
105+
(y, _) => (y.GetToc()
106+
?
107+
.Node?
108+
.Metadata?
109+
.TryGetValue("DateTimeWritten", out var val) ?? false) &&
110+
DateTime.TryParse(val, out var pub)
111+
? pub
112+
: null
113+
)
114+
)
115+
.WithItemImageLink
116+
(
117+
Config.FromDocument
118+
(
119+
(y, z) => y.GetToc()?
120+
.Node?
121+
.Metadata?
122+
.TryGetValue("PreviewImage", out var val) ?? false
123+
? new Uri(z.GetLink(val, true))
124+
: null
77125
)
78126
)
79127
.WithAtomPath("blog/feed.atom")
@@ -84,6 +132,15 @@ public static async Task<int> Main(string[] args)
84132
(
85133
$"Copyright (C) {DateTime.UtcNow.Year} .NET Foundation and Contributors"
86134
)
135+
.AbsolutizeLinks(false)
136+
),
137+
new ForAllMatching()
138+
.WithFilterPatterns("**/*.{md,html,cshtml}")
139+
.WithExecuteModules
140+
(
141+
new RenderRazor(),
142+
new ProcessShortcodes(),
143+
new SetDestination(".html")
87144
)
88145
)
89146
.WithOutputWriteFiles()
@@ -92,6 +149,10 @@ public static async Task<int> Main(string[] args)
92149
.AddShortcode<CaptionShortCode>("Caption")
93150
.AddShortcode<InfoShortCode>("Info")
94151
.AddShortcode<WarningShortCode>("Warning")
152+
.AddSetting("Host", "dotnet.github.io")
153+
.AddSetting("LinkRoot", "/Silk.NET")
154+
.AddSetting("LinksUseHttps", true)
155+
.AddSetting("LinkHideExtensions", false)
95156
.RunAsync();
96157
}
97158
}

website/_Layout.cshtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@
100100
<script src="@InputUrl("theme/clipboard.min.js")"></script>
101101
<script src="@InputUrl("theme/headroom.min.js")"></script>
102102
<script src="@InputUrl("theme/silk.js")"></script>
103-
@if ((toc?.Root.Metadata?.TryGetValue("theme.silk.giscus.repo", out giscusRepo) ?? false) &&
104-
(toc?.Root.Metadata?.TryGetValue("theme.silk.giscus.repo.id", out giscusRepoId) ?? false) &&
105-
(toc?.Root.Metadata?.TryGetValue("theme.silk.giscus.category", out giscusCategory) ?? false) &&
106-
(toc?.Root.Metadata?.TryGetValue("theme.silk.giscus.category.id", out giscusCategoryId) ?? false))
103+
@if ((toc?.Root?.Metadata?.TryGetValue("theme.silk.giscus.repo", out giscusRepo) ?? false) &&
104+
(toc?.Root?.Metadata?.TryGetValue("theme.silk.giscus.repo.id", out giscusRepoId) ?? false) &&
105+
(toc?.Root?.Metadata?.TryGetValue("theme.silk.giscus.category", out giscusCategory) ?? false) &&
106+
(toc?.Root?.Metadata?.TryGetValue("theme.silk.giscus.category.id", out giscusCategoryId) ?? false) &&
107+
(!toc?.Node?.Metadata?.ContainsKey("theme.silk.giscus.exempt") ?? true))
107108
{
108109
<script src="https://giscus.app/client.js"
109110
data-repo="@giscusRepo"

website/_theme/src/21-sidenavcontent.cshtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@
8686

8787
<!-- Content -->
8888
@content
89-
@if ((tocModel?.Root.Metadata?.ContainsKey("theme.silk.giscus.repo") ?? false) &&
90-
(tocModel?.Root.Metadata?.ContainsKey("theme.silk.giscus.repo.id") ?? false) &&
91-
(tocModel?.Root.Metadata?.ContainsKey("theme.silk.giscus.category") ?? false) &&
92-
(tocModel?.Root.Metadata?.ContainsKey("theme.silk.giscus.category.id") ?? false))
89+
@if ((tocModel?.Root?.Metadata?.ContainsKey("theme.silk.giscus.repo") ?? false) &&
90+
(tocModel?.Root?.Metadata?.ContainsKey("theme.silk.giscus.repo.id") ?? false) &&
91+
(tocModel?.Root?.Metadata?.ContainsKey("theme.silk.giscus.category") ?? false) &&
92+
(tocModel?.Root?.Metadata?.ContainsKey("theme.silk.giscus.category.id") ?? false) &&
93+
(!tocModel?.Node?.Metadata?.ContainsKey("theme.silk.giscus.exempt") ?? true))
9394
{
9495
<hr class="silk-last-hr" />
9596
<div class="giscus" />

website/index.cshtml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
"theme.silk.giscus.repo": "dotnet/Silk.NET",
4242
"theme.silk.giscus.repo.id": "MDEwOlJlcG9zaXRvcnkxOTEyMzIyNDA=",
4343
"theme.silk.giscus.category": "Webpage Comments",
44-
"theme.silk.giscus.category.id": "DIC_kwDOC2X48M4CT__i"
44+
"theme.silk.giscus.category.id": "DIC_kwDOC2X48M4CT__i",
45+
46+
"_comment7": "This page is exempt from having a comments page.",
47+
"theme.silk.giscus.exempt": "true"
4548
}
4649
}
4750
}

0 commit comments

Comments
 (0)