Fix buggy RSS feed & comments section

This commit is contained in:
Dylan Perks 2023-05-26 17:28:42 +01:00
Родитель 59fca1a5a8
Коммит fbe41127b0
5 изменённых файлов: 90 добавлений и 22 удалений

Просмотреть файл

@ -45,8 +45,10 @@ namespace Silk.NET.Statiq.TableOfContents.ProcessModules
}
// find a toc in which the document has a matching entry in its map.
var matchingToc = _tocs?.SelectMany(x => x.Object.TocMap)
.FirstOrDefault(x => _pathMatcher(x.Key, input.Source.GetRelativeInputPath()));
var matchingToc = input.Source.IsNull
? null
: _tocs?.SelectMany(x => x.Object.TocMap)
.FirstOrDefault(x => _pathMatcher(x.Key, input.Source.GetRelativeInputPath()));
if (matchingToc?.Value.Value is null) // would be matchingToc is null but FirstOrDefault is strange...
{
if (_anyIfNotFound)

Просмотреть файл

@ -2,8 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Globalization;
using System.Threading.Tasks;
using Silk.NET.Statiq;
using Silk.NET.Statiq.TableOfContents;
using Silk.NET.Statiq.TableOfContents.ProcessModules;
using Statiq.App;
using Statiq.Common;
@ -54,15 +56,24 @@ public static class Program
.WithProcessModules
(
new ExtractFrontMatter(new ParseJson()),
new ForAllMatching().WithFilterPatterns("**/*.md").WithExecuteModules(new RenderMarkdown()),
new AddTableOfContents
(
(tocPath, docPath) => tocPath == docPath.ChangeExtension(".html"),
"**/toc.json"
),
new RenderRazor(),
new ProcessShortcodes(),
new SetDestination(".html"),
new ForAllMatching()
.WithFilterPatterns("**/*.md")
.WithExecuteModules
(
new RenderMarkdown(),
new SetDestination(".html"),
new ProcessShortcodes()
),
new ForAllMatching()
.WithFilterPatterns("**/*.{md,html,cshtml}")
.WithExecuteModules
(
new AddTableOfContents
(
(tocPath, docPath) => tocPath == docPath.ChangeExtension(".html"),
"**/toc.json"
)
),
new ForAllMatching(true)
.WithFilterPatterns("blog/{**/*,!index.cshtml}")
.WithExecuteModules
@ -72,8 +83,45 @@ public static class Program
(
Config.FromDocument
(
(y, z)
=> new Uri(new("https://dotnet.github.io/Silk.NET"), z.GetLink(y, true))
(y, z) => new Uri(z.GetLink(y, true))
)
)
.WithItemAuthor
(
Config.FromDocument
(
(y, _) => y.GetToc()?
.Node?
.Metadata?
.TryGetValue("AuthorGitHub", out var val) ?? false
? val
: "Team Silk.NET"
)
)
.WithItemPublished
(
Config.FromDocument<DateTime?>
(
(y, _) => (y.GetToc()
?
.Node?
.Metadata?
.TryGetValue("DateTimeWritten", out var val) ?? false) &&
DateTime.TryParse(val, out var pub)
? pub
: null
)
)
.WithItemImageLink
(
Config.FromDocument
(
(y, z) => y.GetToc()?
.Node?
.Metadata?
.TryGetValue("PreviewImage", out var val) ?? false
? new Uri(z.GetLink(val, true))
: null
)
)
.WithAtomPath("blog/feed.atom")
@ -84,6 +132,15 @@ public static class Program
(
$"Copyright (C) {DateTime.UtcNow.Year} .NET Foundation and Contributors"
)
.AbsolutizeLinks(false)
),
new ForAllMatching()
.WithFilterPatterns("**/*.{md,html,cshtml}")
.WithExecuteModules
(
new RenderRazor(),
new ProcessShortcodes(),
new SetDestination(".html")
)
)
.WithOutputWriteFiles()
@ -92,6 +149,10 @@ public static class Program
.AddShortcode<CaptionShortCode>("Caption")
.AddShortcode<InfoShortCode>("Info")
.AddShortcode<WarningShortCode>("Warning")
.AddSetting("Host", "dotnet.github.io")
.AddSetting("LinkRoot", "/Silk.NET")
.AddSetting("LinksUseHttps", true)
.AddSetting("LinkHideExtensions", false)
.RunAsync();
}
}

Просмотреть файл

@ -100,10 +100,11 @@
<script src="@InputUrl("theme/clipboard.min.js")"></script>
<script src="@InputUrl("theme/headroom.min.js")"></script>
<script src="@InputUrl("theme/silk.js")"></script>
@if ((toc?.Root.Metadata?.TryGetValue("theme.silk.giscus.repo", out giscusRepo) ?? false) &&
(toc?.Root.Metadata?.TryGetValue("theme.silk.giscus.repo.id", out giscusRepoId) ?? false) &&
(toc?.Root.Metadata?.TryGetValue("theme.silk.giscus.category", out giscusCategory) ?? false) &&
(toc?.Root.Metadata?.TryGetValue("theme.silk.giscus.category.id", out giscusCategoryId) ?? false))
@if ((toc?.Root?.Metadata?.TryGetValue("theme.silk.giscus.repo", out giscusRepo) ?? false) &&
(toc?.Root?.Metadata?.TryGetValue("theme.silk.giscus.repo.id", out giscusRepoId) ?? false) &&
(toc?.Root?.Metadata?.TryGetValue("theme.silk.giscus.category", out giscusCategory) ?? false) &&
(toc?.Root?.Metadata?.TryGetValue("theme.silk.giscus.category.id", out giscusCategoryId) ?? false) &&
(!toc?.Node?.Metadata?.ContainsKey("theme.silk.giscus.exempt") ?? true))
{
<script src="https://giscus.app/client.js"
data-repo="@giscusRepo"

Просмотреть файл

@ -86,10 +86,11 @@
<!-- Content -->
@content
@if ((tocModel?.Root.Metadata?.ContainsKey("theme.silk.giscus.repo") ?? false) &&
(tocModel?.Root.Metadata?.ContainsKey("theme.silk.giscus.repo.id") ?? false) &&
(tocModel?.Root.Metadata?.ContainsKey("theme.silk.giscus.category") ?? false) &&
(tocModel?.Root.Metadata?.ContainsKey("theme.silk.giscus.category.id") ?? false))
@if ((tocModel?.Root?.Metadata?.ContainsKey("theme.silk.giscus.repo") ?? false) &&
(tocModel?.Root?.Metadata?.ContainsKey("theme.silk.giscus.repo.id") ?? false) &&
(tocModel?.Root?.Metadata?.ContainsKey("theme.silk.giscus.category") ?? false) &&
(tocModel?.Root?.Metadata?.ContainsKey("theme.silk.giscus.category.id") ?? false) &&
(!tocModel?.Node?.Metadata?.ContainsKey("theme.silk.giscus.exempt") ?? true))
{
<hr class="silk-last-hr" />
<div class="giscus" />

Просмотреть файл

@ -41,7 +41,10 @@
"theme.silk.giscus.repo": "dotnet/Silk.NET",
"theme.silk.giscus.repo.id": "MDEwOlJlcG9zaXRvcnkxOTEyMzIyNDA=",
"theme.silk.giscus.category": "Webpage Comments",
"theme.silk.giscus.category.id": "DIC_kwDOC2X48M4CT__i"
"theme.silk.giscus.category.id": "DIC_kwDOC2X48M4CT__i",
"_comment7": "This page is exempt from having a comments page.",
"theme.silk.giscus.exempt": "true"
}
}
}