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 @@
(ubase
(>= 0.04))
(markup
(>= 1.0.2))))
(>= 1.0.2))
(lambdasoup
(>= 0.7.2))))
......@@ -9,6 +9,7 @@ depends: [
"omd" {>= "2.0.0~alpha2"}
"ubase" {>= "0.04"}
"markup" {>= "1.0.2"}
"lambdasoup" {>= "0.7.2"}
]
build: [
["dune" "subst"] {pinned}
......
......@@ -114,7 +114,7 @@ We cater to very specific needs. For example, we can translate a “black box”
<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 />
......
(executable
(public_name server)
(modules content server template blog blog_content)
(libraries dream omd ubase markup))
(libraries dream omd ubase markup lambdasoup))
(rule
(targets template.ml)
......
......@@ -30,6 +30,15 @@ let given_article path =
Some (header ^ (Omd.of_string article.content |> Omd.to_html))
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 () =
Dream.run ~interface:"0.0.0.0"
@@ Dream.logger
......@@ -40,39 +49,39 @@ let () =
match page "index" with
| None -> Dream.empty `Not_Found
| Some content ->
Dream.html
(Template.render_unsafe ~lang:"en" ~title:"title" ~content) )
let title = title content in
Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/category" (fun _request ->
let content = Blog.category_home in
Dream.html
(Template.render_unsafe ~lang:"en" ~title:"Categories" ~content) )
let title = title content in
Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/category/:cat" (fun request ->
let content = Blog.given_category (Dream.param "cat" request) in
Dream.html
(Template.render_unsafe ~lang:"en" ~title:"Category" ~content) )
let title = title content in
Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/authors" (fun _request ->
let content = Blog.authors_home in
Dream.html
(Template.render_unsafe ~lang:"en" ~title:"Authors" ~content) )
let title = title content in
Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/authors/:author" (fun request ->
let content = Blog.given_author (Dream.param "author" request) in
Dream.html
(Template.render_unsafe ~lang:"en" ~title:"Author" ~content) )
let title = title content in
Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog/:title" (fun request ->
match given_article (Dream.param "title" request) with
| None -> Dream.empty `Not_Found
| Some content ->
Dream.html
(Template.render_unsafe ~lang:"en" ~title:"title" ~content) )
let title = title content in
Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/blog" (fun _request ->
let content = Blog.home_page in
Dream.html
(Template.render_unsafe ~lang:"en" ~title:"title" ~content) )
let title = title content in
Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
; Dream.get "/:page" (fun request ->
match page (Dream.param "page" request) with
| None -> Dream.empty `Not_Found
| Some content ->
Dream.html
(Template.render_unsafe ~lang:"en" ~title:"title" ~content) )
let title = title content in
Dream.html (Template.render_unsafe ~lang:"en" ~title ~content) )
]
@@ 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