Commit
Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: 315eaf6bb6b521f36defdfd9787f03370a82b3dd
Timestamp: Mon, 12 Apr 2021 18:04:14 +0000 (3 years ago)

+21 -13 +/-2 browse
store raw note content in record
1diff --git a/lib/cmd.ml b/lib/cmd.ml
2index 8984065..e2d2843 100644
3--- a/lib/cmd.ml
4+++ b/lib/cmd.ml
5 @@ -5,8 +5,8 @@ let cfg = Config.load
6 let get_notes =
7 List.map
8 ~f:(fun slug ->
9- let data = In_channel.read_all (Slug.get_path slug) in
10- Note.of_string ~data slug)
11+ let content = In_channel.read_all (Slug.get_path slug) in
12+ Note.of_string ~content slug)
13 (Slug.load cfg.state_dir)
14
15 let filter_arg =
16 diff --git a/lib/note.ml b/lib/note.ml
17index 8c4950f..5b0896a 100644
18--- a/lib/note.ml
19+++ b/lib/note.ml
20 @@ -1,6 +1,11 @@
21 open Core
22
23- type t = { frontmatter : Ezjsonm.t option; markdown : Omd.doc; slug : Slug.t }
24+ type t = {
25+ frontmatter : Ezjsonm.t option;
26+ content : string;
27+ markdown : Omd.doc;
28+ slug : Slug.t;
29+ }
30
31 let build ?(tags = []) ?(content = "") ~title slug =
32 let frontmatter =
33 @@ -9,7 +14,7 @@ let build ?(tags = []) ?(content = "") ~title slug =
34 [ ("title", Ezjsonm.string title); ("tags", Ezjsonm.strings tags) ])
35 in
36 let markdown = Omd.of_string content in
37- { frontmatter; markdown; slug }
38+ { frontmatter; content; markdown; slug }
39
40 let rec title_of_markdown (blocks : Omd.block list) : string =
41 match blocks with
42 @@ -83,7 +88,6 @@ let get_data t =
43 let data = extract_structured_data [] t.markdown in
44 Ezjsonm.list (fun value -> value) data
45
46- (* TODO: fix html conversion *)
47 let to_json t =
48 let frontmatter =
49 match t.frontmatter with
50 @@ -93,7 +97,7 @@ let to_json t =
51 Ezjsonm.dict
52 [
53 ("frontmatter", frontmatter);
54- ("content", Ezjsonm.string (Omd.to_html t.markdown));
55+ ("content", Ezjsonm.string t.content);
56 ("data", get_data t);
57 ]
58
59 @@ -105,11 +109,13 @@ let to_string t =
60 [ "---"; front_matter; "---"; Omd.to_html t.markdown ]
61 | None -> Omd.to_html t.markdown
62
63- let of_string ~data slug =
64- let indexes = String.substr_index_all ~may_overlap:true ~pattern:"---" data in
65+ let of_string ~content slug =
66+ let indexes =
67+ String.substr_index_all ~may_overlap:true ~pattern:"---" content
68+ in
69 if List.length indexes >= 2 then
70 let meta_str =
71- String.slice data (List.nth_exn indexes 0 + 3) (List.nth_exn indexes 1)
72+ String.slice content (List.nth_exn indexes 0 + 3) (List.nth_exn indexes 1)
73 in
74 let frontmatter : Ezjsonm.t =
75 match Yaml.of_string_exn meta_str with
76 @@ -122,14 +128,16 @@ let of_string ~data slug =
77 in
78 let markdown : Omd.doc =
79 Omd.of_string
80- (String.slice data (List.nth_exn indexes 1 + 3) (String.length data))
81+ (String.slice content
82+ (List.nth_exn indexes 1 + 3)
83+ (String.length content))
84 in
85 let frontmatter = Some frontmatter in
86- { frontmatter; markdown; slug }
87+ { frontmatter; content; markdown; slug }
88 else
89 let frontmatter = None in
90- let markdown = Omd.of_string data in
91- { frontmatter; markdown; slug }
92+ let markdown = Omd.of_string content in
93+ { frontmatter; content; markdown; slug }
94
95 module Util = struct
96 let split_words str =