【问题标题】:Fail build if two posts resolve to the same permalink in Jekyll如果两个帖子解析到 Jekyll 中的相同永久链接,则构建失败
【发布时间】:2020-10-16 21:13:28
【问题描述】:

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

permalink: /blog/:title:output_ext

我有两个帖子(在 _posts 中)默默地解析到相同的永久链接,例如:

  • 2020-10-15-my-post.md
  • 2020-10-16-my-post.md

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

如果两个帖子解析到相同的永久链接(然后一个帖子覆盖另一个帖子),有没有办法停止网站的构建并引发错误?

【问题讨论】:

  • 你是如何建立网站的?您是否使用任何任务运行器,例如 Rake(或类似的)?
  • 您是否在 GitHub 页面或任何限制使用 Jekyll 插件的环境中托管网站?
  • 我在 Netlify 中使用 bundle exec jekyll build 构建。没有插件限制。

标签: jekyll


【解决方案1】:

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 发现与上述类似的冲突时,其退出代码将为非零,您可以使用它来使构建失败。

【讨论】:

  • 非常感谢!
猜你喜欢
  • 2016-01-27
  • 2017-09-17
  • 1970-01-01
  • 2012-05-13
  • 1970-01-01
  • 1970-01-01
  • 2013-04-19
  • 1970-01-01
  • 2012-04-06
相关资源
最近更新 更多