我正在使用节点包(sitemap-generator)为我的有角网站创建sitemap.xml文件, 目前,我正在机器上手动运行此代码,然后每次上载生成的文件。 我有什么方法可以自动化此过程,也许是通过上传代码并定期自动运行它
答案 0 :(得分:0)
您可以使用node-scehdule
模块每天在特定时间运行站点地图生成器,可以根据需要设置时间
const SitemapGenerator = require('sitemap-generator');
const cron = require('node-schedule');
const generator = SitemapGenerator('https://examaple.com', {
maxDepth: 0,
filepath: '/var/www/example.com/sitemap.xml',
maxEntriesPerFile: 50000,
stripQuerystring: true,
lastMod:true
});
cron.schedule('0 22 * * *', () => {
console.log("will run at 10:00 PM everyday");
generator.start();
});