【发布时间】:2017-01-12 02:00:53
【问题描述】:
Jekyll 默认使用指定的变量来生成永久链接。但在我的情况下,我需要永久链接来使用页面特定变量(如 chapter)来生成类似 /chapters/:chapter 的 URL,而不是使用日期和其他内容
【问题讨论】:
-
使用集合?
标签: ruby jekyll jekyll-extensions
Jekyll 默认使用指定的变量来生成永久链接。但在我的情况下,我需要永久链接来使用页面特定变量(如 chapter)来生成类似 /chapters/:chapter 的 URL,而不是使用日期和其他内容
【问题讨论】:
标签: ruby jekyll jekyll-extensions
您不能使用任何前端变量来创建永久链接,只能使用the Jekyll defined keys for the type of page。
如 Wickramaranga 所说,要获取您所追求的 URL,您可以使用集合。在你的 _config.yml 中,你定义你的章节集合:
collections:
chapters:
output: true
permalink: /chapters/:title/
然后创建您的章节,例如/_chapters/1.md, /_chapters/2.md.
这将创建 http://localhost:4000/chapters/1/ 和 http://localhost:4000/chapters/2/
【讨论】: