open Data
open Utils
open Xhtml
open GenEntries
open GenMenu
open Output
open Date
(* Generating entries from disk *)
let category_of_name name = input_one_line (name ^ "/category")
let title_of_name name = xml_of_file (name ^ "/title")
let text_of_name name = xml_of_file ~space_handling:Xml_lexer.AllSpaces (name ^ "/text.htmlt")
let date_of_name name file = split_date (input_one_line (name ^ "/" ^ file))
let links_of_name name = Links.parse_links (name ^ "/links")
let range_of_name name =
let d = date_of_name name "date" in
try
let d' = date_of_name name "updated" in
Range(d, d')
with Sys_error _ -> SingleDate d
let own_page name =
try
close_in (open_in (name ^ "/own_page"));
true
with _ -> false
let not_linked name =
try
close_in (open_in (name ^ "/hidden"));
true
with _ -> false
let input_entry name =
let title = title_of_name name in
{ name = name;
date = range_of_name name;
title = title;
title_plain_text = to_plain_text_list_span title;
category = category_of_name name;
text = text_of_name name;
links = links_of_name name;
own_page = own_page name;
hidden = not_linked name;
}
(* All entries *)
let entries_cat =
let entries = Sys.readdir "." in
let entries_cat = Array.make (List.length categories) [] in
Array.iter
(fun name ->
if name.[0] <> '_' && name <> ".htaccess" then
let e = input_entry name in
let n = num_category e.category in
entries_cat.(n) <- e :: entries_cat.(n))
entries;
Array.iteri
(fun i ecat ->
entries_cat.(i) <- List.sort compare_entries_date ecat)
entries_cat;
entries_cat
let top_ten_cat = Array.map (firstn 10) entries_cat
let recent_cat =
Array.mapi (fun cat lcat ->
let tcat = category_text_of_num cat
and lcat = List.map (fun e -> [link_entry e]) lcat in
recent (Some tcat) lcat)
top_ten_cat
let top_fifteen =
List.sort compare_entries_date (Array.fold_left (@) []
(Array.map (firstn 5) top_ten_cat))
let recent_general = recent None
(List.map (fun e -> [link_entry e]) top_fifteen)
let list_jump e =
[a ~href:("#" ^ e.name) ~title:e.title_plain_text e.title]
let contact = input_page "contact.htmlt"
let about = input_page "about.htmlt"
let home = input_page "home.htmlt"
let bibli_date = input_page "../../publis/biblio_date.htmlt"
let bibli_bib = input_page ~space_handling:Xml_lexer.AllSpaces
"../../publis/biblio_bib.htmlt"
let annees_biblio = [2009;2008;2007;2005;2004;2002]
let bibli_menu_date =
let years =
let lyears = List.map (fun i -> let s = string_of_int i in
a ~href:("biblio.html#" ^ s) [text s]) annees_biblio in
ul (List.map (fun e -> [e]) lyears)
in
("Publications by date", [years])
let bibli_menu_bibtex =
("Publications in BibTeX format", [a ~href:"biblio_bib.html" [text "Here"]])
let intro_cat =
[| ["About me", input_page "research.htmlt";
"Publications", input_page "publications.htmlt"];
["Presentation", input_page "software.htmlt"];
["Photography", input_page "photo.htmlt";
"Current gear", input_page "gear.htmlt";
"Header picture", input_page "header.htmlt"] |]
let fullpage_to_file wwwname ~title ?entries_class ~nav ?search ?buttons ?recent ?other_menu text =
log_page wwwname;
to_file ("../../entries/" ^ wwwname ^ ".html")
(fullpage ~title ?entries_class ~nav ?search ?buttons ?recent
?other_menu text)
let _ =
if Data.output_entries then
(* Home *)
fullpage_to_file "home" ~title:"" ~nav:GenNav.navhome ~recent:recent_general
~other_menu:["Presentation", home] (entries_xml ~cat:true top_fifteen);
(* Main by categories *)
List.iter (fun (_, i, catname) ->
fullpage_to_file catname
~title:(String.capitalize catname) ~nav:GenNav.navcat.(i)
~recent:recent_cat.(i)
~other_menu:intro_cat.(i)
(entries_xml ~cat:false entries_cat.(i))) categories;
(* Each entry *)
Array.iteri
(fun cat lcat -> List.iter
(fun entry ->
if entry.own_page then
let nav = GenNav.navcat.(cat)
and recent = recent_cat.(cat) in
let text = [entry_xml ~cat:false entry] in
fullpage_to_file entry.name ~title:entry.title_plain_text
~nav ~recent text)
lcat)
entries_cat;
(* Contact *)
fullpage_to_file "contact" ~title:"Contact" ~buttons:`Second
~nav:GenNav.navcontact contact;
(* About *)
fullpage_to_file "about" ~title:"About" ~buttons:`Second
~nav:GenNav.navabout about;
(* Bib *)
fullpage_to_file "biblio" ~nav:GenNav.navcat.(0)
~title:"Publications by Boris Yakobowski, sorted by date"
~entries_class:"biblio"
~other_menu:[bibli_menu_date; bibli_menu_bibtex] ~buttons:`Second
[div ~id:"bibli-dates" ~nclass:"entry"
[div ~nclass:"entry" bibli_date]];
fullpage_to_file "biblio_bib" ~nav:GenNav.navcat.(0)
~title:"BibTeX entries for publications by Boris Yakobowski"
~entries_class:"biblio-bibtex"
~other_menu:[bibli_menu_date] ~buttons:`Second
[div ~nclass:"entry" bibli_bib];