From 48634dd00567a1471423799bda81a9f6e34ccf59 Mon Sep 17 00:00:00 2001 From: Dave Glick Date: Wed, 22 Apr 2020 13:43:39 -0400 Subject: [PATCH] Added link validation support --- RELEASE.md | 1 + .../BootstrapperFactoryExtensions.cs | 1 + src/Statiq.Web/Pipelines/LinkValidation.cs | 28 +++++++++++++++++++ src/Statiq.Web/Pipelines/Sass.cs | 11 +------- src/Statiq.Web/WebKeys.cs | 15 ++++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/Statiq.Web/Pipelines/LinkValidation.cs diff --git a/RELEASE.md b/RELEASE.md index 67f305dfb..357dfde81 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,6 @@ # 1.0.0-alpha.8 +- Added support for validating links. - Refactored xref error messages to display for all documents at once (instead of one at a time). # 1.0.0-alpha.7 diff --git a/src/Statiq.Web/BootstrapperFactoryExtensions.cs b/src/Statiq.Web/BootstrapperFactoryExtensions.cs index b766111a3..040e2522d 100644 --- a/src/Statiq.Web/BootstrapperFactoryExtensions.cs +++ b/src/Statiq.Web/BootstrapperFactoryExtensions.cs @@ -27,6 +27,7 @@ public static Bootstrapper CreateWeb(this BootstrapperFactory factory, string[] .AddSettingsIfNonExisting(new Dictionary { { WebKeys.MirrorResources, true }, + { WebKeys.ValidateRelativeLinks, true }, { WebKeys.Xref, Config.FromDocument(doc => doc.GetTitle().Replace(' ', '_')) } }); } diff --git a/src/Statiq.Web/Pipelines/LinkValidation.cs b/src/Statiq.Web/Pipelines/LinkValidation.cs new file mode 100644 index 000000000..18eda953d --- /dev/null +++ b/src/Statiq.Web/Pipelines/LinkValidation.cs @@ -0,0 +1,28 @@ +using System.Linq; +using Statiq.Common; +using Statiq.Core; +using Statiq.Html; + +namespace Statiq.Web.Pipelines +{ + public class LinkValidation : Pipeline + { + public LinkValidation() + { + Deployment = true; + + ExecutionPolicy = ExecutionPolicy.Normal; + + Dependencies.AddRange(nameof(Content), nameof(Archives)); + + OutputModules = new ModuleList + { + new ReplaceDocuments(Dependencies.ToArray()), + new ValidateLinks() + .ValidateRelativeLinks(Config.FromSetting(WebKeys.ValidateRelativeLinks)) + .ValidateAbsoluteLinks(Config.FromSetting(WebKeys.ValidateAbsoluteLinks)) + .AsError(Config.FromSetting(WebKeys.ValidateLinksAsError)) + }; + } + } +} diff --git a/src/Statiq.Web/Pipelines/Sass.cs b/src/Statiq.Web/Pipelines/Sass.cs index 41c204bf3..c68448ba6 100644 --- a/src/Statiq.Web/Pipelines/Sass.cs +++ b/src/Statiq.Web/Pipelines/Sass.cs @@ -1,15 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Statiq.App; -using Statiq.Common; +using Statiq.Common; using Statiq.Core; -using Statiq.Html; -using Statiq.Less; -using Statiq.Markdown; -using Statiq.Razor; using Statiq.Sass; -using Statiq.Yaml; namespace Statiq.Web.Pipelines { diff --git a/src/Statiq.Web/WebKeys.cs b/src/Statiq.Web/WebKeys.cs index 40acd8165..af15caea6 100644 --- a/src/Statiq.Web/WebKeys.cs +++ b/src/Statiq.Web/WebKeys.cs @@ -43,6 +43,21 @@ public static class WebKeys public const string MirrorResources = nameof(MirrorResources); + /// + /// Set to true (the default value is false) to validate all absolute links. Note that this may add considerable time to your generation process. + /// + public const string ValidateAbsoluteLinks = nameof(ValidateAbsoluteLinks); + + /// + /// Set to true (the default value is false) to report errors on link validation failures. + /// + public const string ValidateLinksAsError = nameof(ValidateLinksAsError); + + /// + /// Set to true (the default value) to validate all relative links. + /// + public const string ValidateRelativeLinks = nameof(ValidateRelativeLinks); + // Intended for use as document metadata public const string ArchivePipelines = nameof(ArchivePipelines);