1
votes

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:

  1. https://janpio.github.io/jekyll-test/bar/widget
  2. https://janpio.github.io/jekyll-test/bar
  3. https://janpio.github.io/jekyll-test/phone
  4. 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:

  1. http://127.0.0.1:4000/bar/widget
  2. http://127.0.0.1:4000/bar
  3. http://127.0.0.1:4000/phone
  4. 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.

2

2 Answers

1
votes

These are the first solutions that come to my mind:

  1. Stop using 'pretty URLs'
  2. Use only index.md files (each of them in a seperate folder)
  3. Prevent naming collisions between folders and files
  4. Create an index.html file in the bar folder that redirects to bar.html (although that might create a redirect loop)
0
votes

Update for Jekyll 3.7.x

The 3.7.0 Jekyll release included a PR that should fix this problem: return correct file in dir if dir has same name as file