给 eleventy(11ty) 添加 sitemap.xml 和 robots.txt
配置过程
- 添加数据文件
_data/site.json,写入以下内容,定义站点信息和 sitemap 中的一些默认值:
1 | { |
- 添加 sitemap 模板文件,写入以下内容:
1 | --- |
【可选】配置不同页面的 sitemap 表现:
- 如果不希望某些页面在被包含在 sitemap 文件中,在页面元数据中添加
sitemap.ignore: true即可; - 可以对不同的页面设置不同的 sitemap 优先级,在页面元数据中添加
sitemap.priority: 0.5,取值范围 0-1; - 对于分页数据,要设置
pagination.addAllPagesToCollections: true才会在sitemap.xml文件中包含每一个分页页面。
- 如果不希望某些页面在被包含在 sitemap 文件中,在页面元数据中添加
添加模板文件
src/robots.txt,写入以下内容:
1 | --- |
重新编译,over!
参考文档
- How to create sitemap.xml
- Sitemap xml
- liquid
- sitemap format