-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.clj
33 lines (29 loc) · 1.14 KB
/
search.clj
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
(ns goddinpotty.search
(:require [org.candelbio.multitool.core :as u]
[goddinpotty.batadase :as bd]
[goddinpotty.rendering :as render]
[goddinpotty.utils :as utils]
[clojure.string :as str]
))
;;; Writes out a JSON search index for Elasticlunr
;;; See resources/public/search.js for the code that consumes it
(defn index
[bm]
(u/for* [page (bd/displayed-pages bm)
index (range)]
(u/clean-map
{:id index ;TODO not sure this is necessary, we don't use it
:url (utils/clean-page-title (:title page))
;; If punctuation is causing problems, try fiddling with elasticlunr.tokenizer.seperator
:title (:title page)
:alias (when-let [aliases (:alias page)]
(str/join " " aliases))
:body (render/block-full-text bm page)})))
(defn write-index
[bm output-dir]
(utils/write-json (str output-dir "/assets/index.js")
(index bm)))
(defn search-head
[]
[[:script {:src "assets/elasticlunr.min.js"}] ; From https://elasticlunr.com/elasticlunr.min.js
[:script {:src "assets/search.js"}]])