Commit 2bf1ce2a authored by Artemiy's avatar Artemiy
Browse files

normalize tags

parent 011c3d7a
......@@ -112,6 +112,26 @@ let normalize_url target =
| c -> c |> Char.lowercase_ascii )
(Ubase.from_utf8 target)
let normalize_tag tag =
let string_map_partial f s =
let b = Buffer.create (String.length s) in
let maybeadd c =
match f c with
| None -> ()
| Some c' -> Buffer.add_char b c'
in
String.iter maybeadd s;
Buffer.contents b
in
string_map_partial
(function
| '-'
| ' '
| '_' ->
None
| c -> Some (Char.lowercase_ascii c) )
(Ubase.from_utf8 tag)
(** [allowed_categories] is a list of allowed categories for any article posted
on the blog *)
let allowed_categories =
......@@ -249,12 +269,11 @@ let categories_count =
let l = Hashtbl.fold (fun k v acc -> (k, v) :: acc) tbl [] in
List.sort (fun (k1, v1) (k2, v2) -> compare (v2, k2) (v1, k1)) l
let pp_list_to_blog_links t =
let pp_list_to_blog_links t normalize =
Format.pp_print_list
~pp_sep:(fun fmt () -> Format.fprintf fmt ", ")
(fun fmt e ->
Format.fprintf fmt {|<a href="/blog/%s/%s">%s</a>|} t (normalize_url e) e
)
Format.fprintf fmt {|<a href="/blog/%s/%s">%s</a>|} t (normalize e) e )
let links_to_home_pages =
Format.sprintf
......@@ -310,11 +329,11 @@ let pp_article_excerpt fmt article =
<br />
%s <a href="/blog/%s">(Read more)</a>|}
article.url article.title
(pp_list_to_blog_links "authors")
(pp_list_to_blog_links "authors" normalize_url)
article.authors year month day
(normalize_url article.category)
article.category
(pp_list_to_blog_links "tag")
(pp_list_to_blog_links "tag" normalize_tag)
article.tags (preview article.content) article.url
let pp_blog_posts fmt articles_data_list =
......@@ -355,9 +374,9 @@ let specific_article_header title authors (year, month, day) category tags =
<hr class="featurette-divider"/>
<br />|}
title
(pp_list_to_blog_links "authors")
(pp_list_to_blog_links "authors" normalize_url)
authors year month day (normalize_url category) category
(pp_list_to_blog_links "tag")
(pp_list_to_blog_links "tag" normalize_tag)
tags
(** [given_category category] Displays the list of articles corresponding to the
......@@ -400,7 +419,7 @@ let given_tag tag =
List.filter
(fun article ->
List.exists
(fun tag0 -> String.equal (normalize_url tag0) tag)
(fun tag0 -> String.equal (normalize_tag tag0) tag)
article.tags )
articles_by_date
in
......
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