diff --git a/src/Website/Silk.NET.Statiq.TableOfContents/ProcessModules/BakeTocIntoDocuments.cs b/src/Website/Silk.NET.Statiq.TableOfContents/ProcessModules/BakeTocIntoDocuments.cs index d27078c6f..2771a7785 100644 --- a/src/Website/Silk.NET.Statiq.TableOfContents/ProcessModules/BakeTocIntoDocuments.cs +++ b/src/Website/Silk.NET.Statiq.TableOfContents/ProcessModules/BakeTocIntoDocuments.cs @@ -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) diff --git a/src/Website/Silk.NET.Statiq/Program.cs b/src/Website/Silk.NET.Statiq/Program.cs index 9b6bd3379..bebd7222b 100644 --- a/src/Website/Silk.NET.Statiq/Program.cs +++ b/src/Website/Silk.NET.Statiq/Program.cs @@ -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 + ( + (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("Caption") .AddShortcode("Info") .AddShortcode("Warning") + .AddSetting("Host", "dotnet.github.io") + .AddSetting("LinkRoot", "/Silk.NET") + .AddSetting("LinksUseHttps", true) + .AddSetting("LinkHideExtensions", false) .RunAsync(); } } diff --git a/website/_Layout.cshtml b/website/_Layout.cshtml index d7f9f5747..c9e3d0fe5 100644 --- a/website/_Layout.cshtml +++ b/website/_Layout.cshtml @@ -100,10 +100,11 @@ - @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)) {