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