1 (* COCANWIKI - a wiki written in Objective CAML.
2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: page_rss.ml,v 1.6 2006/12/06 09:46:57 rich Exp $
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * This generates an RSS feed from a page. Articles in the RSS feed are
24 * mapped to sections in the page. At the moment it's fairly crude, but
25 * it's good enough for blogging at the moment. We can think about
26 * cleaning it up later.
35 open Cocanwiki_template
37 let run r (q : cgi) dbh hostid {hostname = hostname} _ =
38 let template = get_template r dbh hostid "page_rss.xml" in
40 let page = q#param "page" in
41 let page = if page = "" then "index" else page in
42 template#set "page" page;
44 template#set "hostname" hostname;
46 (* Get the title and description of the page. *)
48 "select id, title, description from pages
49 where hostid = $hostid and url = $page and redirect is null" in
51 let pageid, title, description =
54 | _ -> assert false in
56 template#set "title" title;
57 template#set "description" description;
59 (* Get the sections in the live page. *)
61 "select sectionname, content, ordering
63 where pageid = $pageid
64 and sectionname is not null
68 List.map (fun (sectionname, content, _) -> sectionname, content) rows in
71 List.map (fun (sectionname, content) ->
72 let sectionname = match sectionname with
73 | None -> "" | Some s -> s in
74 let content = Wikilib.xhtml_of_content r dbh hostid content in
75 let linkname = linkname_of_sectionname sectionname in
76 [ "sectionname", Template.VarString sectionname;
77 "linkname", Template.VarString linkname;
78 "content", Template.VarString content ]
81 template#table "sections" sections;
83 q#template ~content_type:"application/rss+xml" template
86 register_script ~restrict:[CanView] run