Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
David Declerck
www
Commits
81849ecd
Commit
81849ecd
authored
Sep 10, 2021
by
Dario Pinto
Browse files
Change error output, add Omd AST for preview text folding
parent
a175cf83
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
11 deletions
+61
-11
src/blog.ml
src/blog.ml
+61
-11
No files found.
src/blog.ml
View file @
81849ecd
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment