simple css support

This commit is contained in:
Stavros Polymenis 2016-09-05 21:38:11 +01:00
parent 4edbbad730
commit 7a4b7c9105
2 changed files with 15 additions and 13 deletions

View File

@ -2,8 +2,12 @@ let html_of ymd =
let ymd_title = ymd.Logarion.meta.title in let ymd_title = ymd.Logarion.meta.title in
let ymd_body = Omd.to_html (Omd.of_string ymd.Logarion.text) in let ymd_body = Omd.to_html (Omd.of_string ymd.Logarion.text) in
let open Tyxml.Html in let open Tyxml.Html in
let tyhtml = html let tyhtml =
(head (title (Unsafe.data ymd_title)) []) html
(body [Unsafe.data ymd_body]) (head
in (title (Unsafe.data ymd_title))
[link ~rel:[`Stylesheet] ~href:"style.css" ();]
)
(body [Unsafe.data ymd_body])
in
Format.asprintf "%a" (Tyxml.Html.pp ()) tyhtml Format.asprintf "%a" (Tyxml.Html.pp ()) tyhtml

View File

@ -1,11 +1,5 @@
open Opium.Std open Opium.Std
let test = "---
title: Test
author: orbifx
---
Hello _world_!"
let load_file f = let load_file f =
let ic = open_in f in let ic = open_in f in
let n = in_channel_length ic in let n = in_channel_length ic in
@ -13,14 +7,18 @@ let load_file f =
really_input ic s 0 n; really_input ic s 0 n;
close_in ic; close_in ic;
(s) (s)
let print_css =
get "/style.css" begin fun req -> `String (load_file "ymd/style.css") |> respond' end
let print_ymd = let print_ymd =
get "/:title" begin fun req -> get "/:title" begin fun req ->
let file = (param req "title") ^ ".ymd" in let file = "ymd/" ^ (param req "title") ^ ".ymd" in
`Html (Html.html_of (Logarion.ymd (load_file file))) |> respond' `Html (Html.html_of (Logarion.ymd (load_file file))) |> respond'
end end
let _ = let _ =
App.empty App.empty
|> print_ymd |> print_ymd
|> print_css
|> App.run_command |> App.run_command