Skip to content

Instantly share code, notes, and snippets.

@bnorberg
Last active March 6, 2023 01:28
Show Gist options
  • Save bnorberg/f22875beb1c5fc4cdee7f7db91f3ee72 to your computer and use it in GitHub Desktop.
Save bnorberg/f22875beb1c5fc4cdee7f7db91f3ee72 to your computer and use it in GitHub Desktop.
HTML Proofer options
def link_check
options = {
allow_hash_href: true, # default false,
allow_missing_href: true,
assume_extension: '.html', # default false,
checks: ['Links', 'Images', 'Scripts', 'OpenGraph'],
check_external_hash: false,
check_sri: false,
directory_index_file: 'index.html',
disable_external: false, # default false,
ignore_empty_alt: true, # default false,
enforce_https: false,
extensions: ['.html'],
external_only: false,
ignore_files: [],
ignore_status_codes: [999],
log_level: :info,
ignore_empty_mailto: false,
only_4xx: false,
ignore_urls: [Regexp.new('^https://github.com/(orgs/)*NetAppDocs/\S*'), Regexp.new('^https://review.docs.netapp.com/\S*'), Regexp.new('^//cdn.jsdelivr.net/\S*'), Regexp.new('^\.\.\/\S*.html')], #ignore review domain, protocol relative links and relative links, and github links
swap_urls: {},
cache: {},
parallel: {}
}
## Create baseurl out of lang and repo name
lang = 'us-en'
lang = ENV['LANG_REPO_NAME'].to_s unless ENV['LANG_REPO_NAME'].to_s.empty?
folder = ENV['PREFIX_REPO_NAME'].to_s
prefix = "^/#{lang}/#{folder}/"
bc_url = "^/#{lang}/#{folder}" #breadcrumb url drops trailing "/" during check so does not find index.html and fails
options[:ignore_urls] << Regexp.new(bc_url) #ignore breadcrumb url
puts "Baseurl: #{prefix}"
## Swap baseurl
options[:swap_urls][Regexp.new(prefix)] = '/'
options[:swap_urls][Regexp.new('^https://mysupport.netapp.com/site')] = 'https://mysupport.netapp.com/site/' #add trailing "/" to avoid redirect error
#setting cache external and internal timeframe
options[:cache][:timeframe] = {}
options[:cache][:timeframe][:external] = '1w'
options[:cache][:timeframe][:internal] = '1w'
pwd = Dir.pwd
begin
proofer = HTMLProofer.check_directory(pwd, options)
proofer.run
rescue Exception => e
puts e
end
return 0
end
def run()
link_check
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment