You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let search = List.fold_left (fun acc f -> acc % "--search-file" % p f) empty search_files in
233
240
let cmd = odoc % "support-files" % "-o" % "html/odoc" in
234
241
run cmd
235
242
```
@@ -582,20 +589,78 @@ let link_all odoc_files =
582
589
583
590
Now we simply run `odoc html-generate` over all of the resulting `odocl` files.
584
591
This will generate sources, as well as documentation for non-hidden units.
592
+
We notify the generator that the javascript file to use for search is `index.js`.
585
593
586
594
```ocaml env=e1
587
595
let generate_all odocl_files =
596
+
let search_files = [ Fpath.v "index.js" ] in
588
597
let relativize_opt = function None -> None | Some file -> Some (relativize file) in
589
-
List.iter (fun (f, source) -> ignore(html_generate f (relativize_opt source))) odocl_files;
590
-
support_files ()
598
+
List.iter
599
+
(fun (f, source) -> ignore(html_generate ~search_files f (relativize_opt source)))
600
+
odocl_files;
601
+
support_files ~search_files ()
602
+
```
603
+
604
+
Finally, we generate an index of all values, types, ... This index is meant to be consumed by search engines, to create their own index. It consists of a JSON array, containing entries with the name, full name, associated comment, link and anchor, and kind.
605
+
Generating the index is done via `odoc compile-index`, which create a json file. This second format is meant to be consumed by search engines to populate their search index. Search engines written in OCaml can also call the `Odoc_model.Fold.unit` and `Odoc_model.Fold.page` function, in conjunction with `Odoc_search.Entry.entry_of_item` in order to get a (version stable) OCaml value of each element to be indexed.
606
+
607
+
```ocaml env=e1
608
+
let index_generate ?(ignore_output = false) () =
609
+
let open Cmd in
610
+
let cmd = odoc % "compile-index" % "-o" % "html/index.json" % "-I" % "." in
We turn the JSON index into a javascript file. In order to never block the UI, this file will be used as a web worker by `odoc`, to perform searches:
617
+
618
+
- The search query will be sent as a plain string to the web worker, using the standard mechanism of message passing
619
+
- The web worker has to sent back the result as a message to the main thread, containing the list of result. Each entry of this list must have the same form as it had in the original JSON file.
620
+
- The file must be named `index.js` and be located in the `odoc-support` URI.
621
+
622
+
In this driver, we use the minisearch javascript library. For more involved application, we could use `index.js` to call a server-side search engine via an API call.
623
+
624
+
```ocaml env=e1
625
+
let js_index () =
626
+
let index = Bos.OS.File.read Fpath.(v "html" / "index.json") |> get_ok in
627
+
let minisearch = Bos.OS.File.read Fpath.(v "minisearch.js") |> get_ok in
0 commit comments