diff --git a/lib/sitemap.xml.js b/lib/sitemap.xml.js
index c182b38b..d51b5e16 100644
--- a/lib/sitemap.xml.js
+++ b/lib/sitemap.xml.js
@@ -3,53 +3,52 @@ import fs from 'fs'
import BLOG from '@/blog.config'
export async function generateSitemapXml({ allPages }) {
- const urls = [{
- loc: `${BLOG.LINK}`,
- lastmod: new Date().toISOString().split('T')[0],
- changefreq: 'daily'
- }, {
- loc: `${BLOG.LINK}/archive`,
- lastmod: new Date().toISOString().split('T')[0],
- changefreq: 'daily'
- }, {
- loc: `${BLOG.LINK}/category`,
- lastmod: new Date().toISOString().split('T')[0],
- changefreq: 'daily'
- }, {
- loc: `${BLOG.LINK}/tag`,
- lastmod: new Date().toISOString().split('T')[0],
- changefreq: 'daily'
- }]
+ const urls = [{
+ loc: `${BLOG.LINK}`,
+ lastmod: new Date().toISOString().split('T')[0],
+ changefreq: 'daily'
+ }, {
+ loc: `${BLOG.LINK}/archive`,
+ lastmod: new Date().toISOString().split('T')[0],
+ changefreq: 'daily'
+ }, {
+ loc: `${BLOG.LINK}/category`,
+ lastmod: new Date().toISOString().split('T')[0],
+ changefreq: 'daily'
+ }, {
+ loc: `${BLOG.LINK}/tag`,
+ lastmod: new Date().toISOString().split('T')[0],
+ changefreq: 'daily'
+ }]
- allPages?.forEach(post => {
- urls.push({
- loc: `${BLOG.LINK}/${post.slug}`,
- lastmod: new Date(post?.date?.start_date || post?.createdTime).toISOString().split('T')[0],
- changefreq: 'daily'
- })
+ allPages?.forEach(post => {
+ urls.push({
+ loc: `${BLOG.LINK}/${post.slug}`,
+ lastmod: new Date(post?.date?.start_date || post?.createdTime).toISOString().split('T')[0],
+ changefreq: 'daily'
})
- const xml = createSitemapXml(urls)
- try {
- fs.writeFileSync('sitemap.xml', xml)
- fs.writeFileSync('./public/sitemap.xml', xml)
- } catch (error) {
- console.warn('无法写入文件', error)
- }
+ })
+ const xml = createSitemapXml(urls)
+ try {
+ fs.writeFileSync('sitemap.xml', xml)
+ fs.writeFileSync('./public/sitemap.xml', xml)
+ } catch (error) {
+ console.warn('无法写入文件', error)
+ }
+}
+function createSitemapXml(urls) {
+ let urlsXml = ''
+ urls.forEach(u => {
+ urlsXml += `
+${u.loc}
+${u.lastmod}
+${u.changefreq}
+
+`
+ })
-
- function createSitemapXml(urls) {
- let urlsXml = ''
- urls.forEach(u => {
- urlsXml += `
- ${u.loc}
- ${u.lastmod}
- ${u.changefreq}
-
- `
- })
-
- return `
-
`
- }
+}