Source file Search_menu.ml
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
open Forester_core
open Forester_compiler
open Forester_frontend
open Pure_html
open HTML
let v =
let markup =
div
[
class_ "modal-overlay";
Hx.trigger "click target:.modal-overlay, keyup[key=='Escape'] from:body";
Hx.target "#modal-container";
Hx.get "/nil";
]
[
div
[class_ "modal-content";]
[
form
[
class_ "search-form";
Hx.post "/search";
Hx.trigger "input changed delay:500ms, keyup[key=='Enter'], load";
Hx.target "#search-results";
]
[
input
[
autofocus;
class_ "search";
type_ "search";
name "search";
placeholder "Start typing a note title or ID";
];
span
[]
[
input [type_ "radio"; name "search-for"; value "full-text"];
label [for_ "full-text"] [txt "Full text"];
];
span
[]
[
input [type_ "radio"; name "search-for"; value "title"];
label [for_ "title-text"] [txt "title"];
];
];
ul
[id "search-results";]
[];
];
]
in
Pure_html.to_string markup
let results (forest : State.t) (links : URI.t list) =
Pure_html.to_string @@
ul
[id "search-results"]
(
List.filter_map
(fun uri ->
let title = State.get_content_of_transclusion {href = uri; target = Title {empty_when_untitled = false}} forest in
Option.map
(fun t ->
a
[
class_ "search-result-item";
href "/trees%s" (URI.path_string uri);
Hx.target "#tree-container";
Hx.swap "outerHTML";
] @@
Htmx_client.render_content forest t
)
title
)
links
)