mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add Pagefind indexing and browser search adapters behind a provider switch. This lets prebuild generate either Stork or Pagefind search artifacts and lets the existing search UI run against Pagefind while preserving scoped filters, excerpts, and result metadata.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 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() )
|
|
await fs.outputJson( sitemapEndpointsPath, response.data, { spaces: 2 } )
|
|
|
|
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)
|
|
})
|