From c958be7ece319cde977773dda808882908bb16c1 Mon Sep 17 00:00:00 2001 From: Benjamin Gill Date: Thu, 4 Apr 2019 17:50:46 +0100 Subject: [PATCH] Fail build if there are dead internal links Using html-proofer. Will apply to new projects only - existing users of the template would need to apply this change manually. --- template/Gemfile | 3 +++ template/config.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/template/Gemfile b/template/Gemfile index 530346bb..d36511e4 100644 --- a/template/Gemfile +++ b/template/Gemfile @@ -10,3 +10,6 @@ gem 'tzinfo-data', platforms: [:mswin, :mingw, :jruby] # Include the tech docs gem gem 'govuk_tech_docs' + +# Include linter to check for dead internal links +gem 'html-proofer' diff --git a/template/config.rb b/template/config.rb index 894a7251..a2f26cbb 100644 --- a/template/config.rb +++ b/template/config.rb @@ -1,3 +1,16 @@ require 'govuk_tech_docs' +require 'html-proofer' GovukTechDocs.configure(self) + +after_build do |builder| + begin + HTMLProofer.check_directory(config[:build_dir], + { :assume_extension => true, + :disable_external => true, + :allow_hash_href => true, + :url_swap => { config[:tech_docs][:host] => "" } }).run + rescue RuntimeError => e + abort e.to_s + end +end