ruby - 如何在 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:4000
或example.github.io
。这取决于 Jekyll 构建是在开发中还是在生产中运行。
我已经探索了 HTMLProofer 问题跟踪器,了解如何在没有明确答案的情况下解决这个问题。问题 #104和问题 #542提供了一些见解,但没有提供有关如何修复内部链接错误的解决方案。内部域功能似乎与此问题有关,但在我的 CI 管道中将其添加到我的 HTMLProofer 配置后,它并没有更改错误消息。
我采取的临时方法是使用url_ignore
HTMLProofer 的参数,但这并不理想,因为每个新帖子都需要调整 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
属性的前缀,则不会失败?
谢谢!
解决方案
推荐阅读
- python - datetime.strptime: TypeError: strptime() argument 1 must be str, not Series
- web-services - 使用 post httpClient ionic 发送数组字符串
- typescript - 打字稿地图迭代给出错误map.keys不是云函数中的函数
- angular - 需要帮助设计带有 jumbotron 内面板的引导容器
- ios - 当我在 Alamofire 中使用 UserDefaults.standard.object 时,它显示“调用中的额外参数”错误
- c - 连接 n 个文件并在屏幕和文件上输出
- python - 通过python中的插值或QHull的分散数据的轮廓
- javascript - Firebase - 创建用户帐户后通过电子邮件发送密码
- r - if else 语句连接 - R
- mongodb - 尝试使用 MongoDB 数据库创建 Docker 映像,但即使加载成功,容器也没有它