Skip to content

Commit 3d19c60

Browse files
committed
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
1 parent eaeff51 commit 3d19c60

5 files changed

Lines changed: 57 additions & 28 deletions

File tree

helpers/site-listings.js

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
1-
import youtubeVideosText from '~/static/api/youtube-videos.json?raw'
2-
import appListText from '~/static/app-list.json?raw'
31
import deviceListText from '~/static/device-list.json?raw'
4-
import gameListText from '~/static/game-list.json?raw'
2+
import videoListingsText from '~/static/api/youtube-video-listings.json?raw'
53

6-
import {
7-
buildVideoListingFromFetchedVideo,
8-
makeVideoSlug
9-
} from '~/helpers/build-video-list.js'
104
const trailingCommaPattern = /,\s*([\]}])/g
115
const parsedDeviceList = JSON.parse( deviceListText.replace( trailingCommaPattern, '$1' ) )
12-
const parsedAppList = JSON.parse( appListText.replace( trailingCommaPattern, '$1' ) )
13-
const parsedGameList = JSON.parse( gameListText.replace( trailingCommaPattern, '$1' ) )
14-
const parsedYoutubeVideos = JSON.parse( youtubeVideosText )
6+
const parsedVideoListings = JSON.parse( videoListingsText )
157

168
export function getDeviceListingBySlug ( slug ) {
179
return parsedDeviceList.find( device => device.slug === slug ) || null
1810
}
1911

20-
function getAllVideoAppsList () {
21-
return [
22-
...parsedAppList,
23-
...parsedGameList
24-
]
25-
}
26-
2712
export async function getVideoListingBySlug ( slug ) {
28-
const allVideoAppsList = getAllVideoAppsList()
29-
30-
for ( const [ videoId, fetchedVideo ] of Object.entries( parsedYoutubeVideos ) ) {
31-
if ( makeVideoSlug( fetchedVideo.title, videoId ) !== slug ) continue
32-
33-
return await buildVideoListingFromFetchedVideo( fetchedVideo, videoId, allVideoAppsList )
34-
}
35-
36-
return null
13+
return parsedVideoListings[slug] || null
3714
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import fs from 'fs-extra'
2+
3+
import {
4+
buildVideoListingFromFetchedVideo,
5+
makeVideoSlug
6+
} from '~/helpers/build-video-list.js'
7+
import { saveYouTubeVideos, youtubeVideoPath } from '~/helpers/api/youtube/build.js'
8+
9+
const outputPath = './static/api/youtube-video-listings.json'
10+
const trailingCommaPattern = /,\s*([\]}])/g
11+
12+
async function readJsonWithTrailingCommaFallback ( path ) {
13+
return JSON.parse(
14+
( await fs.readFile( path, 'utf8' ) ).replace( trailingCommaPattern, '$1' )
15+
)
16+
}
17+
18+
await saveYouTubeVideos()
19+
20+
const [
21+
fetchedVideos,
22+
appList,
23+
gameList
24+
] = await Promise.all([
25+
fs.readJson( youtubeVideoPath ),
26+
readJsonWithTrailingCommaFallback( './static/app-list.json' ),
27+
readJsonWithTrailingCommaFallback( './static/game-list.json' )
28+
])
29+
30+
const allVideoAppsList = [
31+
...appList,
32+
...gameList
33+
]
34+
const videoListingsBySlug = {}
35+
36+
for ( const [ videoId, fetchedVideo ] of Object.entries( fetchedVideos ) ) {
37+
const videoListing = await buildVideoListingFromFetchedVideo(
38+
fetchedVideo,
39+
videoId,
40+
allVideoAppsList
41+
)
42+
43+
if ( videoListing === undefined ) continue
44+
45+
videoListingsBySlug[ makeVideoSlug( fetchedVideo.title, videoId ) ] = videoListing
46+
}
47+
48+
await fs.outputJson( outputPath, videoListingsBySlug )
49+
50+
console.log(
51+
`Wrote ${ Object.keys( videoListingsBySlug ).length } video listing fallbacks to ${ outputPath }`
52+
)

static/api/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
*
22
!.gitignore
3-
!youtube-videos.json
3+
!youtube-video-listings.json

static/api/youtube-video-listings.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

static/api/youtube-videos.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)