Skip to content
Permalink
Browse files

Add custom mp extension

  • Loading branch information...
tsileo committed May 28, 2019
1 parent f5a4410 commit b23f5e8ed7f3970750dfc3d842988db8474305d2
Showing with 14 additions and 4 deletions.
  1. +1 −1 Makefile
  2. +7 −1 lib/entry.ml
  3. +6 −2 lib/micropub.ml
@@ -4,4 +4,4 @@ app:

.PHONY: bundle
bundle:
tar czvf bundle.tgz app static template.html atom.xml config.yaml
tar czvf bundle.tgz app static template.html atom.xml
@@ -22,6 +22,8 @@ let entry_tpl_data jdata =
let uid = jform_field jdata ["properties"; "uid"] "" in
let tags = jform_strings jdata ["properties"; "category"] in
let slug = jform_field jdata ["properties"; "mp-slug"] (slugify name) in
let extra_head = jform_field jdata ["properties"; "mp-extra-head"] "" in
let extra_body = jform_field jdata ["properties"; "mp-extra-body"] "" in
let has_category = if List.length tags > 0 then true else false in
let is_page = if List.mem "page" tags then true else false in
let is_draft = if List.mem "draft" tags then true else false in
@@ -42,6 +44,8 @@ let entry_tpl_data jdata =
"uid", `String uid;
"category", Ezjsonm.(strings tags);
"has_category", `Bool has_category;
"extra_head", `String extra_head;
"extra_body", `String extra_body;
"is_page", `Bool is_page;
"is_draft", `Bool is_draft;
"has_been_updated", `Bool has_been_updated;
@@ -89,7 +93,7 @@ let set uid entry =
Store.set t ~info:(info "Updating entry %s" uid) ["entries"; uid] Ezjsonm.(to_string entry)

(* Save a new entry *)
let save uid slug entry_type entry_content entry_name entry_published entry_category =
let save uid slug entry_type entry_content entry_name entry_published entry_category extra_head extra_body =
(* Serialize the entry to JSON microformats2 format *)
let obj = `O [
"type", `A [ `String entry_type ];
@@ -102,6 +106,8 @@ let save uid slug entry_type entry_content entry_name entry_published entry_cate
"url", `A [ `String (build_url uid slug) ];
"category", Ezjsonm.(strings entry_category);
"mp-slug", `A [ `String slug ];
"mp-extra-head", `A [ `String extra_head ];
"mp-extra-body", `A [ `String extra_body ];
]
] in
(* JSON serialize *)
@@ -170,11 +170,13 @@ let handle_json_create jdata scopes =
let entry_content = jform_field jdata ["properties"; "content"] "" in
let entry_category = jform_strings jdata ["properties"; "category"] in
let entry_published = jform_field jdata ["properties"; "published"] (Date.now () |> Date.to_string) in
let extra_head = jform_field jdata ["mp-extra-head"] "" in
let extra_body = jform_field jdata ["mp-extra-body"] "" in
if entry_type <> "h-entry" then
raise (Error_invalid_request "invalid type, only entry is supported")
else
let uid = new_id () in
save uid slug entry_type entry_content entry_name entry_published entry_category >>= fun () ->
save uid slug entry_type entry_content entry_name entry_published entry_category extra_head extra_body >>= fun () ->
Entry.update_hook (build_url uid slug) entry_content >>= fun (_) ->
let headers = Cohttp.Header.init ()
|> add_header "Location" (build_url uid slug) in
@@ -212,6 +214,8 @@ let handle_form_create dat scopes =
(* TODO better than Untitled *)
let entry_name = form_value dat "name" "Untitled" in
let slug = form_value dat "mp-slug" (slugify entry_name) in
let extra_head = form_value dat "mp-extra-head" "" in
let extra_body = form_value dat "mp-extra-body" "" in
let entry_category = parse_cat dat in
let entry_published = form_value dat "published" (Date.now () |> Date.to_string) in
if entry_content = "" then
@@ -222,7 +226,7 @@ let handle_form_create dat scopes =
raise (Error_invalid_request "invalid type, only entry is supported")
else
let uid = new_id () in
save uid slug ("h-" ^ entry_type) entry_content entry_name entry_published entry_category >>= fun () ->
save uid slug ("h-" ^ entry_type) entry_content entry_name entry_published entry_category extra_head extra_body >>= fun () ->
Entry.update_hook (build_url uid slug) entry_content >>= fun (_) ->
let headers = Cohttp.Header.init ()
|> add_header "Location" (build_url uid slug) in

0 comments on commit b23f5e8

Please sign in to comment.
You can’t perform that action at this time.