Fix formatiing in generateSitemap

This commit is contained in:
r-freeman 2023-01-14 22:17:58 +00:00
parent b6f13fd99a
commit d8157c148b

View File

@ -6,24 +6,24 @@ import {writeFile} from 'fs/promises'
const BASE_URL = process.env.NEXT_PUBLIC_SITE_URL
async function createSitemap(pages) {
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
const sitemap =
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${pages.map((url) => {
return `
<url>
${pages.map((url) =>
`<url>
<loc>${url}</loc>
<lastmod>${new Date().toISOString()}</lastmod>
<changefreq>monthly</changefreq>
<priority>1.0</priority>
</url>`
}).join("")}
</urlset>`
</url>`).join('')}
</urlset>`.replace(/(\s\s+|\t)/g, ' ').trim()
await writeFile('./public/sitemap.xml', sitemap, 'utf8')
}
async function createRobots() {
const robots = `# *
const robots =
`# *
User-agent: *
Allow: /
@ -31,7 +31,7 @@ Allow: /
Host: ${BASE_URL}
# Sitemaps
Sitemap: ${BASE_URL}/sitemap.xml`
Sitemap: ${BASE_URL}/sitemap.xml`.replace(/(\s\s+|\t)/g, ' ').trim()
await writeFile('./public/robots.txt', robots, 'utf8')
}