首页 > 解决方案 > 如何在 CI 管道中使用 HTMLProofer 检查内部链接?

问题描述

我正在使用Jekyll将网站部署到 GitHub Pages 。我有一个持续集成 (CI) 管道,它使用HTMLProofer检查有效的 HTML 以及是否有任何链接损坏。但是,由于站点中的内部链接,HTMLProofer 在我运行它时总是失败。请参阅下面的示例输出:

- ./_site/index.html
  *  internally linking to /about, which does not exist (line 58)
     <a href="/about">About</a>
  *  internally linking to /i-don't-feel-hungry, which does not exist (line 66)
     <a href="/i-don't-feel-hungry">I don't feel hungry</a>
  *  internally linking to /i-don't-feel-hungry, which does not exist (line 69)
     <a href="/i-don't-feel-hungry">Read more</a>
  *  internally linking to /little-things, which does not exist (line 77)
     <a href="/little-things">Little things</a>
  *  internally linking to /little-things, which does not exist (line 80)
     <a href="/little-things">Read more</a>
  *  internally linking to /paintings, which does not exist (line 57)
     <a href="/paintings">Paintings</a>
  *  internally linking to /photos, which does not exist (line 56)
     <a href="/photos">Photos</a>
  *  internally linking to /poems, which does not exist (line 55)
     <a href="/poems">Poems</a>
  *  internally linking to /potsdam, which does not exist (line 88)
     <a href="/potsdam">Potsdam</a>
  *  internally linking to /potsdam, which does not exist (line 91)
     <a href="/potsdam">Read more</a>
  *  internally linking to /three-quarters-of-a-dream, which does not exist (line 99)
     <a href="/three-quarters-of-a-dream">Three-quarters of a dream</a>
  *  internally linking to /three-quarters-of-a-dream, which does not exist (line 103)
     <a href="/three-quarters-of-a-dream">Read more</a>

所有这些页面都存在,但它们是内部链接并且不指定域,例如localhost:4000example.github.io。这取决于 Jekyll 构建是在开发中还是在生产中运行。

我已经探索了 HTMLProofer 问题跟踪器,了解如何在没有明确答案的情况下解决这个问题。问题 #104问题 #542提供了一些见解,但没有提供有关如何修复内部链接错误的解决方案。内部域功能似乎与此问题有关,但在我的 CI 管道中将其添加到我的 HTMLProofer 配置后,它并没有更改错误消息。

我采取的临时方法是使用url_ignoreHTMLProofer 的参数,但这并不理想,因为每个新帖子都需要调整 CI 管道。请参阅下面的摘录:

task :test do
  sh "bundle exec jekyll build"
  options = {
    :allow_hash_href => true,
    :check_html => true,
    :empty_alt_ignore => true,
    :http_status_ignore => [0,400,503,999],
    :url_ignore => [
      # internal pages
      "/about",
      "/paintings",
      "/photos",
      "/poems",

      # internal posts
      "/i-don't-feel-hungry",
      "/little-things",
      "/potsdam",
      "/three-quarters-of-a-dream",

      # regular expressions
      /poem\/.*/,
      /www\.facebook\.com\/sharer\/.*/,
    ],
    :cache => {
      :timeframe => "6w"
    }

HTMLProofer 怎么可能仍然验证内部链接是否存在,但如果没有指定 FQDN,或者域没有作为href属性的前缀,则不会失败?

谢谢!

标签: rubytestingcontinuous-integrationjekyll

解决方案


推荐阅读