diff --git a/build-lists.js b/build-lists.js index cceacf9..f3daa2e 100644 --- a/build-lists.js +++ b/build-lists.js @@ -5,6 +5,7 @@ import buildAppList from './helpers/build-app-list.js' 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 { videosRelatedToApp } from './helpers/related.js' import { buildVideoPayload, buildAppBenchmarkPayload } from './helpers/build-payload.js' @@ -14,6 +15,7 @@ import { getAppType, getAppEndpoint, getVideoEndpoint, + isVideo } from './helpers/app-derived.js' import { makeSearchableList } from './helpers/searchable-list.js' @@ -61,6 +63,11 @@ class BuildLists { path: '/static/homebrew-list.json', buildMethod: buildHomebrewList, }, + { + name: 'device', + path: '/static/device-list.json', + buildMethod: buildDeviceList, + }, // Secondary Derivative built lists // Always goes after initial lists @@ -225,10 +232,10 @@ class BuildLists { this.lists[listKey].forEach( app => { - const isVideo = (app.category === undefined) + // const isVideo = (app.category === undefined) const appType = getAppType( app ) - if ( isVideo ) { + if ( isVideo( app ) ) { // this.endpointMaps.eleventy.add({ // route: getVideoEndpoint(app), // payload: buildVideoPayload( app, this.allVideoAppsList, this.lists.video ) @@ -273,9 +280,14 @@ class BuildLists { relatedVideos } ) + } else if ( appType === 'device' ) { + // Add device endpoint + // console.log('Added to nuxt endpoints', app.endpoint ) + this.endpointMaps.nuxt.set( app.endpoint , { listing: app } ) + } else { // Add game or other endpoint - // console.log('Added to nuxt endpoints', getAppEndpoint(app)) + // console.log('Added to nuxt endpoints', app.endpoint ) this.endpointMaps.nuxt.set( getAppEndpoint(app), { app } ) } diff --git a/helpers/app-derived.js b/helpers/app-derived.js index 8ed7ec0..da98483 100644 --- a/helpers/app-derived.js +++ b/helpers/app-derived.js @@ -1,5 +1,10 @@ // App Data that is derived from other app data +export function isDevice ( listing ) { + if ( !listing.hasOwnProperty('endpoint') ) return false + + return listing.endpoint.startsWith('/device/') +} export function isVideo ( app ) { return app.hasOwnProperty('thumbnail') && app.hasOwnProperty('timestamps') @@ -13,6 +18,10 @@ export function getAppType ( app ) { return 'video' } + if ( isDevice( app ) ) { + return 'device' + } + if(app.category !== Object(app.category)) { console.warn('app has no categories', app) diff --git a/helpers/build-device-list.js b/helpers/build-device-list.js new file mode 100644 index 0000000..2cbaec1 --- /dev/null +++ b/helpers/build-device-list.js @@ -0,0 +1,33 @@ +import axios from 'axios' + +import { makeSlug } from './slug.js' + +export function getDeviceEndpoint ( slug ) { + return `/device/${ slug }` +} + + + +export default async function () { + + const devicesJsonUrl = `${process.env.VFUNCTIONS_URL}/api/devices` + + const rawDeviceList = await axios.get(devicesJsonUrl) + .then( response => { + return response.data + }) + .catch(function (error) { + // handle error + console.warn('Error fetching device list', error) + }) + + return rawDeviceList.map( device => { + const slug = makeSlug( device.name ) + + return { + ...device, + slug, + endpoint: getDeviceEndpoint( slug ), + } + }) +}