mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Keep YouTube fallbacks small enough to review
The first baseline committed the raw YouTube API dump, which fixed clean builds but carried unused API metadata. The route fallback only needs prebuilt listing objects, so this replaces the raw seed with slug-keyed listing fallbacks and adds a refresh script that fetches the latest source data before projecting it. Constraint: helpers/site-listings.js must work in a fresh checkout before generated static/api output exists Rejected: Commit the full raw YouTube JSON | unnecessarily large and mostly unused by the fallback path Rejected: Drop descriptions only | smaller but would weaken app-link and tag matching semantics Confidence: high Scope-risk: narrow Reversibility: clean Directive: Refresh static/api/youtube-video-listings.json via scripts/update-youtube-video-listing-fallbacks.js, not by committing static/api/youtube-videos.json Tested: pnpm run with-env vite-node scripts/update-youtube-video-listing-fallbacks.js Tested: pnpm run with-env vitest test/prebuild/site-listings.test.js Tested: pnpm run netlify-prebuild:test-prebuild-functions Tested: pnpm run netlify-prebuild
This commit is contained in:
parent
eaeff51cc9
commit
3d19c60670
5 changed files with 57 additions and 28 deletions
|
|
@ -1,37 +1,14 @@
|
||||||
import youtubeVideosText from '~/static/api/youtube-videos.json?raw'
|
|
||||||
import appListText from '~/static/app-list.json?raw'
|
|
||||||
import deviceListText from '~/static/device-list.json?raw'
|
import deviceListText from '~/static/device-list.json?raw'
|
||||||
import gameListText from '~/static/game-list.json?raw'
|
import videoListingsText from '~/static/api/youtube-video-listings.json?raw'
|
||||||
|
|
||||||
import {
|
|
||||||
buildVideoListingFromFetchedVideo,
|
|
||||||
makeVideoSlug
|
|
||||||
} from '~/helpers/build-video-list.js'
|
|
||||||
const trailingCommaPattern = /,\s*([\]}])/g
|
const trailingCommaPattern = /,\s*([\]}])/g
|
||||||
const parsedDeviceList = JSON.parse( deviceListText.replace( trailingCommaPattern, '$1' ) )
|
const parsedDeviceList = JSON.parse( deviceListText.replace( trailingCommaPattern, '$1' ) )
|
||||||
const parsedAppList = JSON.parse( appListText.replace( trailingCommaPattern, '$1' ) )
|
const parsedVideoListings = JSON.parse( videoListingsText )
|
||||||
const parsedGameList = JSON.parse( gameListText.replace( trailingCommaPattern, '$1' ) )
|
|
||||||
const parsedYoutubeVideos = JSON.parse( youtubeVideosText )
|
|
||||||
|
|
||||||
export function getDeviceListingBySlug ( slug ) {
|
export function getDeviceListingBySlug ( slug ) {
|
||||||
return parsedDeviceList.find( device => device.slug === slug ) || null
|
return parsedDeviceList.find( device => device.slug === slug ) || null
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllVideoAppsList () {
|
|
||||||
return [
|
|
||||||
...parsedAppList,
|
|
||||||
...parsedGameList
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getVideoListingBySlug ( slug ) {
|
export async function getVideoListingBySlug ( slug ) {
|
||||||
const allVideoAppsList = getAllVideoAppsList()
|
return parsedVideoListings[slug] || null
|
||||||
|
|
||||||
for ( const [ videoId, fetchedVideo ] of Object.entries( parsedYoutubeVideos ) ) {
|
|
||||||
if ( makeVideoSlug( fetchedVideo.title, videoId ) !== slug ) continue
|
|
||||||
|
|
||||||
return await buildVideoListingFromFetchedVideo( fetchedVideo, videoId, allVideoAppsList )
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
52
scripts/update-youtube-video-listing-fallbacks.js
Normal file
52
scripts/update-youtube-video-listing-fallbacks.js
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
import fs from 'fs-extra'
|
||||||
|
|
||||||
|
import {
|
||||||
|
buildVideoListingFromFetchedVideo,
|
||||||
|
makeVideoSlug
|
||||||
|
} from '~/helpers/build-video-list.js'
|
||||||
|
import { saveYouTubeVideos, youtubeVideoPath } from '~/helpers/api/youtube/build.js'
|
||||||
|
|
||||||
|
const outputPath = './static/api/youtube-video-listings.json'
|
||||||
|
const trailingCommaPattern = /,\s*([\]}])/g
|
||||||
|
|
||||||
|
async function readJsonWithTrailingCommaFallback ( path ) {
|
||||||
|
return JSON.parse(
|
||||||
|
( await fs.readFile( path, 'utf8' ) ).replace( trailingCommaPattern, '$1' )
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
await saveYouTubeVideos()
|
||||||
|
|
||||||
|
const [
|
||||||
|
fetchedVideos,
|
||||||
|
appList,
|
||||||
|
gameList
|
||||||
|
] = await Promise.all([
|
||||||
|
fs.readJson( youtubeVideoPath ),
|
||||||
|
readJsonWithTrailingCommaFallback( './static/app-list.json' ),
|
||||||
|
readJsonWithTrailingCommaFallback( './static/game-list.json' )
|
||||||
|
])
|
||||||
|
|
||||||
|
const allVideoAppsList = [
|
||||||
|
...appList,
|
||||||
|
...gameList
|
||||||
|
]
|
||||||
|
const videoListingsBySlug = {}
|
||||||
|
|
||||||
|
for ( const [ videoId, fetchedVideo ] of Object.entries( fetchedVideos ) ) {
|
||||||
|
const videoListing = await buildVideoListingFromFetchedVideo(
|
||||||
|
fetchedVideo,
|
||||||
|
videoId,
|
||||||
|
allVideoAppsList
|
||||||
|
)
|
||||||
|
|
||||||
|
if ( videoListing === undefined ) continue
|
||||||
|
|
||||||
|
videoListingsBySlug[ makeVideoSlug( fetchedVideo.title, videoId ) ] = videoListing
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.outputJson( outputPath, videoListingsBySlug )
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Wrote ${ Object.keys( videoListingsBySlug ).length } video listing fallbacks to ${ outputPath }`
|
||||||
|
)
|
||||||
2
static/api/.gitignore
vendored
2
static/api/.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
*
|
*
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!youtube-videos.json
|
!youtube-video-listings.json
|
||||||
|
|
|
||||||
1
static/api/youtube-video-listings.json
Normal file
1
static/api/youtube-video-listings.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue