首页 > 健康速递 > 正文

React app生成sitemap

日期:2023-07-07 02:32:40 来源 : 哔哩哔哩


(资料图片)

安装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目录下

上一篇:44年最高!地球最热一天又刷新,研究警告:15年内或现气候临界点 下一篇:最后一页
x

推荐阅读