Commit
Author: Kevin Schoon [kevinschoon@gmail.com]
Hash: e023db6fef75605dbc6156150268abf1a34cbf73
Timestamp: Thu, 28 Jan 2021 15:15:59 +0000 (3 years ago)

+21 -3 +/-4 browse
add support for description column
1diff --git a/lib/config.ml b/lib/config.ml
2index d642ec0..2d24e5b 100644
3--- a/lib/config.ml
4+++ b/lib/config.ml
5 @@ -39,16 +39,18 @@ module Encoding = struct
6 end
7
8 module Column = struct
9- type t = [ `Title | `Tags | `WordCount | `Slug ]
10+ type t = [ `Title | `Description | `Tags | `WordCount | `Slug ]
11
12 let to_string = function
13 | `Title -> "title"
14+ | `Description -> "description"
15 | `Tags -> "tags"
16 | `WordCount -> "words"
17 | `Slug -> "slug"
18
19 let of_string = function
20 | "title" -> `Title
21+ | "description" -> `Description
22 | "tags" -> `Tags
23 | "words" -> `WordCount
24 | "slug" -> `Slug
25 diff --git a/lib/config.mli b/lib/config.mli
26index 96fb0a3..bd693c5 100644
27--- a/lib/config.mli
28+++ b/lib/config.mli
29 @@ -17,7 +17,7 @@ module Encoding : sig
30 end
31
32 module Column : sig
33- type t = [ `Title | `Tags | `WordCount | `Slug ]
34+ type t = [ `Title | `Description | `Tags | `WordCount | `Slug ]
35
36 val of_string : string -> t
37
38 diff --git a/lib/note.ml b/lib/note.ml
39index 7c817b8..c51c85f 100644
40--- a/lib/note.ml
41+++ b/lib/note.ml
42 @@ -35,6 +35,17 @@ let get_title t =
43 in
44 match title with Some e -> Omd_backend.text_of_md [ e ] | None -> "???" )
45
46+ let get_description t =
47+ let description =
48+ match t.frontmatter with
49+ | Some fm -> (
50+ match Ezjsonm.find_opt (Ezjsonm.value fm) [ "description" ] with
51+ | Some v -> Some (Ezjsonm.get_string v)
52+ | None -> None )
53+ | None -> None
54+ in
55+ match description with Some description -> description | None -> ""
56+
57 let get_tags t =
58 match t.frontmatter with
59 | Some fm -> (
60 @@ -204,6 +215,7 @@ module Display = struct
61 [
62 [
63 ("title", [ Bold; Underlined ]);
64+ ("description", [ Bold; Underlined ]);
65 ("tags", [ Bold; Underlined ]);
66 ("words", [ Bold; Underlined ]);
67 ("slug", [ Bold; Underlined ]);
68 @@ -213,12 +225,13 @@ module Display = struct
69 ~f:(fun accm note ->
70 let title = (get_title note, [ Reset ]) in
71 let tags = (String.concat ~sep:"|" (get_tags note), [ Reset ]) in
72+ let description = (get_description note, [Reset]) in
73 let word_count =
74 ( Core.sprintf "%d" (List.length (Util.to_words note.markdown)),
75 [ Reset ] )
76 in
77 let slug = (Slug.to_string note.slug, [ Reset ]) in
78- accm @ [ [ title; tags; word_count; slug ] ])
79+ accm @ [ [ title; description; tags; word_count; slug ] ])
80 notes
81
82 let fixed_spacing cells =
83 diff --git a/lib/note.mli b/lib/note.mli
84index ddf0aa2..6f4dd30 100644
85--- a/lib/note.mli
86+++ b/lib/note.mli
87 @@ -6,6 +6,9 @@ val build : ?tags:string list -> ?content:string -> title:string -> Slug.t -> t
88 val get_title : t -> string
89 (** access the title of a note *)
90
91+ val get_description : t -> string
92+ (** access the description of a note *)
93+
94 val get_path : t -> string
95 (** access the absolute path of a note *)
96