网站robot文件可以加sitemap.txt吗?
<p>如果在robots文件里面加入sitemap.txt可以吗?不是sitemap.xml<br></p><p>例如这样的 </p>
4 人参与回答
看看别人的回答。
Robots.txt在线生成:
robots文件生成 在线网站robots.txt文件生成器
robots.txt:
robots.txt
User-agent: *Disallow:
Disallow: /cgi-bin/
Sitemap: 使用node生成文件:
const { SitemapStream, streamToPromise } = require('sitemap')
const { Readable } = require('stream')
//遍历文件夹获取link列表
const getLinks = async () => {
return await new Promise((resolve, rejects) => {
(outputDir, function (err, files) {
if (err) {
(err)
} else {
let links = (item => {
return { url:
${('md', 'html')}
, changefreq: 'daily', priority: }})
resolve(links)
}
})
})
}
//根据link列表生成文件
const getSitemap = async (req, res) => {
const links = await getLinks()
//const links = [{ url: '/page-1/', changefreq: 'daily', priority: }]
// Create a stream to write to
const stream = new SitemapStream({ hostname: '' })
// Return a promise that resolves with your XML string
let mySitemap = '1'
await streamToPromise((links).pipe(stream)).then((data) => {
mySitemap = ()
})
const sitemapFilePath = './csdn/'
(sitemapFilePath, mySitemap, { encoding: 'utf8' }, (err) => {})
({
state: 1,
data: {
mySitemap,
links
},
message: 'sitemap'
})
}