为 _collection/foo.md` 生成的 link `/foo` 在本地不起作用(但在 Github 页面上起作用)
Generated link `/foo` for `_collection/foo.md` doesn't work work locally (but does on Github Pages)
我的 Jekyll 项目中有以下文件结构:
├── _articles
│ ├── bar
│ │ └── widget.md
│ ├── bar.md
│ └── phone.md
└── foo.md
看这里:https://github.com/janpio/jekyll-test
_articles
是在 _config.yml
:
中定义的集合
collections:
articles:
title: Articles
output: true
permalink: :path
在 Github 页面上,这是内置到这些 URI 中的:
- 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/
看这里:https://janpio.github.io/jekyll-test/
一切都很好,符合预期。
但是当我 bundle exec jekyll s
在本地 1 这个项目时,它的工作方式不同。我得到预期的 URI:
- 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/
但问题是 #2 被重定向到 127.0.0.1:4000/bar/
并显示目录列表而不是实际页面!
查看_site
这是生成的文件结构:
├── bar
│ └── widget.html
├── bar.html
├── foo.html
├── index.html
└── phone.html
所以我可以在 http://127.0.0.1:4000/bar.html
访问 bar.md
。
我该如何解决这个问题?
1 我的 Gemfile 环境应该与 Github 页面相同:https://github.com/janpio/jekyll-test/blob/master/Gemfile
Jekyll 3 更新。6.x
3.6.0 Jekyll release changed this behaviour:
Fix serving files that clash with directories (#6222) (#6231)
不幸的是,这些更改并没有真正解决问题,而是用一个不太严重的问题代替它:link 现在 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
。
这些是我想到的第一个解决方案:
- 停止使用 'pretty URLs'
- 仅使用 index.md 个文件(每个文件都在一个单独的文件夹中)
- 防止文件夹和文件之间的命名冲突
- 在重定向到 bar.html 的 bar 文件夹中创建一个 index.html 文件(尽管这可能会创建一个重定向循环)
Jekyll 3 更新。7.x
Jekyll 3.7.0 版本包含一个应该可以解决此问题的 PR:
return correct file in dir if dir has same name as file
我的 Jekyll 项目中有以下文件结构:
├── _articles
│ ├── bar
│ │ └── widget.md
│ ├── bar.md
│ └── phone.md
└── foo.md
看这里:https://github.com/janpio/jekyll-test
_articles
是在 _config.yml
:
collections:
articles:
title: Articles
output: true
permalink: :path
在 Github 页面上,这是内置到这些 URI 中的:
- 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/
看这里:https://janpio.github.io/jekyll-test/
一切都很好,符合预期。
但是当我 bundle exec jekyll s
在本地 1 这个项目时,它的工作方式不同。我得到预期的 URI:
- 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/
但问题是 #2 被重定向到 127.0.0.1:4000/bar/
并显示目录列表而不是实际页面!
查看_site
这是生成的文件结构:
├── bar
│ └── widget.html
├── bar.html
├── foo.html
├── index.html
└── phone.html
所以我可以在 http://127.0.0.1:4000/bar.html
访问 bar.md
。
我该如何解决这个问题?
1 我的 Gemfile 环境应该与 Github 页面相同:https://github.com/janpio/jekyll-test/blob/master/Gemfile
Jekyll 3 更新。6.x
3.6.0 Jekyll release changed this behaviour:
Fix serving files that clash with directories (#6222) (#6231)
不幸的是,这些更改并没有真正解决问题,而是用一个不太严重的问题代替它:link 现在 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
。
这些是我想到的第一个解决方案:
- 停止使用 'pretty URLs'
- 仅使用 index.md 个文件(每个文件都在一个单独的文件夹中)
- 防止文件夹和文件之间的命名冲突
- 在重定向到 bar.html 的 bar 文件夹中创建一个 index.html 文件(尽管这可能会创建一个重定向循环)
Jekyll 3 更新。7.x
Jekyll 3.7.0 版本包含一个应该可以解决此问题的 PR: return correct file in dir if dir has same name as file