From: rich Date: Wed, 23 Nov 2005 11:32:37 +0000 (+0000) Subject: Google sitemap.xml. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=be6c7d6de3a92bc850a84ca4c234836b8e166fb9;p=cocanwiki.git Google sitemap.xml. --- diff --git a/conf/cocanwiki.conf b/conf/cocanwiki.conf index e3fc616..bcaea26 100644 --- a/conf/cocanwiki.conf +++ b/conf/cocanwiki.conf @@ -1,5 +1,5 @@ # Apache configuration for COCANWIKI. -# $Id: cocanwiki.conf,v 1.22 2005/11/16 16:06:33 rich Exp $ +# $Id: cocanwiki.conf,v 1.23 2005/11/23 11:32:37 rich Exp $ # Uncomment the following lines if necessary. You will probably need # to adjust the paths to reflect where cocanwiki is really installed. @@ -72,6 +72,7 @@ RewriteRule ^/_recent$ /_bin/recent.cmo [PT,L,QSA] RewriteRule ^/_recent.rss$ /_bin/recent_rss.cmo [PT,L,QSA] RewriteRule ^/_search$ /_bin/search.cmo [PT,L,QSA] RewriteRule ^/_sitemap$ /_bin/sitemap.cmo [PT,L,QSA] +RewriteRule ^/sitemap.xml$ /_bin/sitemap_xml.cmo [PT,L,QSA] RewriteRule ^/_userprefs$ /_bin/user_prefs_form.cmo [PT,L,QSA] RewriteRule ^/_users$ /_bin/users.cmo [PT,L,QSA] diff --git a/scripts/lib/cocanwiki_date.ml b/scripts/lib/cocanwiki_date.ml index 8450fd6..124f3f7 100644 --- a/scripts/lib/cocanwiki_date.ml +++ b/scripts/lib/cocanwiki_date.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_date.ml,v 1.2 2005/04/02 17:30:54 rich Exp $ + * $Id: cocanwiki_date.ml,v 1.3 2005/11/23 11:32:38 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,3 +50,12 @@ let printable_date (date, _) = printable_date' date let printable_date_time (date, time) = sprintf "%d %s %04d %02d:%02d" date.Dbi.day (short_month date.Dbi.month) date.Dbi.year time.Dbi.hour time.Dbi.min + +(* ISO 8601 timestamp. *) +let iso_8601_date_time (date, time) = + sprintf "%04d-%02d-%02dT%02d:%02d:%02d" + date.Dbi.year date.Dbi.month date.Dbi.day + time.Dbi.hour time.Dbi.min time.Dbi.sec ^ + match time.Dbi.timezone with + | None -> "Z" + | Some t -> sprintf "+%02d:00" t diff --git a/scripts/sitemap_xml.ml b/scripts/sitemap_xml.ml new file mode 100644 index 0000000..1df01b5 --- /dev/null +++ b/scripts/sitemap_xml.ml @@ -0,0 +1,66 @@ +(* COCANWIKI - a wiki written in Objective CAML. + * Written by Richard W.M. Jones . + * Copyright (C) 2004 Merjis Ltd. + * $Id: sitemap_xml.ml,v 1.1 2005/11/23 11:32:37 rich Exp $ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + *) + +open Apache +open Registry +open Cgi +open Printf + +open Cocanwiki +open Cocanwiki_template +open Cocanwiki_date +open Cocanwiki_strings + +(* For Google sitemap.xml specification, please see: + * https://www.google.com/webmasters/sitemaps/docs/en_GB/protocol.html + *) + +let run r (q : cgi) (dbh : Dbi.connection) hostid { hostname = hostname } _ = + let template = get_template dbh hostid "sitemap.xml" in + + (* Pull out all the current pages. *) + let sth = dbh#prepare_cached "select p.url, p.url = 'index', + p.last_modified_date + from pages p + where p.hostid = ? and p.url is not null + and p.redirect is null + order by 2 desc, 1" in + sth#execute [`Int hostid]; + + let table = + sth#map + (function [`String url; `Bool is_index; + `Timestamp last_modified_date] -> + let url = if is_index then "" else url in + let last_modified_date = iso_8601_date_time last_modified_date in + let priority = if is_index then "1.0" else "0.5" in + [ "url", Template.VarString url; + "last_modified_date", Template.VarString last_modified_date; + "priority", Template.VarString priority ] + | xs -> failwith (Dbi.sdebug xs)) in + + template#set "hostname" hostname; + template#table "sitemap" table; + + q#template ~content_type:"application/xml" template + +let () = + register_script ~restrict:[CanView] run diff --git a/templates/sitemap.xml b/templates/sitemap.xml new file mode 100644 index 0000000..1634f40 --- /dev/null +++ b/templates/sitemap.xml @@ -0,0 +1,20 @@ + + + + +http://::hostname::/_recent +daily + + + +http://::hostname::/_sitemap + + +::table(sitemap):: +http://::hostname::/::url_html:: +::last_modified_date_html:: +::priority_html:: + +::end:: + + \ No newline at end of file