为了加快搜索引擎收录博客文章,往往需要手动提交sitemap,Gridea会自动生成站点地图,名为atom.xml,提交到对应位置即可。
百度sitemap提交
https://ziyuan.baidu.com

注意: Gridea生成的 atom.xml 主要为SSR订阅使用,百度无法抓取,需要手动修改、添加一些文件。
生成百度可识别的sitemap
找到Gridea的文件夹(设置里的站点源文件路径),笔者自定义的路径为D:\Blog,然后找到主题的templates文件夹下的post.ejs,我的位置示例(Next主题):D:\Blog\themes\next\templates\post.ejs。把以下代码放在下图位置即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://cdn.jsdelivr.net/gh/ganzhilin/cdn@master/sitemap/push_1.js'; } else { bp.src = 'https://cdn.jsdelivr.net/gh/ganzhilin/cdn@master/sitemap/push_2.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script>
|

D:\Blog\themes\next\templates\处创建一个sitemap.ejs,复制以下代码并保存,重新启动Gridea并同步即可得到符合百度要求的 sitemap。
1 2 3 4 5 6 7 8 9
| <%- sitemap() %><% -%> <% function sitemap(){ let links='' site.posts.forEach(function(post){ links+=post.link+'\n' }) return links }%>
|
生成的文件是 html 文件,以本站点为例,提交 sitemap 的链接为:
1
| https://ganzhilin.net/sitemap/index.html
|
谷歌sitemap提交