Commit f0b1f908 authored by Dario Pinto's avatar Dario Pinto
Browse files

Add title support with lambdasoup, change article to md source

parent 64fa0e2f
...@@ -20,4 +20,6 @@ ...@@ -20,4 +20,6 @@
(ubase (ubase
(>= 0.04)) (>= 0.04))
(markup (markup
(>= 1.0.2)))) (>= 1.0.2))
(lambdasoup
(>= 0.7.2))))
...@@ -9,6 +9,7 @@ depends: [ ...@@ -9,6 +9,7 @@ depends: [
"omd" {>= "2.0.0~alpha2"} "omd" {>= "2.0.0~alpha2"}
"ubase" {>= "0.04"} "ubase" {>= "0.04"}
"markup" {>= "1.0.2"} "markup" {>= "1.0.2"}
"lambdasoup" {>= "0.7.2"}
] ]
build: [ build: [
["dune" "subst"] {pinned} ["dune" "subst"] {pinned}
......
...@@ -114,7 +114,7 @@ We cater to very specific needs. For example, we can translate a “black box” ...@@ -114,7 +114,7 @@ We cater to very specific needs. For example, we can translate a “black box”
<hr class="featurette-divider"> <hr class="featurette-divider">
<h1 class="page-subtitle" align="center">You're in good company</h1> <h2 class="page-subtitle" align="center">You're in good company</h2>
<br /> <br />
<br /> <br />
......
(executable (executable
(public_name server) (public_name server)
(modules content server template blog blog_content) (modules content server template blog blog_content)
(libraries dream omd ubase markup)) (libraries dream omd ubase markup lambdasoup))
(rule (rule
(targets template.ml) (targets template.ml)
......
...@@ -30,6 +30,15 @@ let given_article path = ...@@ -30,6 +30,15 @@ let given_article path =
Some (header ^ (Omd.of_string article.content |> Omd.to_html)) Some (header ^ (Omd.of_string article.content |> Omd.to_html))
end end
open Soup
let title content =
try
let soup = content |> parse in
soup $ "h1" |> R.leaf_text
with
| Failure _e -> "Harnessing Cutting-Edge Technologies"
let () = let () =
Dream.run ~interface:"0.0.0.0" Dream.run ~interface:"0.0.0.0"
@@ Dream.logger @@ Dream.logger
...@@ -40,39 +49,39 @@ let () = ...@@ -40,39 +49,39 @@ let () =
match page "index" with match page "index" with
| None -> Dream.empty `Not_Found | None -> Dream.empty `Not_Found
| Some content -> | Some content ->
Dream.html let title = title content in
(Template.render_unsafe ~lang:"en" ~title:"title" ~content) ) Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/category" (fun _request -> ; Dream.get "/blog/category" (fun _request ->
let content = Blog.category_home in let content = Blog.category_home in
Dream.html let title = title content in
(Template.render_unsafe ~lang:"en" ~title:"Categories" ~content) ) Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/category/:cat" (fun request -> ; Dream.get "/blog/category/:cat" (fun request ->
let content = Blog.given_category (Dream.param "cat" request) in let content = Blog.given_category (Dream.param "cat" request) in
Dream.html let title = title content in
(Template.render_unsafe ~lang:"en" ~title:"Category" ~content) ) Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/authors" (fun _request -> ; Dream.get "/blog/authors" (fun _request ->
let content = Blog.authors_home in let content = Blog.authors_home in
Dream.html let title = title content in
(Template.render_unsafe ~lang:"en" ~title:"Authors" ~content) ) Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/authors/:author" (fun request -> ; Dream.get "/blog/authors/:author" (fun request ->
let content = Blog.given_author (Dream.param "author" request) in let content = Blog.given_author (Dream.param "author" request) in
Dream.html let title = title content in
(Template.render_unsafe ~lang:"en" ~title:"Author" ~content) ) Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/:title" (fun request -> ; Dream.get "/blog/:title" (fun request ->
match given_article (Dream.param "title" request) with match given_article (Dream.param "title" request) with
| None -> Dream.empty `Not_Found | None -> Dream.empty `Not_Found
| Some content -> | Some content ->
Dream.html let title = title content in
(Template.render_unsafe ~lang:"en" ~title:"title" ~content) ) Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog" (fun _request -> ; Dream.get "/blog" (fun _request ->
let content = Blog.home_page in let content = Blog.home_page in
Dream.html let title = title content in
(Template.render_unsafe ~lang:"en" ~title:"title" ~content) ) Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/:page" (fun request -> ; Dream.get "/:page" (fun request ->
match page (Dream.param "page" request) with match page (Dream.param "page" request) with
| None -> Dream.empty `Not_Found | None -> Dream.empty `Not_Found
| Some content -> | Some content ->
Dream.html let title = title content in
(Template.render_unsafe ~lang:"en" ~title:"title" ~content) ) Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
] ]
@@ Dream.not_found @@ Dream.not_found
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