on master help sign in
api: search checks headings

Returns a 'page content' flag if so.

commitbef9aa20a6a821c98056d06b4d0756c5c623116a authorMatilde Park <matilde.park@urbit.org> dateTue 26 Jul 2022, 14:38 (4 years ago) parent3cb5c5f
1 file changed+22−1
pages/api/search.js+22−1
pages/api/search.js+22−1
@@ -8,7 +8,28 @@ export default (req, res) => {
88 e?.slug.includes(req.query.q.toLowerCase()) ||
99 e?.parent.toLowerCase().includes(req.query.q.toLowerCase())
1010 );
11− const sorted = levenSort(results, req.q, ["title", "slug", "parent"]);
11+
12+ results.push(
13+ ...index
14+ .filter((e) => !results.includes(e))
15+ .filter((e) => {
16+ let found = false;
17+ e.headings.forEach((heading) => {
18+ if (heading.toLowerCase().includes(req.query.q.toLowerCase())) {
19+ found = true;
20+ }
21+ });
22+ return found;
23+ })
24+ .map((e) => ({ ...e, foundOnPage: true }))
25+ );
26+
27+ const sorted = levenSort(results, req.q, [
28+ "title",
29+ "slug",
30+ "parent",
31+ "headings",
32+ ]);
1233 res.statusCode = 200;
1334 res.setHeader("Content-Type", "application/json");
1435 res.end(JSON.stringify({ results: sorted }));