mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
feat(search): add pagefind provider support
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.
This commit is contained in:
parent
727f84e4c2
commit
e1da6eb880
12 changed files with 690 additions and 65 deletions
43
scripts/build-pagefind-index.js
Normal file
43
scripts/build-pagefind-index.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
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)
|
||||
})
|
||||
18
scripts/build-search-index.js
Normal file
18
scripts/build-search-index.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { execSync } from 'child_process'
|
||||
import 'dotenv/config.js'
|
||||
|
||||
import {
|
||||
getSearchProvider
|
||||
} from '~/helpers/search/config.js'
|
||||
|
||||
const searchProvider = getSearchProvider( process.env.PUBLIC_SEARCH_PROVIDER )
|
||||
|
||||
console.log(`Building search index for provider: ${ searchProvider }`)
|
||||
|
||||
if ( searchProvider === 'stork' ) {
|
||||
execSync( 'pnpm stork-index', { stdio: 'inherit' } )
|
||||
process.exit()
|
||||
}
|
||||
|
||||
execSync( 'pnpm build-pagefind-index', { stdio: 'inherit' } )
|
||||
process.exit()
|
||||
Loading…
Add table
Add a link
Reference in a new issue