forked from pulumi/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-search-index.js
42 lines (33 loc) · 1.16 KB
/
build-search-index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Adapted from https://lunrjs.com/guides/index_prebuilding.html
const lunr = require("../js/lunr.min.js");
const stdin = process.stdin;
const stdout = process.stdout;
let buffer = [];
stdin.resume();
stdin.setEncoding("utf8");
stdin.on("data", data => buffer.push(data));
stdin.on("end", () => {
const data = JSON.parse(buffer.join(""));
const index = lunr(function () {
this.ref("ref");
this.field("title", { boost: 10 });
this.field("content");
for (var url in data) {
const page = data[url];
if (page.title || page.content) {
// We use '|' to separate the URL and title in the ref, so
// ensure we haven't inadvertently introduced a page that
// contains a '|' in its URL.
if (url.indexOf("|") !== -1) {
throw new Error(`unexpected '|' in url: ${url}`);
}
this.add({
ref: url + "|" + page.title,
title: page.title,
content: page.content
});
}
}
})
stdout.write(JSON.stringify(index));
});