返回

sitemap自动化提交方案

   
摘要GPT
摘要小助理暂时失联跑路啦……😜

并不是所有网站都像wordpress那样有插件可以实现

以下方案基于windows

假设我更新了10篇文章,那么我要如何快速也更新sitemap呢,

1、首先把这10篇链接复制到一个txt文本,每行一条链接,假设为123.txt,

2、同目录下新建一个sitemap.xml 文件 (空文件)

3、同目录下新建一个sitemap.bat脚本

4、最后新建一个推送到网站的push.sh脚本

sitemap.bat脚本

@echo off
setlocal enabledelayedexpansion

REM 设置变量
set "sitemap=sitemap.xml"
set "temp_file=temp.xml"

REM 清空sitemap.xml文件
type nul > "%sitemap%"

REM 将sitemap.xml中的<urlset>标签写入临时文件
echo ^<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="http://www.baidu.com/schemas/sitemap-mobile/1/"^> >> "%sitemap%"

REM 逐行读取123.txt中的链接,并将每个链接写入sitemap.xml中
for /f "usebackq tokens=*" %%a in ("123.txt") do (
    echo ^<url^> >> "%sitemap%"
    echo ^<loc^>%%a^</loc^> >> "%sitemap%"
    echo ^<mobile:mobile type="pc,mobile"/^> >> "%sitemap%"
    REM 获取当前时间并将其格式化为需要的格式
    for /f "delims=" %%t in ('powershell Get-Date -Format yyyy-MM-ddTHH:mm:sszzz') do set "timestamp=%%t"
    echo ^<lastmod^>!timestamp!^</lastmod^> >> "%sitemap%"
    echo ^<changefreq^>daily^</changefreq^> >> "%sitemap%"
    echo ^<priority^>1.0^</priority^> >> "%sitemap%"
    echo ^</url^> >> "%sitemap%"
)

REM 添加</urlset>标签到sitemap.xml文件中
echo ^</urlset^> >> "%sitemap%"

echo Links have been successfully inserted into the sitemap.xml file.

REM 清空123.txt文件
type nul > "123.txt"
echo 123.txt has been cleared.

push.sh脚本

这里需要你使用密钥方式连接你的服务器,教程博客有

#!/bin/bash

# 执行 SCP 命令
scp -i ~/.ssh/id_ed25519 -P 22 sitemap.xml root@223.5.5.5:/www/wwwroot/sitemap

这条命令的意思是把当前sitemap.xml文件传送到ip为223.5.5.5的服务器的/www/wwwroot/sitemap目录

运行脚本

当前目录新建一个run.bat ,来运行上面两个脚本

@echo off

rem 运行sitemap.bat
echo Running sitemap.bat
call sitemap.bat

rem 等待2秒
timeout /t 2 >nul

rem 运行push.sh
echo Running push.sh
call push.sh

echo All scripts executed successfully

如何自动化

想象一下,上面的这些操作哪些是需要变化的,文章链接是变化的,

再进一步,如果文章更新的位置是不变的,也就是说网站的布局是不变的

那么可以使用模拟鼠标键盘的操作,去复制粘贴,最后一键运行run.bat

推荐工具:

quicker的录制键鼠动作

ztasker : 定时任务工具


知识共享许可证 CC BY-NC-SA 4.0
最后更新于 2024-07-17 18:28
使用 Hugo 构建
主题 hugo-magic小洋葱 魔改 由 Jimmy 设计
Written by Human, Not by AI