(资料图片)
安装node
npm install sitemap axios
写一个sitemap generator, 例子
const { SitemapStream, streamToPromise } = require('sitemap');const { createWriteStream } = require('fs');const { resolve } = require('path');const axios = require('axios');async function generateSitemap() { const links = [ // Array of your website's URLs { url: '/', changefreq: 'weekly', priority: }, { url: '/about', changefreq: 'weekly', priority: }, // Add more URLs as needed ]; // Create a new sitemap stream const stream = new SitemapStream({ hostname: '' }); // Generate sitemap by adding each link to the stream ((link) => { (link); }); (); // Convert the stream to a promise const sitemap = await streamToPromise(stream); // Save the sitemap to a file const filePath = resolve(__dirname, ''); const writeStream = createWriteStream(filePath); (()); (); (`Sitemap generated successfully at ${filePath}`);}// Call the generateSitemap functiongenerateSitemap();
最后运行:
node
就会生成到指定路径,一般在public目录下