How to link to a page with page.url without the html extension in Jekyll?

一笑奈何 提交于 2019-12-04 03:03:54

问题


I'm building a website in Jekyll. To remove html extension in posts I added the following to _config.yml

permalink:        /kb/:title

To remove html extension from pages, I created folders for each page, and placed an index.html file in each page folder.

Now the posts and pages work without html extension, but when I link to a page with page.url it returns the whole link (/kb/index.html) instead of just /kb.

What variable can I use to link to a page without html extension?


回答1:


The value returned by {{ page.url }} reflects what the permalink for the page is.

To get the urls to not include the "index.html" part you will need to add a permalink setting to the front matter for each of these pages. This actually removes the need of having all the files named "index.html" and in separate folders.

So your front matter would contain something like:

---
permalink: /scratchpad/level/relative/
---

Note the trailing slash, if you omit this then Jekyll would create a file called "relative" instead of a directory containing an index.html file.



来源:https://stackoverflow.com/questions/22034994/how-to-link-to-a-page-with-page-url-without-the-html-extension-in-jekyll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!