Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a2b3e9f4d5
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 42 lines (32 sloc) 1.014 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
open Printf
open Htmlgen

(* get template body *)
let get n = Db.get_tmpl n
(* substitute markdown from template *)
let md n = Markdown_html.t (Markdown.parse_text (get n))

let header = get "header.inc"
let footer = get "footer.inc"

(* substitute keys in hashtbl h in string s *)
let subst s h =
  let re frm tos s =
    let rex = Pcre.regexp frm in
    let itempl = Pcre.subst tos in
    Pcre.replace ~rex ~itempl s in
  Hashtbl.fold re h s

(* new hash with title key *)
let keys ?extra title =
  let h = Hashtbl.create 1 in
  Hashtbl.add h "@@TITLE@@" title;
  (match extra with
  |None -> ()
  |Some l -> List.iter (fun (k,v) -> Hashtbl.add h k v) l);
  h

let page p h = subst (header ^ p ^ footer) h

module Index = struct

  let h = keys ~extra:[ "@@CONTENT@@", md "intro.md" ; "@@HEADER_PIC@@", "home" ] "index"
  let t = page (get "index.inc") h

end

module Pages = struct
  let h c = keys ~extra:[ "@@CONTENT@@", c; "@@HEADER_PIC@@", "papers" ] "papers"
  let t c = page (get "papers.inc") (h c)
end
Something went wrong with that request. Please try again.