diff --git a/helpers/build-payload.js b/helpers/build-payload.js new file mode 100644 index 0000000..3dc4ed9 --- /dev/null +++ b/helpers/build-payload.js @@ -0,0 +1,55 @@ + + +import { appsRelatedToVideo, videosRelatedToVideo, videosRelatedToApp } from './related.js' +// import videoList from '~/static/video-list.json' + + +export function buildVideoPayload ( video, allVideoAppsList, videoList ) { + // const { appsRelatedToVideo, videosRelatedToVideo } = await import('~/helpers/related.js') + // const { default: videoList } = await import('~/static/video-list.json') + + // Find the video for our current page + // const video = videoList.find(video => (video.slug === slug)) + + // Get featured apps + const featuredApps = appsRelatedToVideo( video, allVideoAppsList ) + + // Get related videos + const relatedVideos = videosRelatedToVideo( video, allVideoAppsList, videoList ) + + return { + video, + featuredApps, + // If no related video found just get the 12 newest ones + relatedVideos: (relatedVideos.length !== 0) ? relatedVideos : videoList.slice(0, 12) + } +} + + +export function buildAppBenchmarkPayload ( app, allVideoAppsList, videoList ) { + // const { allVideoAppsList } = await import('~/helpers/get-list.js') + + // const { videosRelatedToApp } = await import('~/helpers/related.js') + + // const app = allVideoAppsList.find(app => (app.slug === slug)) + + const submitVideoCard = { + endpoint: `https://docs.google.com/forms/d/e/1FAIpQLSeEVGM9vE7VcfLMy6fJkfU70X2VZ60rHDyhDQLtnAN4nso0WA/viewform?usp=pp_url&entry.1018125313=${app.name}` + } + + // const featuredApps = [] + + const relatedVideos = videosRelatedToApp( app, videoList ).map(video => { + // console.log('video', video) + return { + ...video, + // endpoint: `#${video.id}` + } + }) + + return { + app, + allVideos: relatedVideos, + submitVideoCard + } +} diff --git a/helpers/get-list.js b/helpers/get-list.js index f67787e..ac861c4 100644 --- a/helpers/get-list.js +++ b/helpers/get-list.js @@ -21,9 +21,9 @@ export const allList = [ ] -export function makeAppSearchLinks (app) { +export function makeAppSearchLinks ( app, videoList ) { - const videos = videosRelatedToApp(app) + const videos = videosRelatedToApp( app, videoList ) // If there are no videos // then skip diff --git a/helpers/related.js b/helpers/related.js index c22a510..700b289 100644 --- a/helpers/related.js +++ b/helpers/related.js @@ -1,15 +1,16 @@ -import { allVideoAppsList } from '~/helpers/get-list.js' -import videoList from '~/static/video-list.json' +// import { allVideoAppsList } from '~/helpers/get-list.js' +// import videoList from '~/static/video-list.json' export function matchesWholeWord (needle, haystack) { return new RegExp('\\b' + needle + '\\b').test(haystack) } -export function appsRelatedToVideo ( video ) { +export function appsRelatedToVideo ( video, allVideoAppsList ) { const relatedApps = [] // Find the apps listed in this video for (const app of allVideoAppsList) { + // console.log('video', video) // Skip this app if it's not listed in the videos apps if (!video.apps.includes(app.slug)) continue @@ -20,14 +21,18 @@ export function appsRelatedToVideo ( video ) { return relatedApps } -export function videosRelatedToVideo ( video ) { +export function videosRelatedToVideo ( video, allVideoAppsList, videoList ) { const relatedVideos = {} - const featuredApps = appsRelatedToVideo( video ) + // console.log('videoList', videoList[0]) + // console.log('allVideoAppsList', allVideoAppsList[0]) + + const featuredApps = appsRelatedToVideo( video, allVideoAppsList ) // Find other videos that also feature this video's app for (const otherVideo of videoList) { for (const app of featuredApps) { + // console.log('otherVideo', otherVideo) // Skip if this app is not in the other video's apps if (!otherVideo.apps.includes(app.slug)) continue @@ -43,7 +48,8 @@ export function videosRelatedToVideo ( video ) { } -export function videosRelatedToApp ( app ) { +export function videosRelatedToApp ( app, videoList ) { + const relatedVideos = {} // Find other videos that also feature this video's app diff --git a/nuxt.config.js b/nuxt.config.js index 85152a4..8537871 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -7,6 +7,8 @@ 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 { buildVideoPayload, buildAppBenchmarkPayload } from './helpers/build-payload.js' + import { categories } from './helpers/categories.js' import { getAppEndpoint, getVideoEndpoint } from './helpers/app-derived.js' @@ -75,12 +77,12 @@ const storeAppLists = async function (builder) { ] = lists // Build a video app list with apps and games only - const videoAppList = [ + const allVideoAppsList = [ ...appList, ...gameList ].flat(1) - return await saveList(videoListOptions, videoAppList) + return await saveList(videoListOptions, allVideoAppsList) }) console.log('Build Lists finished') @@ -142,11 +144,29 @@ export default { .then(( lists ) => { // console.log('appList', appList) + // Break out lists + const [ + appList, + gameList, + _,//homebrewList, + + videoList + ] = lists + + const allVideoAppsList = [ + ...appList, + ...gameList + ] + + // console.log('allVideoAppsList', allVideoAppsList[0]) + // console.log('videoList', videoList[0]) + const [ appRoutes, gameRoutes, - videoRoutes, - homebrewRoutes + homebrewRoutes, + + videoRoutes ] = lists.map((list, listI) => { return list.map( app => { @@ -155,7 +175,7 @@ export default { if (isVideo) { return { route: getVideoEndpoint(app), - payload: { video: app } + payload: buildVideoPayload(app, allVideoAppsList, videoList) } } @@ -169,8 +189,11 @@ export default { // Build routes for app types that support benchmark endpoints const benchmarkRoutes = [ ...appRoutes, - // ...gameRoutes, - ].flat(1).map( route => `${route}/benchmarks`) + ...gameRoutes, + ].flat(1).map( ({ route, payload: { app } }) => ({ + route: `${route}/benchmarks`, + payload: buildAppBenchmarkPayload( app, allVideoAppsList, videoList ) + })) // console.log('homebrewRoutes', homebrewRoutes) @@ -179,7 +202,8 @@ export default { // payload: appList })) - return [ + // Merge endpoints into set to ensure no duplicates + const allEndpointsSet = new Set([ ...appRoutes, ...gameRoutes, ...homebrewRoutes, @@ -188,7 +212,9 @@ export default { ...videoRoutes, ...categoryRoutes, ...benchmarkRoutes - ] + ]) + + return Array.from(allEndpointsSet) }) } }, diff --git a/pages/app/_slug/benchmarks.vue b/pages/app/_slug/benchmarks.vue index 0db762a..073ec01 100644 --- a/pages/app/_slug/benchmarks.vue +++ b/pages/app/_slug/benchmarks.vue @@ -107,32 +107,32 @@ export default { VideoPlayer, ChannelCredit }, - async asyncData ({ params: { slug } }) { + async asyncData ({ params: { slug }, payload: { app, allVideos, submitVideoCard } }) { - const { allVideoAppsList } = await import('~/helpers/get-list.js') - // const { default: videoList } = await import('~/static/video-list.json') + // const { allVideoAppsList } = await import('~/helpers/get-list.js') + // // const { default: videoList } = await import('~/static/video-list.json') - const { videosRelatedToApp } = await import('~/helpers/related.js') + // const { videosRelatedToApp } = await import('~/helpers/related.js') - const app = allVideoAppsList.find(app => (app.slug === slug)) + // const app = allVideoAppsList.find(app => (app.slug === slug)) - const submitVideoCard = { - endpoint: `https://docs.google.com/forms/d/e/1FAIpQLSeEVGM9vE7VcfLMy6fJkfU70X2VZ60rHDyhDQLtnAN4nso0WA/viewform?usp=pp_url&entry.1018125313=${app.name}` - } + // const submitVideoCard = { + // endpoint: `https://docs.google.com/forms/d/e/1FAIpQLSeEVGM9vE7VcfLMy6fJkfU70X2VZ60rHDyhDQLtnAN4nso0WA/viewform?usp=pp_url&entry.1018125313=${app.name}` + // } - // const featuredApps = [] + // // const featuredApps = [] - const relatedVideos = videosRelatedToApp( app ).map(video => { - // console.log('video', video) - return { - ...video, - // endpoint: `#${video.id}` - } - }) + // const relatedVideos = videosRelatedToApp( app ).map(video => { + // // console.log('video', video) + // return { + // ...video, + // // endpoint: `#${video.id}` + // } + // }) return { app, - allVideos: relatedVideos, + allVideos, submitVideoCard } }, diff --git a/pages/app/_slug/index.vue b/pages/app/_slug/index.vue index c9b7175..80f1e1c 100644 --- a/pages/app/_slug/index.vue +++ b/pages/app/_slug/index.vue @@ -82,7 +82,7 @@ export default { const app = appList.find(app => (app.slug === slug)) - const relatedVideos = videosRelatedToApp(app) + const relatedVideos = videosRelatedToApp( app, videoList ) // Find other videos that also feature this video's app // for (const video of videoList) { diff --git a/pages/benchmarks.vue b/pages/benchmarks.vue index 82327f8..c88962c 100644 --- a/pages/benchmarks.vue +++ b/pages/benchmarks.vue @@ -99,12 +99,13 @@ export default { const { appsRelatedToVideo } = await import('~/helpers/related.js') const { default: videoList } = await import('~/static/video-list.json') + const { allVideoAppsList } = await import('~/helpers/get-list.js') // Get featured apps const featuredAppsSet = new Set() videoList.slice(0, 24).forEach( video => { - appsRelatedToVideo(video).forEach( app => { + appsRelatedToVideo(video, allVideoAppsList).forEach( app => { featuredAppsSet.add(app) }) }) diff --git a/pages/game/_slug/benchmarks.vue b/pages/game/_slug/benchmarks.vue index 4fdc00d..f414a5d 100644 --- a/pages/game/_slug/benchmarks.vue +++ b/pages/game/_slug/benchmarks.vue @@ -72,32 +72,38 @@ export default { VideoPlayer, ChannelCredit }, - async asyncData ({ params: { slug } }) { + async asyncData ({ params: { slug }, payload: { app, allVideos } }) { - const { allVideoAppsList } = await import('~/helpers/get-list.js') + // const { allVideoAppsList } = await import('~/helpers/get-list.js') // const { default: videoList } = await import('~/static/video-list.json') - const { videosRelatedToApp } = await import('~/helpers/related.js') + // const { videosRelatedToApp } = await import('~/helpers/related.js') - const app = allVideoAppsList.find(app => (app.slug === slug)) + // const app = allVideoAppsList.find(app => (app.slug === slug)) - // const submitVideoCard = { - // endpoint: `https://docs.google.com/forms/d/e/1FAIpQLSeEVGM9vE7VcfLMy6fJkfU70X2VZ60rHDyhDQLtnAN4nso0WA/viewform?usp=pp_url&entry.1018125313=${app.name}` - // } + // // const submitVideoCard = { + // // endpoint: `https://docs.google.com/forms/d/e/1FAIpQLSeEVGM9vE7VcfLMy6fJkfU70X2VZ60rHDyhDQLtnAN4nso0WA/viewform?usp=pp_url&entry.1018125313=${app.name}` + // // } - // const featuredApps = [] + // // const featuredApps = [] - const relatedVideos = videosRelatedToApp( app ).map(video => { - // console.log('video', video) - return { - ...video, - // endpoint: `#${video.id}` - } - }) + // const relatedVideos = videosRelatedToApp( app, videoList ).map(video => { + // // console.log('video', video) + // return { + // ...video, + // // endpoint: `#${video.id}` + // } + // }) + + // console.log({ + // app, + // allVideos, + // // submitVideoCard + // }) return { app, - allVideos: relatedVideos, + allVideos, // submitVideoCard } }, diff --git a/pages/game/_slug/index.vue b/pages/game/_slug/index.vue index 84dea15..625f6a7 100644 --- a/pages/game/_slug/index.vue +++ b/pages/game/_slug/index.vue @@ -119,7 +119,7 @@ export default { const app = gameList.find(app => (app.slug === slug)) - const relatedVideos = videosRelatedToApp(app) + const relatedVideos = videosRelatedToApp( app, videoList ) // Find other videos that also feature this video's app // for (const video of videoList) { diff --git a/pages/games.vue b/pages/games.vue index c811751..fdc7981 100644 --- a/pages/games.vue +++ b/pages/games.vue @@ -37,6 +37,7 @@ export default { async asyncData () { const { sortedAppList, allList, allVideoAppsList, makeAppSearchLinks } = await import('~/helpers/get-list.js') const { default: gameList } = await import('~/static/game-list.json') + const { default: videoList } = await import('~/static/video-list.json') return { // Map game list @@ -50,7 +51,7 @@ export default { text: app.text, lastUpdated: app.lastUpdated, category: app.category, - searchLinks: makeAppSearchLinks(app) + searchLinks: makeAppSearchLinks( app, videoList ) } }) } diff --git a/pages/index.vue b/pages/index.vue index 8307c53..bb58b63 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -72,6 +72,7 @@ export default { // const { default: gamelist } = await import('~/static/game-list.json') const { sortedAppList, allList, allVideoAppsList, makeAppSearchLinks } = await import('~/helpers/get-list.js') + const { default: videoList } = await import('~/static/video-list.json') const allAppSearchLinks = {} @@ -79,7 +80,7 @@ export default { allVideoAppsList.forEach( app => { // Make the search links - const searchLinks = makeAppSearchLinks(app) + const searchLinks = makeAppSearchLinks( app, videoList ) // If there are more than zero // add them to our list diff --git a/pages/kind/_slug.vue b/pages/kind/_slug.vue index d5b8178..92603a7 100644 --- a/pages/kind/_slug.vue +++ b/pages/kind/_slug.vue @@ -61,6 +61,7 @@ export default { async asyncData ({ params: { slug } }) { const { sortedAppList, allList, allVideoAppsList, makeAppSearchLinks } = await import('~/helpers/get-list.js') const { default: gameList } = await import('~/static/game-list.json') + const { default: videoList } = await import('~/static/video-list.json') const filteredList = allList.filter(app => { return app.category.slug === slug @@ -77,7 +78,7 @@ export default { text: app.text, lastUpdated: app.lastUpdated, category: app.category, - searchLinks: makeAppSearchLinks(app) + searchLinks: makeAppSearchLinks( app, videoList ) } }) } diff --git a/pages/tv/_slug.vue b/pages/tv/_slug.vue index 0a2ff3f..a52aef3 100644 --- a/pages/tv/_slug.vue +++ b/pages/tv/_slug.vue @@ -86,25 +86,30 @@ export default { VideoPlayer, ChannelCredit }, - async asyncData ({ params: { slug } }) { + async asyncData ({ params: { slug }, payload: { video, featuredApps, relatedVideos } }) { - const { appsRelatedToVideo, videosRelatedToVideo } = await import('~/helpers/related.js') - const { default: videoList } = await import('~/static/video-list.json') + // const { appsRelatedToVideo, videosRelatedToVideo } = await import('~/helpers/related.js') + // const { default: videoList } = await import('~/static/video-list.json') // Find the video for our current page - const video = videoList.find(video => (video.slug === slug)) + // const video = videoList.find(video => (video.slug === slug)) // Get featured apps - const featuredApps = appsRelatedToVideo(video) + // const featuredApps = appsRelatedToVideo(video) - // Get related videos - const relatedVideos = videosRelatedToVideo(video) + // // Get related videos + // const relatedVideos = videosRelatedToVideo(video) + + // console.log({ + // video, + // featuredApps, + // relatedVideos + // }) return { video, featuredApps, - // If no related video found just get the 12 newest ones - relatedVideos: (relatedVideos.length !== 0) ? relatedVideos : videoList.slice(0, 12) + relatedVideos } }, computed: {