2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: sitemap.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
15 open Cocanwiki_template
17 let template = get_template "sitemap.html"
19 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
20 (* Pull out all the current pages, and a bit of content from each. *)
21 let sth = dbh#prepare_cached "select p.url, p.url = 'index',
22 p.title, p.description,
24 (select content from contents
26 order by ordering limit 1) as content
28 where p.hostid = ? and p.url is not null
29 and p.redirect is null
30 order by 2 desc, 3, 1" in
31 sth#execute [`Int hostid];
35 (function [`String url; _; `String title; `String description;
36 `Timestamp last_modified_date;
37 (`Null | `String _) as content] ->
38 let url = if url = "index" then "" else url in
39 let date = printable_date last_modified_date in
40 [ "url", Template.VarString url;
41 "title", Template.VarString title;
42 "description", Template.VarString description;
43 "last_modified_date", Template.VarString date;
44 "has_content", Template.VarConditional (content <> `Null);
45 "content", Template.VarString
50 (Wikilib.text_of_xhtml
51 (Wikilib.xhtml_of_content dbh hostid c))) ]
52 | _ -> assert false) in
54 template#set "hostname" hostname;
55 template#table "sitemap" table;