Commit
+53 -4 +/-5 browse
1 | diff --git a/bin/note.ml b/bin/note.ml |
2 | index e6a9031..7866844 100644 |
3 | --- a/bin/note.ml |
4 | +++ b/bin/note.ml |
5 | @@ -83,8 +83,7 @@ module Encoding = struct |
6 | tree |> Note.Tree.to_json |> Ezjsonm.wrap |> Yaml.to_string_exn |
7 | |> print_endline |
8 | | `Html -> |
9 | - let note = tree |> Note.Tree.fst in |
10 | - note |> Note.to_html |> print_endline |
11 | + tree |> Note.Tree.to_html |> print_endline |
12 | end |
13 | |
14 | module Args = struct |
15 | diff --git a/lib/dune b/lib/dune |
16 | index 05d525c..6bd0172 100644 |
17 | --- a/lib/dune |
18 | +++ b/lib/dune |
19 | @@ -2,4 +2,4 @@ |
20 | (name note_lib) |
21 | (preprocess |
22 | (pps ppx_jane)) |
23 | - (libraries ANSITerminal base core dune-build-info ezjsonm omd stdio re yaml)) |
24 | + (libraries ANSITerminal base core dune-build-info ezjsonm lambdasoup omd stdio re yaml)) |
25 | diff --git a/lib/html.ml b/lib/html.ml |
26 | new file mode 100644 |
27 | index 0000000..02e5d06 |
28 | --- /dev/null |
29 | +++ b/lib/html.ml |
30 | @@ -0,0 +1,19 @@ |
31 | + let template = {| |
32 | + <html> |
33 | + <head> |
34 | + <style> |
35 | + * { |
36 | + margin: 0; |
37 | + padding: 0; |
38 | + box-sizing: border-box; |
39 | + } |
40 | + </style> |
41 | + </head> |
42 | + <body> |
43 | + <h1> Notes </h1> |
44 | + <ul class="wtree"> |
45 | + <navigation></navigation> |
46 | + </ul> |
47 | + </body> |
48 | + </html> |
49 | + |} |
50 | diff --git a/lib/note.ml b/lib/note.ml |
51 | index ccd22d6..b72c8a0 100644 |
52 | --- a/lib/note.ml |
53 | +++ b/lib/note.ml |
54 | @@ -123,6 +123,33 @@ module Tree = struct |
55 | |
56 | let note_to_json = to_json |
57 | |
58 | + let to_html tree = |
59 | + let open Soup in |
60 | + let rec to_nodes ~title others = |
61 | + match others with |
62 | + | [] -> |
63 | + let li = create_element "li" in |
64 | + append_child li (create_element ~inner_text:title "span"); |
65 | + li |
66 | + | tl -> |
67 | + let li = create_element "li" in |
68 | + append_child li (create_element ~inner_text:title "span"); |
69 | + let ul = create_element "ul" in |
70 | + append_child li ul; |
71 | + tl |
72 | + |> List.iter ~f:(fun other -> |
73 | + let (Tree (root, others)) = other in |
74 | + let title = (root |> frontmatter).path in |
75 | + append_child ul (to_nodes ~title others)); |
76 | + li |
77 | + in |
78 | + let (Tree (root, others)) = tree in |
79 | + let title = (root |> frontmatter).path in |
80 | + let index = to_nodes ~title others in |
81 | + let soup = Html.template |> parse in |
82 | + index |> replace (soup $ "navigation"); |
83 | + soup |> to_string |
84 | + |
85 | let rec to_json tree = |
86 | let (Tree (root, others)) = tree in |
87 | Ezjsonm.dict |
88 | diff --git a/lib/note.mli b/lib/note.mli |
89 | index 0108019..5f11037 100644 |
90 | --- a/lib/note.mli |
91 | +++ b/lib/note.mli |
92 | @@ -35,7 +35,11 @@ module Tree : sig |
93 | (* flatten a tree into a list of notes *) |
94 | |
95 | val to_json : tree -> Ezjsonm.value |
96 | - (* return a json representation of each note and it's descendants *) |
97 | + (* return a json representation of each note and their descendants *) |
98 | + |
99 | + val to_html : tree -> string |
100 | + (* return an html represetation of each note and their descendants *) |
101 | + |
102 | end |
103 | |
104 | (* |