如何使用Jekyll site.pages生成sitemap.xml
我正在尝试使用site.pages在Jekyll(GitHub pages)中自动生成如何使用Jekyll site.pages生成sitemap.xml,jekyll,github-pages,Jekyll,Github Pages,我正在尝试使用site.pages在Jekyll(GitHub pages)中自动生成sitemap.xml,这是我得到的sitemap.xml代码: --- --- <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> {% for page in site.pages %} <url>
sitemap.xml
,这是我得到的sitemap.xml
代码:
---
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in site.pages %}
<url>
<loc>https://example.com{{ page.url | remove: 'index.html' }}</loc>
</url>
{% endfor %}
</urlset>
---
---
{site.pages%中的页面为%s}
https://example.com{{page.url}删除:'index.html'}
{%endfor%}
它的输出与此类似:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/samplepage.html</loc>
<!--<loc>https://example.com/samplepage</loc>-->
</url>
</urlset>
https://example.com/samplepage.html
我的目标是生成一个sitemap.xml,而不使用注释行中的拖尾.html
。我尝试了gsub
(我假设Jekyll采用Ruby语法:),但它似乎没有改变任何东西,或者完全删除了page.url
如果有人可以,我将不胜感激
.html
|remove:'index.html'
(它删除URLhttps://example.com/index.html
来自生成的sitemap.xml
)remove
是其中之一,因此Jekyll文档没有列出它
如果根文件夹中有此文件,则页面URL很简单:
samplepage.html # https://example.com/samplepage.html
相反,如果您有:
samplepage/
index.html # https://example.com/samplepage/index.html
# https://example.com/samplepage/
页面URL最终成为文件夹名称,如果您使用第二个链接,服务器将自动为其中的index.html
文件提供服务
site.pages
将为您提供第一个链接。由于您有一个从路径中删除index.html
的过滤器,您最终会得到。Jekyll文件夹中的任何文件都是以其扩展名生成的,除非您使用
如果像这样创建sitemap.xml
文件:
---
layout: null
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for page in site.pages %}
<url>
<loc>https://example.com{{ page.url | remove: 'index.html' }}</loc>
</url>
{% endfor %}
</urlset>
---
布局:空
---
{site.pages%中的页面为%s}
https://example.com{{page.url}删除:'index.html'}
{%endfor%}
它将生成为sitemap.xml
您还可以使用github页面支持的wich。Awesome。正是我要找的!