diff --git a/helpers/get-list.js b/helpers/get-list.js index 7bb6366..f67787e 100644 --- a/helpers/get-list.js +++ b/helpers/get-list.js @@ -3,6 +3,9 @@ import gameList from '~/static/game-list.json' import homebrewList from '~/static/homebrew-list.json' import { byTimeThenNull } from '~/helpers/sort-list.js' +import { videosRelatedToApp } from '~/helpers/related.js' +import { getAppEndpoint } from '~/helpers/app-derived.js' + export const allVideoAppsList = [ ...appList.sort(byTimeThenNull), @@ -16,3 +19,54 @@ export const allList = [ ...homebrewList, ...gameList, ] + + +export function makeAppSearchLinks (app) { + + const videos = videosRelatedToApp(app) + + // If there are no videos + // then skip + if (videos.length === 0) return [] + + const searchLinks = [] + + const appBenchmarksUrl = `${getAppEndpoint(app)}/benchmarks` + + let hasPerformanceVideo = false + + for (const video of videos) { + // If there are no video tags + // then skip + if (video.tags.length === 0) continue + + // If there's any benchmark video then add + if (video.tags.includes('benchmark')) { + // Add a benchmark link + searchLinks.push({ + href: appBenchmarksUrl, + label: 'Benchmarks' + }) + + // then stop looking + break + } + + if (video.tags.includes('performance')) { + hasPerformanceVideo = true + } + } + + // If there was no bechmark video found + // but there was a performance video found + // then push Performance link + if (searchLinks.length === 0 && hasPerformanceVideo) { + // Add a performance link + searchLinks.push({ + href: appBenchmarksUrl, + label: 'Performance' + }) + } + + return searchLinks +} diff --git a/pages/games.vue b/pages/games.vue index b04b428..2f128b1 100644 --- a/pages/games.vue +++ b/pages/games.vue @@ -34,6 +34,29 @@ import ThomasCredit from '~/components/thomas-credit.vue' import gameList from '~/static/game-list.json' export default { + async asyncData () { + const { sortedAppList, allList, allVideoAppsList, makeAppSearchLinks } = await import('~/helpers/get-list.js') + const { default: gameList } = await import('~/static/game-list.json') + + return { + // Map game list + gameList: gameList.map( app => { + + return { + name: app.name, + status: app.status, + slug: app.slug, + // endpoint: app.endpoint, + text: app.text, + lastUpdated: app.lastUpdated, + category: app.category, + searchLinks: makeAppSearchLinks(app) + } + }), + // allAppSearchLinks, + // customSummaryNumbers: getListSummaryNumbers(allList) + } + }, components: { Search, LinkButton, @@ -59,9 +82,9 @@ export default { } }, computed: { - gameList() { - return gameList - } + // gameList() { + // return gameList + // } }, head() { return { diff --git a/pages/index.vue b/pages/index.vue index 6d2ac6e..b1b96c2 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -71,13 +71,33 @@ export default { // const { default: appList } = await import('~/static/app-list.json') // const { default: gamelist } = await import('~/static/game-list.json') - const { sortedAppList, allList } = await import('~/helpers/get-list.js') + const { sortedAppList, allList, allVideoAppsList, makeAppSearchLinks } = await import('~/helpers/get-list.js') + const allAppSearchLinks = {} + // console.log('allVideoAppsList', allVideoAppsList) + + allVideoAppsList.forEach( app => { + // Make the search links + const searchLinks = makeAppSearchLinks(app) + + // If there are more than zero + // add them to our list + if (searchLinks.length > 0) { + allAppSearchLinks[app.slug] = searchLinks + } + }) return { // Filter app list to leave out data not needed for search initialAppList: sortedAppList.map( app => { + + let searchLinks = [] + + if (typeof allAppSearchLinks[app.slug] !== 'undefined') { + searchLinks = allAppSearchLinks[app.slug] + } + return { name: app.name, status: app.status, @@ -86,8 +106,10 @@ export default { text: app.text, lastUpdated: app.lastUpdated, category: app.category, + searchLinks } }), + allAppSearchLinks, customSummaryNumbers: getListSummaryNumbers(allList) } }, @@ -163,6 +185,8 @@ export default { // then stop if (this.fetchedAppList.length !== 0 || this.query.trim().length === 0) return + // console.log('this.allAppSearchLinks', this.allAppSearchLinks) + const fetchedListUrls = [ '/game-list.json', '/homebrew-list.json' @@ -179,7 +203,19 @@ export default { // console.log('fetchedLists', fetchedLists) - this.fetchedAppList = fetchedLists.flat(1) + this.fetchedAppList = fetchedLists.flat(1).map( app => { + + let searchLinks = [] + + if (typeof this.allAppSearchLinks[app.slug] !== 'undefined') { + searchLinks = this.allAppSearchLinks[app.slug] + } + + return { + ...app, + searchLinks + } + }) return } diff --git a/pages/kind/_slug.vue b/pages/kind/_slug.vue index ed81c88..41ce139 100644 --- a/pages/kind/_slug.vue +++ b/pages/kind/_slug.vue @@ -55,26 +55,32 @@ import Search from '~/components/search.vue' import LinkButton from '~/components/link-button.vue' -import { byTimeThenNull } from '~/helpers/sort-list.js' - import { categories, getAppCategory } from '~/helpers/categories.js' -import appList from '~/static/app-list.json' -import gamelist from '~/static/game-list.json' -import homebrewList from '~/static/homebrew-list.json' - -const allList = [ - ...appList.sort(byTimeThenNull), - ...homebrewList, - ...gamelist, -] - export default { async asyncData ({ params: { slug } }) { - // Maybe I could import() here to reduce client script size + const { sortedAppList, allList, allVideoAppsList, makeAppSearchLinks } = await import('~/helpers/get-list.js') + const { default: gameList } = await import('~/static/game-list.json') + + const filteredList = allList.filter(app => { + return app.category.slug === slug + }) + return { slug, - // app: appList.find(app => (app.slug === slug)) + categoryAppList: filteredList.map( app => { + + return { + name: app.name, + status: app.status, + slug: app.slug, + // endpoint: app.endpoint, + text: app.text, + lastUpdated: app.lastUpdated, + category: app.category, + searchLinks: makeAppSearchLinks(app) + } + }) } }, components: { @@ -104,20 +110,6 @@ export default { category () { return categories[this.slug] }, - categoryAppList () { - - const filteredList = allList.filter(app => { - return app.category.slug === this.slug - }) - - // const sortedList = list.sort(byTimeThenNull) - - // if (this.category.slug === 'homebrew') { - // return filteredList.slice(0, 300) - // } - - return filteredList - }, supportedAppList () { return this.categoryAppList.filter(app => { return app.status.includes('yes')