diff --git a/build-lists.js b/build-lists.js index 57a75cc..e7433d0 100644 --- a/build-lists.js +++ b/build-lists.js @@ -13,7 +13,10 @@ 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 { + saveSitemap, + getUrlsForAstroDefinedPages +} from '~/helpers/api/sitemap/build.js' import { deviceSupportsApp } from '~/helpers/devices.js' import getListSummaryNumbers from '~/helpers/get-list-summary-numbers.js' import { logArraysDifference } from '~/helpers/array.js' @@ -702,6 +705,12 @@ class BuildLists { }) } ) + // Add routes for Astro pages + const astroPageUrls = await getUrlsForAstroDefinedPages() + + console.log( 'astroPageUrls', astroPageUrls ) + + // Save sitemap endpoints console.log('Building Sitemap JSON') await this.saveToJson( sitemapEndpoints, './static/sitemap-endpoints.json') diff --git a/helpers/api/sitemap/build.js b/helpers/api/sitemap/build.js index 578a71e..bdfd4a4 100644 --- a/helpers/api/sitemap/build.js +++ b/helpers/api/sitemap/build.js @@ -1,10 +1,39 @@ -// import fs from 'fs-extra' +import glob from 'fast-glob' import { simpleSitemapAndIndex } from 'sitemap' -import { - sitemapLocation +import { + sitemapLocation } from '~/helpers/constants.js' +import { getSiteUrl } from '~/helpers/url.js' + +const astroPageTemplatePath = './src/pages' + +export async function getUrlsForAstroDefinedPages () { + const siteUrl = getSiteUrl() + const filesPaths = await glob( `${ astroPageTemplatePath }/**/*.astro` ) + + const urls = [] + + for ( const filePath of filesPaths ) { + const urlPath = filePath + .replace( astroPageTemplatePath, '' ) + .replace( '.astro', '' ) + .replace( '/index', '/' ) + + // Skip any paths for templates that include '[' + if ( urlPath.includes( '[' ) ) continue + + console.log( 'urlPath', urlPath ) + + // Create a new url object from the site url and the path + const url = new URL( urlPath, siteUrl ) + + urls.push( url.pathname ) + } + + return urls +} export async function saveSitemap ( sitemapUrls ) {