-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from CriticalMoments/site_search_build_step
Move search index building into vite plugin
- Loading branch information
Showing
3 changed files
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { buildSearchIndex } from "$lib/build_index" | ||
import { dev } from "$app/environment" | ||
import { error } from "@sveltejs/kit" | ||
|
||
export async function GET() { | ||
const searchData = await buildSearchIndex() | ||
|
||
return new Response(JSON.stringify(searchData), { | ||
headers: { "Content-Type": "application/json" }, | ||
}) | ||
// only build search index in dev mode. It will be pre-built in production (see vite.config.js) | ||
if (dev) { | ||
const { buildSearchIndex } = await import("$lib/build_index") | ||
const searchData = await buildSearchIndex() | ||
return new Response(JSON.stringify(searchData), { | ||
headers: { "Content-Type": "application/json" }, | ||
}) | ||
} | ||
error(404, "Search index not found") | ||
} | ||
|
||
export const prerender = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters