如果两个帖子在 Jekyll 中解析为相同的永久链接,则构建失败

Fail build if two posts resolve to the same permalink in Jekyll

在我的 Jekyll 站点中,我有一个像这样的永久链接结构 _config.yml:

permalink: /blog/:title:output_ext

并且我有两个 posts(在 _posts 中)解析为相同的永久链接静默,例如:

只有一个写入_site/blog/my-post.html

如果两个 post 解析到同一个永久链接(然后,一个 post 覆盖另一个),是否有办法停止站点的构建并抛出错误?

Jekyll CLI 有一个名为 doctor 的命令,它会输出您站点的任何弃用或配置问题,除其他外,它会检测两个帖子何时解析为相同的永久链接。

您可以 运行 它类似于您今天构建网站的方式:

bundle exec jekyll doctor

在您在问题中给出的示例中,jekyll doctor 将向您显示有关两个页面之间存在冲突的错误消息,类似于:

Configuration file: /your-website/_config.yml
       Jekyll Feed: Generating feed for posts
          Conflict: The URL '/your-website/_site/blog/my-post.html' is the destination
                    for the following pages: /your-website/_posts/2020-10-15-my-post.md,
                    /your-website/_posts/2020-10-16-my-post.md

jekyll doctor发现上述冲突时,其退出代码将是non-zero,您可以使用它来使构建失败。