ai generated solutions to our ai generated problems

This commit is contained in:
2026-06-20 00:38:24 +01:00
parent 152467515d
commit fb773489f5
3 changed files with 60 additions and 4 deletions
+38
View File
@@ -2281,6 +2281,43 @@ function routeStructuredData(origin, seo, canonicalUrl) {
])
}
function readPublicDataSnapshot(relativePath) {
try {
const filePath = path.resolve(PUBLIC_DATA_CACHE_DIR, relativePath)
const relativeToCache = path.relative(PUBLIC_DATA_CACHE_DIR, filePath)
if (relativeToCache.startsWith('..') || path.isAbsolute(relativeToCache)) return null
const stat = fs.statSync(filePath)
if (!stat.isFile() || Date.now() - stat.mtimeMs > PUBLIC_DATA_CACHE_STALE_MS) return null
return JSON.parse(fs.readFileSync(filePath, 'utf8'))
} catch {
return null
}
}
function routeBootData(pathname) {
const boot = {}
if (pathname === '/') {
const homeTeams = readPublicDataSnapshot('home-teams.json')
const live = readPublicDataSnapshot('recent-games.json')
if (homeTeams) boot.homeTeams = homeTeams
if (live) boot.live = live
} else if (pathname === '/teams') {
const leaderboard = readPublicDataSnapshot('leaderboard-teams.json')
if (leaderboard) boot.leaderboard = leaderboard
} else if (pathname === '/players') {
const playerLeaderboard = readPublicDataSnapshot('leaderboard-players.json')
if (playerLeaderboard) boot.playerLeaderboard = playerLeaderboard
} else if (pathname === '/battle-logs' || pathname === '/live') {
const live = readPublicDataSnapshot('recent-games.json')
const leaderboard = readPublicDataSnapshot('leaderboard-teams.json')
if (live) boot.live = live
if (leaderboard) boot.leaderboard = leaderboard
}
return Object.keys(boot).length ? boot : null
}
function htmlWithSeo(req, data) {
const origin = pagePublicOrigin(req)
let pathname = '/'
@@ -2301,6 +2338,7 @@ function htmlWithSeo(req, data) {
.replaceAll('__SEO_ROBOTS__', escapeHtml(seo.robots))
.replaceAll('__SEO_CANONICAL__', escapeHtml(canonicalUrl))
.replaceAll('__SEO_JSON_LD__', routeStructuredData(origin, seo, canonicalUrl).replace(/</g, '\\u003c'))
.replaceAll('__TSS_BOOT_DATA__', JSON.stringify(routeBootData(pathname)).replace(/</g, '\\u003c'))
.replaceAll('__TURNSTILE_SESSION__', isTurnstileSessionVerified(req) ? 'verified' : 'required')
}