# frozen_string_literal: true

require "rake"

task default: :build

desc "Build the site."
task :build do
  sh "jekyll", "build"
end

desc "Run Markdownlint to validate the Markdown style."
task :lint do
  sh "mdl $(git ls-files '*.md' | grep -v 'Manpage.md')"
  sh "grep -L '^last_review_date:' $(git ls-files '*.md' | grep -v 'Manpage.md') | " \
     "xargs -I {} echo 'File {} is missing last_review_date frontmatter.'"
end

desc "Run HTMLProofer to validate the HTML output."
task test: :build do
  require "html-proofer"
  HTMLProofer.check_directory(
    "./_site",
    parallel:            { in_threads: 4 },
    favicon:             true,
    ignore_status_codes: [0, 403],
    check_favicon:       true,
    check_opengraph:     true,
    check_html:          true,
    check_img_http:      true,
    enforce_https:       true,
    ignore_files:        [
      /Kickstarter-Supporters/,
    ],
    ignore_urls:         [
      "/",
      %r{https://formulae.brew.sh},
      %r{https://github.com/},
      %r{https://homebrew.1password.com/},
      "https://legacy.python.org/dev/peps/pep-0453/#recommendations-for-downstream-distributors",
      "https://metacpan.org/pod/local::lib",
    ],
    cache:               {
      timeframe: {
        external: "1d",
        internal: "1h",
      },
    },
  ).run
end
