const fs = require('fs')
const path = require('path')
const domain = 'https://doc.dcloud.net.cn'
const xmlBefore = `
`
const xmlAfter = `\n`
module.exports = (links, callback = () => { }) => {
const xmlItems = links.map(url => {
if (!url.endsWith('/') && !url.endsWith('html')) url += '.html'
return `
${domain + url}
`
}).join('\n')
const rootPath = path.resolve(__dirname, '../public')
const staticExists = fs.existsSync(rootPath)
if (!staticExists) fs.mkdirSync(rootPath)
fs.writeFile(
path.resolve(rootPath, 'sitemap.xml'),
xmlBefore + xmlItems + xmlAfter,
{ encoding: 'utf-8' },
callback
)
}