如何在Jekyll中链接不带html扩展名的具有page.url的页面? [英] How to link to a page with page.url without the html extension in Jekyll?
问题描述
我正在Jekyll建立一个网站.为了删除帖子中的html扩展名,我在_config.yml
I'm building a website in Jekyll. To remove html extension in posts I added the following to _config.yml
permalink: /kb/:title
要从页面中删除html扩展名,我为每个页面创建了文件夹,并在每个页面文件夹中放置了一个index.html文件.
To remove html extension from pages, I created folders for each page, and placed an index.html file in each page folder.
现在,帖子和页面无需html扩展名即可工作,但是当我使用page.url链接到页面时,它将返回整个链接(/kb/index.html),而不仅仅是/kb.
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.
我可以使用哪个变量链接到没有html扩展名的页面?
What variable can I use to link to a page without html extension?
推荐答案
{{ page.url }}
返回的值反映了页面的永久链接.
The value returned by {{ page.url }}
reflects what the permalink for the page is.
要使网址不包含"index.html"部分,您需要为每个页面的首页添加一个永久链接设置.实际上,这消除了将所有名为"index.html"的文件放在单独的文件夹中的需要.
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/
---
请注意末尾的斜杠,如果您省略此斜杠,那么Jekyll将创建一个称为相对"的文件,而不是包含index.html文件的目录.
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.
这篇关于如何在Jekyll中链接不带html扩展名的具有page.url的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!