Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 033a904

Browse files
committed
Enable hook to be always run with the jekyll serve command
Read the proofer options form _config.checks.yml Ignore URLs excluded in the Jekyll config
1 parent bf71ef8 commit 033a904

File tree

3 files changed

+30
-69
lines changed

3 files changed

+30
-69
lines changed

_checks/html-check-config.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

_checks/html-check-hook.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

_plugins/html-check-hook.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# The hook runs html-proofer with options defined in the
2+
# _checks/html-check-config.yml file
3+
#
4+
# For more details about html-proofer, refer to: https://github.com/gjtorikian/html-proofer
5+
# For more details about Jekyll hooks, refer to: https://jekyllrb.com/docs/plugins/hooks/
6+
#
7+
require 'html-proofer'
8+
require 'yaml'
9+
10+
Jekyll::Hooks.register :site, :post_write do |site|
11+
12+
# If 'jekyll serve' has been run, read options for html-proofer
13+
# in '_config.checks.yml' and merge the 'url_ignore' list with 'excludes'
14+
# from Jekyll configurtiuon
15+
#
16+
if site.config['serving'] == true
17+
begin
18+
checks_config = YAML.load_file('_config.checks.yml')
19+
jekyll_excludes = site.config['exclude']
20+
jekyll_excludes_as_regex = jekyll_excludes.map { |item| /#{item}/ }
21+
checks_config['html-proofer'][:url_ignore].push(jekyll_excludes_as_regex).flatten!.uniq!
22+
options = checks_config['html-proofer']
23+
# Run html-proofer to check the jekyll destination directory
24+
HTMLProofer.check_directory(site.dest, options).run
25+
rescue
26+
puts
27+
puts 'Fix the broken links before you commit the changes.'.blue
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)