Save sitemap as xml during build

This commit is contained in:
Sam Carlton 2022-06-06 20:41:37 -05:00
parent fc8dd41f18
commit 915c1b0a3a
3 changed files with 34 additions and 3 deletions

View file

@ -0,0 +1,25 @@
// import fs from 'fs-extra'
import { simpleSitemapAndIndex } from 'sitemap'
import {
sitemapLocation
} from '~/helpers/constants.js'
export async function saveSitemap ( sitemapUrls ) {
await simpleSitemapAndIndex({
hostname: process.env.PUBLIC_URL,
destinationDir: sitemapLocation,
gzip: false,
// [{ url: '/page-1/', changefreq: 'daily'}, ...],
sourceData: sitemapUrls.map( url => {
return {
url,
// Google doesn't care about changefreq and priority - https://www.seroundtable.com/google-priority-change-frequency-xml-sitemap-20273.html
// changefreq: 'daily'
}
}),
})
}

View file

@ -1,2 +1,6 @@
export const filterSeparator = '_'
export const sitemapLocation = './static/'
export const sitemapIndexFileName = 'sitemap-index.xml'