diff --git a/src/content/assets/css/style.css b/src/content/assets/css/style.css index 0d409db..87a9198 100644 --- a/src/content/assets/css/style.css +++ b/src/content/assets/css/style.css @@ -141,3 +141,9 @@ a.post-menu-link { text-decoration: none; color: green; } + +.rss-logo { + height: 30px; + width: auto; + float: right; +} diff --git a/src/content/assets/img/atom.svg b/src/content/assets/img/atom.svg new file mode 100644 index 0000000..b325149 --- /dev/null +++ b/src/content/assets/img/atom.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/permap.ml b/src/permap.ml index bd166d8..90af8a6 100644 --- a/src/permap.ml +++ b/src/permap.ml @@ -288,6 +288,16 @@ let babillard_post request = | `Wrong_session _ | `Wrong_content_type -> Dream.empty `Bad_Request ) +let thread_feed_get request = + let thread_id = Dream.param request "thread_id" in + if Babillard.thread_exist thread_id then + let feed = Pp_babillard.feed thread_id in + match feed with + | Error e -> render_unsafe e request + | Ok feed -> + Dream.respond ~headers:[ ("Content-Type", "application/atom+xml") ] feed + else Dream.respond ~status:`Not_Found "Thread not found" + let thread_get request = let thread_id = Dream.param request "thread_id" in if Babillard.thread_exist thread_id then @@ -371,6 +381,7 @@ let routes = ; post "/report/:post_id" report_post ; get_ "/thread/:thread_id" thread_get ; post "/thread/:thread_id" reply_post + ; get_ "/thread/:thread_id/feed" thread_feed_get ; get_ "/user" user ; get_ "/user/:user" user_profile ; get_ "/user/:user/avatar" avatar_image diff --git a/src/pp_babillard.ml b/src/pp_babillard.ml index ac21946..4dfc3ad 100644 --- a/src/pp_babillard.ml +++ b/src/pp_babillard.ml @@ -271,3 +271,59 @@ let get_markers () = ops in Ok markers + +(* TODO get from config file? *) +let server_url = "http://localhost:3696" + +(* RFC-3339 date-time *) +let pp_date fmt date = + let date = Unix.gmtime date in + Format.fprintf fmt "%04d-%02d-%02dT%02d:%02d:%02dZ" (1900 + date.tm_year) + (1 + date.tm_mon) date.tm_mday date.tm_hour date.tm_min date.tm_sec + +let pp_feed_entry fmt post = + Format.fprintf fmt + {| + + Atom-Powered Robots Run Amok + urn:uuid:%s + %a + + %s + + %s + + + |} + post.id pp_date post.date post.nick + (Dream.html_escape post.comment) + server_url post.parent_id post.id + +let feed thread_id = + let* thread_data, op_post = get_op thread_id in + let^ ids = Db.collect_list Q.get_thread_posts thread_id in + let* posts = get_posts ids in + let posts = List.sort (fun a b -> compare b.date a.date) posts in + let last_update = (List.nth posts 0).date in + let entries fmt () = + (Format.pp_print_list ~pp_sep:Format.pp_print_space pp_feed_entry) fmt posts + in + (*TODO different uuid for op and thread ..?*) + let feed = + Format.asprintf + {| + + %s | Permap + + %a + + %s + + urn:uuid:%s + %a + + |} + thread_data.subject server_url thread_id pp_date last_update op_post.nick + op_post.id entries () + in + Ok feed diff --git a/src/thread_page.eml.html b/src/thread_page.eml.html index 1c4a4dd..6f311a2 100644 --- a/src/thread_page.eml.html +++ b/src/thread_page.eml.html @@ -1,9 +1,10 @@ let f thread_view thread_id request = <%s! thread_view %> +% let thread_url = Format.sprintf "/thread/%s" thread_id in % begin match Dream.session "nick" request with % | None -> -% let redirect = Dream.to_percent_encoded (Format.sprintf "/thread/%s" thread_id) in +% let redirect = Dream.to_percent_encoded thread_url in Login to reply! % | Some _ ->
@@ -25,3 +26,8 @@ let f thread_view thread_id request =
% end; +% let feed_url = Format.sprintf "%s/feed" thread_url in + > + + + />