diff --git a/build-lists.js b/build-lists.js index a090163..aa1a67a 100644 --- a/build-lists.js +++ b/build-lists.js @@ -13,6 +13,7 @@ import buildGamesList from '~/helpers/build-game-list.js' import buildHomebrewList from '~/helpers/build-homebrew-list.js' import buildVideoList from '~/helpers/build-video-list.js' import buildDeviceList from '~/helpers/build-device-list.js' +import { saveSitemap } from '~/helpers/api/sitemap/build.js' import { deviceSupportsApp } from '~/helpers/devices.js' import getListSummaryNumbers from '~/helpers/get-list-summary-numbers.js' @@ -697,13 +698,14 @@ class BuildLists { }) } ) - // Add paginated category lists to sitemap - // sitemapEndpoints.push( ...this.getKindListForCategories() ) - // Save sitemap endpoints console.log('Building Sitemap JSON') await this.saveToJson( sitemapEndpoints, './static/sitemap-endpoints.json') + // Save XML Sitemap + console.log('Building XML Sitemap') + await saveSitemap( sitemapEndpoints.map( ({ route }) => route ) ) + // Save stork toml index console.log('Building Stork toml index') await writeStorkToml( sitemapEndpoints ) diff --git a/helpers/api/sitemap/build.js b/helpers/api/sitemap/build.js new file mode 100644 index 0000000..578a71e --- /dev/null +++ b/helpers/api/sitemap/build.js @@ -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' + } + }), + }) + +} diff --git a/helpers/constants.js b/helpers/constants.js index 1bc0880..f6d7411 100644 --- a/helpers/constants.js +++ b/helpers/constants.js @@ -1,2 +1,6 @@ export const filterSeparator = '_' + +export const sitemapLocation = './static/' + +export const sitemapIndexFileName = 'sitemap-index.xml' \ No newline at end of file