Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b1470b
commit 554c451
Showing
5 changed files
with
32 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import createDebug from "debug"; | ||
|
||
const debug = createDebug("search-local"); | ||
export const debugVerbose = debug.extend("verbose"); | ||
export const debugInfo = debug.extend("info"); | ||
export const debugWarn = debug.extend("warn"); |
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,38 +1,37 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import util from "util"; | ||
import _debug from "debug"; | ||
import { ProcessedPluginOptions, PostBuildData } from "../../shared/interfaces"; | ||
import { buildIndex } from "./buildIndex"; | ||
import { debugInfo } from "./debug"; | ||
import { processDocInfos } from "./processDocInfos"; | ||
import { scanDocuments } from "./scanDocuments"; | ||
|
||
const debug = _debug("search-local"); | ||
const writeFileAsync = util.promisify(fs.writeFile); | ||
|
||
export function postBuildFactory(config: ProcessedPluginOptions) { | ||
return async function postBuild(buildData: PostBuildData): Promise<void> { | ||
debug("Gathering documents"); | ||
debugInfo("gathering documents"); | ||
|
||
const data = processDocInfos(buildData, config); | ||
|
||
debug("Parsing documents"); | ||
debugInfo("parsing documents"); | ||
|
||
// Give every index entry a unique id so that the index does not need to store long URLs. | ||
const allDocuments = await scanDocuments(data); | ||
|
||
debug("Building index"); | ||
debugInfo("building index"); | ||
|
||
const searchIndex = buildIndex(allDocuments, config); | ||
|
||
debug("Writing index to disk"); | ||
debugInfo("writing index to disk"); | ||
|
||
await writeFileAsync( | ||
path.join(buildData.outDir, "search-index.json"), | ||
JSON.stringify(searchIndex), | ||
{ encoding: "utf8" } | ||
); | ||
|
||
debug("Index written to disk, success!"); | ||
debugInfo("index written to disk successfully!"); | ||
}; | ||
} |
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