Commit 81849ecd authored by Dario Pinto's avatar Dario Pinto
Browse files

Change error output, add Omd AST for preview text folding

parent a175cf83
......@@ -8,6 +8,54 @@ type article =
; url : string
}
let error msg =
Format.eprintf "error: %s@." msg;
Format.pp_print_flush Format.err_formatter ();
exit 1
(* The code below is used to extract a small preview from the content field of a article type with the help of Omd *)
open Omd
let rec handle_inline = function
| Concat (attr, attr_inline_list) ->
Concat (attr, List.map handle_inline attr_inline_list)
| Text (attr, s) -> Text (attr, s)
| Emph (attr, attr_inline) -> Emph (attr, handle_inline attr_inline)
| Strong (attr, attr_inline) -> Strong (attr, handle_inline attr_inline)
| Code (attr, s) -> Code (attr, s)
| Hard_break attr -> Hard_break attr
| Soft_break attr -> Soft_break attr
| Link (attr, attr_link) -> Link (attr, attr_link)
| Image (attr, attr_link) -> Image (attr, attr_link)
| Html (attr, s) -> Html (attr, s)
let rec handle_block = function
| Paragraph (attr, inline) -> Paragraph (attr, handle_inline inline)
| List (attr, list_type, list_spacing, attr_block_list_list) ->
List
( attr
, list_type
, list_spacing
, List.map (List.map handle_block) attr_block_list_list )
| Blockquote (attr, attr_block_list) ->
Blockquote (attr, List.map handle_block attr_block_list)
| Thematic_break attr -> Thematic_break attr
| Heading (attr, i, attr_inline) ->
Heading (attr, i, handle_inline attr_inline)
| Code_block (attr, s1, s2) -> Code_block (attr, s1, s2)
| Html_block (attr, str) -> Html_block (attr, str)
| Definition_list (attr, attr_def_elt_list) ->
Definition_list (attr, attr_def_elt_list)
let find_preview doc = Omd.to_html (List.map handle_block doc)
let preview article_content =
let _content = Omd.of_string article_content |> find_preview in
Format.sprintf "%s..." "This will hold some preview of article soon"
(* The code above is used to extract a small preview from the content field of a article type with the help of Omd *)
(** [normalize_url target] takes a target URL and rids it of unwanted
characters, such as utf8, and spaces *)
let normalize_url target =
String.map
(function
......@@ -27,8 +75,6 @@ let allowed_categories =
; "Rust"
]
let category_urls = List.map normalize_url allowed_categories
(** [raw_articles] List of all raw text in all articles in /content/blog/
subdirectory *)
let raw_articles =
......@@ -70,13 +116,17 @@ let article_of_string post url =
; category =
begin
let c = get_meta_value category in
if not @@ List.mem c allowed_categories then
failwith
(Format.asprintf {|Category (%s) invalid, try: %a|} c
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt ", ")
Format.pp_print_string )
allowed_categories );
if not @@ List.mem c allowed_categories then (
let err_msg =
Format.asprintf {|Category (%s) invalid, try: %a@.|} c
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt ", ")
Format.pp_print_string )
allowed_categories
in
Format.pp_print_flush Format.str_formatter ();
error err_msg
);
c
end
; content = String.concat "\n" r
......@@ -180,7 +230,7 @@ let pp_article_excerpt fmt article =
</div>
</div>
<br />
<a href="/blog/%s">Read more...</a>
%s<a href="/blog/%s">(Read more...)</a>
<hr class="featurette-divider"/>
<br />|}
article.url article.title
......@@ -195,7 +245,7 @@ let pp_article_excerpt fmt article =
(Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt ", ")
Format.pp_print_string )
article.tags article.url
article.tags (preview article.content) article.url
let pp_blog_posts fmt articles_data_list =
List.iter (Format.fprintf fmt "%a" pp_article_excerpt) articles_data_list
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment