Add benchmark and performance links to search

This commit is contained in:
Sam Carlton 2020-12-28 14:44:28 -06:00
parent f1a772b905
commit f62f33d98c
4 changed files with 138 additions and 33 deletions

View file

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