Store endpoints as map to prevent duplicates

This commit is contained in:
Sam Carlton 2021-03-06 16:32:55 -06:00
parent ffb4b08e26
commit c031582964

View file

@ -23,12 +23,12 @@ class BuildLists {
// Where our lists are stored // Where our lists are stored
this.lists = {} this.lists = {}
this.endpointSets = { this.endpointMaps = {
// Where Nuxt Routes and Payloads get stored // Where Nuxt Routes and Payloads get stored
nuxt: new Set(), nuxt: new Map(),
// Where Eleventy Endpoints get stored // Where Eleventy Endpoints get stored
eleventy: new Set() eleventy: new Map()
} }
this.allVideoAppsList = new Set() this.allVideoAppsList = new Set()
@ -224,15 +224,12 @@ class BuildLists {
const appType = getAppType( app ) const appType = getAppType( app )
if ( isVideo ) { if ( isVideo ) {
// this.endpointSets.eleventy.add({ // this.endpointMaps.eleventy.add({
// route: getVideoEndpoint(app), // route: getVideoEndpoint(app),
// payload: buildVideoPayload( app, this.allVideoAppsList, this.lists.video ) // payload: buildVideoPayload( app, this.allVideoAppsList, this.lists.video )
// }) // })
this.endpointSets.nuxt.add({ this.endpointMaps.nuxt.set( getVideoEndpoint(app), buildVideoPayload( app, this.allVideoAppsList, this.lists.video ) )
route: getVideoEndpoint(app),
payload: buildVideoPayload( app, this.allVideoAppsList, this.lists.video )
})
return return
} }
@ -245,26 +242,31 @@ class BuildLists {
// Only add a benchmarks endpoint if it has any videos // Only add a benchmarks endpoint if it has any videos
if ( payload.allVideos.length > 0 ) { if ( payload.allVideos.length > 0 ) {
this.endpointSets.nuxt.add({ // this.endpointMaps.nuxt.add({
route: `${getAppEndpoint(app)}/benchmarks`, // route: `${getAppEndpoint(app)}/benchmarks`,
payload: buildAppBenchmarkPayload( app, this.allVideoAppsList, this.lists.video ) // payload: buildAppBenchmarkPayload( app, this.allVideoAppsList, this.lists.video )
}) // })
this.endpointMaps.nuxt.set( `${getAppEndpoint(app)}/benchmarks`, buildAppBenchmarkPayload( app, this.allVideoAppsList, this.lists.video ) )
} }
} }
// Add standard app endpoint // Add standard app endpoint
if ( appType === 'formula' ) { if ( appType === 'app' || appType === 'formula' ) {
this.endpointSets.eleventy.add({ // this.endpointMaps.eleventy.add({
route: getAppEndpoint(app), // route: getAppEndpoint(app),
payload: { app } // payload: { app }
}) // })
this.endpointMaps.eleventy.set( getAppEndpoint(app), { app } )
} else { } else {
// Add app or game endpoint // Add app or game endpoint
this.endpointSets.nuxt.add({ // this.endpointMaps.nuxt.add({
route: getAppEndpoint(app), // route: getAppEndpoint(app),
payload: { app } // payload: { app }
}) // })
// console.log('Added to nuxt endpoints', getAppEndpoint(app)) // console.log('Added to nuxt endpoints', getAppEndpoint(app))
this.endpointMaps.nuxt.set( getAppEndpoint(app), { app } )
} }
return return
@ -273,28 +275,30 @@ class BuildLists {
} }
// Create endpoints for categories
Object.keys(categories).forEach( slug => { Object.keys(categories).forEach( slug => {
this.endpointSets.nuxt.add({ // this.endpointMaps.nuxt.add({
route: '/kind/' + slug, // route: '/kind/' + slug,
// payload: appList // // payload: appList
}) // })
this.endpointMaps.nuxt.set( '/kind/' + slug, {} )
}) })
// Save Nuxt Endpoints // Save Nuxt Endpoints
// await this.saveToJson(Array.from(this.endpointSets.nuxt), './static/nuxt-endpoints.json') // await this.saveToJson(Array.from(this.endpointMaps.nuxt), './static/nuxt-endpoints.json')
// // Save Eleventy Endpoints // // Save Eleventy Endpoints
// await this.saveToJson(Array.from(this.endpointSets.eleventy), './static/eleventy-endpoints.json') // await this.saveToJson(Array.from(this.endpointMaps.eleventy), './static/eleventy-endpoints.json')
for ( const [ endpointSetName, endpointSet ] of Object.entries(this.endpointSets) ) { for ( const [ endpointSetName, endpointSet ] of Object.entries(this.endpointMaps) ) {
// Save Endpoints // Save Endpoints
await this.saveToJson(Array.from( endpointSet ), `./static/${endpointSetName}-endpoints.json`) await this.saveToJson(Array.from( endpointSet , ([route, payload]) => ({ route, payload })), `./static/${endpointSetName}-endpoints.json`)
} }
// Save sitemap endpoints // Save sitemap endpoints
await this.saveToJson(Object.values(this.endpointSets).map( endpointSet => { await this.saveToJson(Object.values(this.endpointMaps).map( endpointSet => {
return Array.from( endpointSet ) return Array.from( endpointSet , ([route, payload]) => ({ route, payload }) )
} ).flat(1), './static/sitemap-endpoints.json') } ).flat(1), './static/sitemap-endpoints.json')
return return