2
votes

In my Jekyll site I have a permalink structure like this in _config.yml:

permalink: /blog/:title:output_ext

And I have two posts (in _posts) that resolve to the same permalink silently, for example:

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

Only one is written to _site/blog/my-post.html.

Is there a way to halt the building of the site, and throw an error, if two posts resolve to the same permalink (and then, one post overwriting the other)?

1
How are you building the website? Are you using any task runner such as Rake (or similar)?C. Augusto Proiete
Are you hosting the website on GitHub pages or any environment that restricts the use of Jekyll plugins?C. Augusto Proiete
I build using bundle exec jekyll build in Netlify. No plugins restrictions.Victor

1 Answers

2
votes

The Jekyll CLI has a command called doctor that outputs any deprecation or configuration issues with your site and, among other things, it detects when two posts resolve to the same permalink.

You can run it similarly to how you build your site today:

bundle exec jekyll doctor

In the example you gave in your question, jekyll doctor will show you an error message about a conflict between two pages, similar to this:

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

When jekyll doctor finds a conflict like the above, its exit code will be non-zero which you can use to fail the build.