From edf7176e94baea63b846e74da83bb32707f71ca6 Mon Sep 17 00:00:00 2001 From: Swrup Date: Wed, 2 Feb 2022 13:47:04 +0100 Subject: [PATCH] show tags --- src/content/assets/css/style.css | 6 ++++++ src/pp_babillard.ml | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/content/assets/css/style.css b/src/content/assets/css/style.css index 5d2623c..11d8eea 100644 --- a/src/content/assets/css/style.css +++ b/src/content/assets/css/style.css @@ -96,3 +96,9 @@ blockquote.blockquote { color: #5a5a5a; font-size: 30px; } + +.tag { + background-color: #FFB300; + border-radius: 4px; + padding: 2px; +} diff --git a/src/pp_babillard.ml b/src/pp_babillard.ml index 748b7c2..273d411 100644 --- a/src/pp_babillard.ml +++ b/src/pp_babillard.ml @@ -7,7 +7,7 @@ let view_post ?is_thread_preview post_id = let* date = Db.find Q.get_post_date post_id in let* image_info = Db.find_opt Q.get_post_image_info post_id in - let* _tags = Db.fold Q.get_post_tags (fun tag acc -> tag :: acc) post_id [] in + let* tags = Db.fold Q.get_post_tags (fun tag acc -> tag :: acc) post_id [] in let* replies = Db.fold Q.get_post_replies (fun reply_id acc -> reply_id :: acc) post_id [] in @@ -33,9 +33,10 @@ let view_post ?is_thread_preview post_id = Format.fprintf fmt {|>>%s|} reply reply in - let pp_print_replies = + let pp_print_replies replies = Format.asprintf {|
%a
|} (Format.pp_print_list ~pp_sep:Format.pp_print_space pp_print_reply) + replies in let replies_view = @@ -78,6 +79,18 @@ let view_post ?is_thread_preview post_id = |} nick date post_links_view in + + let pp_print_tag fmt tag = + Format.fprintf fmt {|%s|} tag + in + let pp_print_tags tags = + Format.asprintf {|
%a
|} + (Format.pp_print_list ~pp_sep:Format.pp_print_space pp_print_tag) + tags + in + let tags = List.sort String.compare tags in + let tags_view = pp_print_tags tags in + let post_view = Format.sprintf {| @@ -86,10 +99,11 @@ let view_post ?is_thread_preview post_id = %s %s
%s
+ %s |} - post_id post_info_view image_view comment + post_id post_info_view image_view comment tags_view in Ok post_view