Jekyll 默认情况下使用指定的变量来生成永久链接。但就我而言,我需要永久链接来使用特定于页面的变量(例如 chapter
)来生成 url(例如 /chapters/:chapter
),而不是使用日期和其他内容
最佳答案
您不能使用任何 Front Matter 变量来创建永久链接,只能使用 the Jekyll defined keys for the type of page .
要获取您想要的 URL,您可以使用集合,正如 Wickramaranga 所说。在 _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/
关于ruby - JekyllRB : how to create an online book (force permalink to be like chapter/1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39318048/