Skip to content

Commit

Permalink
Added link validation support
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Apr 22, 2020
1 parent d87f7d2 commit 48634dd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 10 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Statiq.Web/BootstrapperFactoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static Bootstrapper CreateWeb(this BootstrapperFactory factory, string[]
.AddSettingsIfNonExisting(new Dictionary<string, object>
{
{ WebKeys.MirrorResources, true },
{ WebKeys.ValidateRelativeLinks, true },
{ WebKeys.Xref, Config.FromDocument(doc => doc.GetTitle().Replace(' ', '_')) }
});
}
Expand Down
28 changes: 28 additions & 0 deletions src/Statiq.Web/Pipelines/LinkValidation.cs
Original file line number Diff line number Diff line change
@@ -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<bool>(WebKeys.ValidateRelativeLinks))
.ValidateAbsoluteLinks(Config.FromSetting<bool>(WebKeys.ValidateAbsoluteLinks))
.AsError(Config.FromSetting<bool>(WebKeys.ValidateLinksAsError))
};
}
}
}
11 changes: 1 addition & 10 deletions src/Statiq.Web/Pipelines/Sass.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
15 changes: 15 additions & 0 deletions src/Statiq.Web/WebKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ public static class WebKeys

public const string MirrorResources = nameof(MirrorResources);

/// <summary>
/// Set to <c>true</c> (the default value is <c>false</c>) to validate all absolute links. Note that this may add considerable time to your generation process.
/// </summary>
public const string ValidateAbsoluteLinks = nameof(ValidateAbsoluteLinks);

/// <summary>
/// Set to <c>true</c> (the default value is <c>false</c>) to report errors on link validation failures.
/// </summary>
public const string ValidateLinksAsError = nameof(ValidateLinksAsError);

/// <summary>
/// Set to <c>true</c> (the default value) to validate all relative links.
/// </summary>
public const string ValidateRelativeLinks = nameof(ValidateRelativeLinks);

// Intended for use as document metadata

public const string ArchivePipelines = nameof(ArchivePipelines);
Expand Down

0 comments on commit 48634dd

Please sign in to comment.