Pull video data from payload

This commit is contained in:
Sam Carlton 2021-01-02 16:11:20 -06:00
parent bca074498e
commit 147bf74190
13 changed files with 167 additions and 65 deletions

55
helpers/build-payload.js Normal file
View file

@ -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
}
}

View file

@ -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

View file

@ -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

View file

@ -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)
})
}
},

View file

@ -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
}
},

View file

@ -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) {

View file

@ -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)
})
})

View file

@ -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 relatedVideos = videosRelatedToApp( app, videoList ).map(video => {
// // console.log('video', video)
// return {
// ...video,
// // endpoint: `#${video.id}`
// }
// })
// const featuredApps = []
const relatedVideos = videosRelatedToApp( app ).map(video => {
// console.log('video', video)
return {
...video,
// endpoint: `#${video.id}`
}
})
// console.log({
// app,
// allVideos,
// // submitVideoCard
// })
return {
app,
allVideos: relatedVideos,
allVideos,
// submitVideoCard
}
},

View file

@ -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) {

View file

@ -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 )
}
})
}

View file

@ -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

View file

@ -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 )
}
})
}

View file

@ -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: {