解決Hexo建立Sitemap的錯誤網址內容

在Google管理員後台發現一堆網址被檢索為404。
找不到已提交的網址_1

點開其中一個網址,右側顯示被檢索的網址是錯的。
找不到已提交的網址_2

錯誤網址:

https://carlos.my-net.tw/Tasker%25E6%258E%25A7%25E5%2588%25B6AdGuard%25E9%2596%258B%25E9%2597%259C/

正確網址:

https://carlos.my-net.tw/Tasker%E6%8E%A7%E5%88%B6AdGuard%E9%96%8B%E9%97%9C/

打開sitemap.xml檢查內容,發現所有建立的網址內容都是錯的,每個中文編碼字元都被加了%25
Hexo Sitemap錯誤網址內容

確定的是,這是Hexo升級到4.0.0才出現的問題。參考這篇〈Hexo博客提交搜索引擎〉的方法,開啟node_modules/hexo-generator-sitemap/sitemap.xml,將:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  {% for post in posts %}
  
    {{ post.permalink | uriencode }}
    {% if post.updated %}
    {{ post.updated.toISOString() }}
    {% elif post.date %}
    {{ post.date.toISOString() }}
    {% endif %}
  
  {% endfor %}
</urlset>

改為:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  {% for post in posts %}
  
    {{ (config.urlforgoogle+post.path) | uriencode }}
    {% if post.updated %}
    {{ post.updated.toISOString() }}
    {% elif post.date %}
    {{ post.date.toISOString() }}
    {% endif %}
  
  {% endfor %}
</urlset>

開啟網站設定檔_config.yml,加入一行:

urlforgoogle: https://carlos.my-net.tw/ #你的網域名稱

開啟終端機輸入hexo cleanhexo g重建一次上傳,到Google管理員後台刪除Sitemap再提交一次,最後點選[驗證修正後的項目],等更新結果。

已回報該問題,確認是Bug,等hexo-generator-sitemap更新。