go-sonic / sonic

Sonic is a blogging platform developed by Go. Simple and powerful
MIT License
1.99k stars 255 forks source link

sonic所生成的站点地图无法被Google抓取 #400

Open aaro-n opened 4 months ago

aaro-n commented 4 months ago

检查清单

是什么版本出现了此问题?

1.1.4

使用的什么数据库?

Other

使用的哪种方式部署?

Docker

在线站点地址

https://www.itansuo.info/

发生了什么?

在google search console 提交sonic所生成的站点地图,google search console 提示有错误,要修正。 Google

相关日志输出

附加信息

https://www.itansuo.info/sonic.xml

aaro-n commented 4 months ago

在bing测试站点地图,看起来是没问题的。

aaro-n commented 4 months ago

临时解决方案,下载sitemap.xml文件,用脚本修改sitemap.xml内容,另存为后在nginx配置访问这个文件

sonic-sitemap.sh脚本

#!/bin/bash

# 获取远程 sitemap.xml 文件
# 根据自己的实际情况调整sitemap.xml 可访问地址
wget -q -O /tmp/sitemap.xml http://172.0.0.1:8080/sitemap.xml

# 检查获取文件是否失败
if [ $? -ne 0 ]; then
            echo "无法获取远程 sitemap.xml 文件。跳过更新过程。"
                exit 1
fi

# 获取本地 sitemap.xml 文件中的第2个 <lastmod> 值
# 根据自己的实际情况修改`/home/www/nginx/html/sonic/sitemap.xml `
lastmod_local=$(grep '<lastmod>' /home/www/nginx/html/sonic/sitemap.xml | head -2 | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1)

# 获取远程 sitemap.xml 文件中的第2个 <lastmod> 值
lastmod_tmp=$(grep '<lastmod>' /tmp/sitemap.xml | head -2 | tail -1 | cut -d '>' -f 2 | cut -d '<' -f 1)

# 比较两个 <lastmod> 值
if [ "$lastmod_local" = "$lastmod_tmp" ]; then
            echo "sitemap 未更新。跳过更新过程。"
                exit 0
fi

# 修改 sitemap.xml 中的 URL
# 将www.itansuo.info代替为自己的sonic公网域名
sed -i 's/<loc>\/archives\//<loc>https:\/\/www.itansuo.info\/archives\//g' /tmp/sitemap.xml

# 将修改后的文件保存到本地目录
# 根据自己的实际情况修改
# 与 # 获取本地 sitemap.xml 文件中的第2个 <lastmod> 值 相关联
rm /home/www/nginx/html/sonic/sitemap.xml
mv /tmp/sitemap.xml /home/www/nginx/html/sonic/

echo "sitemap 已更新。"

nginx配置 根据自己的实际情况修改

    location = /sonic.xml {
         alias /home/www/nginx/html/sonic/sitemap.xml; 
    }

赋予 sonic-sitemap.sh脚本脚本执行权限 chmod +x sonic-sitemap.sh

可以设置crontab每天运行一次脚本。

github-actions[bot] commented 1 day ago

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 5 days