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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
open Tyxml.Html
let this_title = title (txt "Your Cool Web Page")
let image_box =
div ~a:[a_id "image_box"]
[]
let links_box =
ul ~a:[a_class ["links_bar"]; a_id "links_bar"]
[li ~a:[a_id "home_click"]
[txt "My Musings"];
li ~a:[a_id "about_click"]
[txt "About Me"];
li ~a:[a_id "blog_posts_click"]
[txt "Blog"];
li ~a:[a_id "hackathons_click"]
[txt "Hackathons"]]
let common_footer =
footer ~a:[a_id "footer_box"]
[p [txt "This site was made with ";
a ~a:[a_href "http://ocaml.org"] [txt "OCaml"];
txt " and ";
a ~a:[a_href "https://www.gnu.org/software/emacs/"] [txt "emacs"]]]
let home_content =
div
[h2
[txt "Hello Coder"]]
let main_payload =
div ~a:[a_id "payload"]
[home_content]
let common_nav =
nav [links_box]
let content_box =
div ~a:[a_id "content_box"]
[common_nav;
main_payload;
common_footer]
let main_script =
script ~a:[a_src (Xml.uri_of_string "main.js")] (txt "")
let home_page_doc =
html (head this_title
[link ~rel:[`Stylesheet] ~href:"home.css" ();])
(body [image_box; content_box; main_script])
(** The set of pages in your website. *)
let pages = [("index.html", home_page_doc)]
(** Small code to emit all the pages. *)
let emit_page (name, page) =
Printf.printf "Generating: %s\n" name ;
let file_handle = open_out name in
let fmt = Format.formatter_of_out_channel file_handle in
Format.fprintf fmt "%a@." (pp ~indent:true ()) page;
close_out file_handle
let () = List.iter emit_page pages
|