doesitarm/scripts/build-pagefind-index.js
ThatGuySam c5ec942de0
Some checks failed
Deploy to Cloudflare Workers with Wrangler / Deploy (push) Has been cancelled
Run Node 24 Checks / build (24.x) (push) Has been cancelled
fix(ci): avoid serializing downloaded sitemap endpoints
Keep the Pagefind bootstrap path from rewriting the remote sitemap
payload locally when the static JSON file is absent. GitHub-hosted runs
only need the fetched data in memory, and stringifying the 385 MB payload
was exhausting Node during netlify-build.
2026-03-15 19:33:05 -05:00

42 lines
1.1 KiB
JavaScript

import fs from 'fs-extra'
import axios from 'axios'
import 'dotenv/config.js'
import {
sitemapEndpointsPath
} from '~/helpers/pagefind/config.js'
import {
writePagefindIndex
} from '~/helpers/pagefind/index.js'
async function loadSitemapEndpoints () {
if ( await fs.pathExists( sitemapEndpointsPath ) ) {
return await fs.readJson( sitemapEndpointsPath )
}
if ( !process.env.PUBLIC_API_DOMAIN ) {
throw new Error(`Missing ${ sitemapEndpointsPath } and PUBLIC_API_DOMAIN is not set`)
}
const apiUrl = new URL( process.env.PUBLIC_API_DOMAIN )
apiUrl.pathname = sitemapEndpointsPath.replace(/^\.?\/?static\//, '/')
const response = await axios.get( apiUrl.toString() )
return response.data
}
;(async () => {
const sitemapEndpoints = await loadSitemapEndpoints()
const {
outputPath,
recordCount
} = await writePagefindIndex( sitemapEndpoints )
console.log(`Built Pagefind index with ${ recordCount } records at ${ outputPath }`)
process.exit()
})().catch( error => {
console.error( error )
process.exit(1)
})