From f36f25cfa79b3f954975b97aa7a8bb6b0cbe4991 Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Tue, 23 Feb 2021 22:41:27 -0600 Subject: [PATCH] Generate sitemap endpoints from json --- build-lists.js | 30 ++++++++++++++++++++---------- nuxt.config.js | 13 ++++++++++++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/build-lists.js b/build-lists.js index c3e09ef..8c77825 100644 --- a/build-lists.js +++ b/build-lists.js @@ -25,10 +25,10 @@ class BuildLists { this.endpointSets = { // Where Nuxt Routes and Payloads get stored - nuxtEndpointsSet: new Set(), + nuxt: new Set(), // Where Eleventy Endpoints get stored - eleventyEndpointsSet: new Set() + eleventy: new Set() } this.allVideoAppsList = new Set() @@ -227,9 +227,14 @@ class BuildLists { const isGame = (app.category === 'games') if (isVideo) { - this.endpointSets.eleventyEndpointsSet.add({ + // this.endpointSets.eleventy.add({ + // route: getVideoEndpoint(app), + // // payload: buildVideoPayload( app, this.allVideoAppsList, this.lists.video ) + // }) + + this.endpointSets.nuxt.add({ route: getVideoEndpoint(app), - // payload: buildVideoPayload( app, this.allVideoAppsList, this.lists.video ) + payload: buildVideoPayload( app, this.allVideoAppsList, this.lists.video ) }) return @@ -237,13 +242,13 @@ class BuildLists { // Add benchmark endpoints for apps and games if ( isApp || isGame ) { - this.endpointSets.nuxtEndpointsSet.add({ + this.endpointSets.nuxt.add({ route: `${getAppEndpoint(app)}/benchmarks`, payload: buildAppBenchmarkPayload( app, this.allVideoAppsList, this.lists.video ) }) } - this.endpointSets.nuxtEndpointsSet.add({ + this.endpointSets.nuxt.add({ route: getAppEndpoint(app), payload: { app } }) @@ -255,7 +260,7 @@ class BuildLists { Object.keys(categories).forEach( slug => { - this.endpointSets.nuxtEndpointsSet.add({ + this.endpointSets.nuxt.add({ route: '/kind/' + slug, // payload: appList }) @@ -263,10 +268,15 @@ class BuildLists { // Save Nuxt Endpoints - await this.saveToJson(Array.from(this.endpointSets.nuxtEndpointsSet), './static/nuxt-endpoints.json') + // await this.saveToJson(Array.from(this.endpointSets.nuxt), './static/nuxt-endpoints.json') - // Save Eleventy Endpoints - await this.saveToJson(Array.from(this.endpointSets.eleventyEndpointsSet), './static/eleventy-endpoints.json') + // // Save Eleventy Endpoints + // await this.saveToJson(Array.from(this.endpointSets.eleventy), './static/eleventy-endpoints.json') + + for ( const [ endpointSetName, endpointSet ] of Object.entries(this.endpointSets) ) { + // Save Endpoints + await this.saveToJson(Array.from( endpointSet ), `./static/${endpointSetName}-endpoints.json`) + } // Save sitemap endpoints await this.saveToJson(Object.values(this.endpointSets).map( endpointSet => { diff --git a/nuxt.config.js b/nuxt.config.js index 4db7a7f..66eaf5b 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -127,7 +127,18 @@ export default { ], sitemap: { - hostname: 'https://doesitarm.com' + hostname: 'https://doesitarm.com', + routes: async () => { + // Get routes from previous build + const sitemapEndpoints = await fs.readFile('./static/sitemap-endpoints.json', 'utf-8') + .then( endpointsJson => { + return JSON.parse(endpointsJson) + }) + + console.log('Total Sitemap Endpoints', sitemapEndpoints.length) + + return sitemapEndpoints.map( endpoint => endpoint.route ) + } }, buildModules: [