您当前所在的位置: 首页 > 健康速递 > > 正文

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

关键词:
x 广告
x 广告

Copyright ©  2015-2022 南方健康网版权所有  备案号:粤ICP备18023326号-21   联系邮箱:855 729 8@qq.com