I have the following file structure in my Jekyll project:
├── _articles
│ ├── bar
│ │ └── widget.md
│ ├── bar.md
│ └── phone.md
└── foo.md
See here: https://github.com/janpio/jekyll-test
_articles
is a collection that is defined in _config.yml
:
collections:
articles:
title: Articles
output: true
permalink: :path
On Github Pages this is built into these URIs:
- https://janpio.github.io/jekyll-test/bar/widget
- https://janpio.github.io/jekyll-test/bar
- https://janpio.github.io/jekyll-test/phone
- https://janpio.github.io/jekyll-test/foo/
See here: https://janpio.github.io/jekyll-test/
That is all fine and as expected.
But when I bundle exec jekyll s
this project locally1 it doesn't work the same way. I get the expected URIs:
- http://127.0.0.1:4000/bar/widget
- http://127.0.0.1:4000/bar
- http://127.0.0.1:4000/phone
- http://127.0.0.1:4000/foo/
But the problem is that #2 gets redirected to 127.0.0.1:4000/bar/
and shows a directory listing instead of the actual page!
Looking at _site
this is the file structure that is generated:
├── bar
│ └── widget.html
├── bar.html
├── foo.html
├── index.html
└── phone.html
So I can access bar.md
at http://127.0.0.1:4000/bar.html
.
How can I fix this?
1 My Gemfile is so the environment should be identical to Github Pages: https://github.com/janpio/jekyll-test/blob/master/Gemfile
Update for Jekyll 3.6.x
The 3.6.0 Jekyll release changed this behaviour:
Fix serving files that clash with directories (#6222) (#6231)
Unfortunately, these changes didn't really fix the problem but replace it with a less serious one: The link now doesn't show the directory listing any more but the correct page, but the path is still different in that it adds the /
at the end. Unfortunately as a regression bar/widget
doesn't render the correct content any more but shows bar.md
.