Events in iCalendar format

Ceri Davies ceri at submonkey.net
Wed Aug 17 11:23:48 UTC 2005


On Wed, Aug 17, 2005 at 07:42:20PM +0900, Hiroki Sato wrote:
> Ceri Davies <ceri at submonkey.net> wrote
>   in <20050817094746.GR55885 at submonkey.net>:
> 
> ce> On Wed, Aug 17, 2005 at 07:01:43AM +0900, Hiroki Sato wrote:
> ce> >  Hmm, could you please put the XSLT stylesheet into the language-independent
> ce> >  directory?
> ce>
> ce> Along this line, I don't see why we have a copy of events.dtd in every
> ce> language-dependent directory.
> 
>  Yes, it is pointless, too.  I am planning to clean up this sort of
>  duplicate files when I import doc.xml.mk.  So when you add a new
>  language-independent file, putting it into the LI directory
>  from the beginning would be nice.

OK, here's the new diff.

Ceri
-- 
Only two things are infinite, the universe and human stupidity, and I'm
not sure about the former.			  -- Einstein (attrib.)
-------------- next part --------------
Index: share/sgml/events2ics.xsl
===================================================================
RCS file: share/sgml/events2ics.xsl
diff -N share/sgml/events2ics.xsl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ share/sgml/events2ics.xsl	17 Aug 2005 11:23:06 -0000
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<!-- Copyright (c) 2005 Ceri Davies <ceri at FreeBSD.org>
+     All rights reserved.
+
+     Redistribution and use in source and binary forms, with or without
+     modification, are permitted provided that the following conditions
+     are met:
+     1. Redistributions of source code must retain the above copyright
+	notice, this list of conditions and the following disclaimer.
+     2. Redistributions in binary form must reproduce the above copyright
+	notice, this list of conditions and the following disclaimer in the
+	documentation and/or other materials provided with the distribution.
+
+     THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+     ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+     FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+     OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+     HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+     OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+     SUCH DAMAGE.
+
+     $FreeBSD$
+-->
+
+<!-- Generate an iCalendar file from a www/en/events/events.dtd
+  compliant events.xml -->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
+  xmlns:cvs="http://www.FreeBSD.org/XML/CVS"
+  exclude-result-prefixes="cvs">
+
+  <xsl:variable name="freebsd-web-base" select="'http://www.FreeBSD.org'"/>
+
+  <xsl:output method="text" encoding="iso-8859-1"/>
+  <xsl:strip-space elements="*"/>
+
+  <!-- Template: events -->
+  <xsl:template match="events">BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:$FreeBSD$
+    <xsl:apply-templates select="event"/>
+END:VCALENDAR</xsl:template>
+
+  <!-- Template: event -->
+  <xsl:template match="event">
+BEGIN:VEVENT
+SEQUENCE:<xsl:value-of select="position()" />
+SUMMARY:<xsl:value-of select="name"/>
+    <xsl:if test="url">
+      <xsl:apply-templates select="url"/>
+    </xsl:if>
+LOCATION:<xsl:if test="location/site!=''">
+      <xsl:value-of select="location/site"/>
+    </xsl:if>
+    <xsl:if test="location/city!=''">
+      <xsl:text>, </xsl:text>
+      <xsl:value-of select="location/city"/>
+    </xsl:if>
+    <xsl:if test="location/state!=''">
+      <xsl:text>, </xsl:text>
+      <xsl:value-of select="location/state"/>
+    </xsl:if>
+    <xsl:if test="location/country!=''">
+      <xsl:text>, </xsl:text>
+      <xsl:value-of select="location/country"/>
+    </xsl:if>
+    <xsl:call-template name="gen-ical-date-interval">
+      <xsl:with-param name="startdate" select="startdate" />
+      <xsl:with-param name="enddate" select="enddate" />
+    </xsl:call-template>
+DESCRIPTION:<xsl:copy-of select="description/child::node()"/>
+    <xsl:if test="link">
+      <xsl:apply-templates select="link"/>
+    </xsl:if>
+END:VEVENT</xsl:template>
+
+  <!-- Template: link -->
+  <xsl:template match="link">
+    <xsl:apply-templates select="url"/>
+  </xsl:template>
+
+  <!-- Template: url -->
+  <xsl:template match="url">
+URL;VALUE=URI:<xsl:choose>
+      <xsl:when test="@type='freebsd-website'">
+        <xsl:value-of select="$freebsd-web-base"/>
+      </xsl:when>
+    </xsl:choose>
+    <xsl:value-of select="."/>
+  </xsl:template>
+
+  <!-- Generate iCalendar DTSTART and DTEND entries -->
+  <xsl:template name="gen-ical-date-interval">
+    <xsl:param name="startdate"/>
+    <xsl:param name="enddate"/>
+
+DTSTART;VALUE=DATE:<xsl:value-of select="concat(startdate/year,
+	    format-number(startdate/month, '00'),
+	    format-number(startdate/day, '00'))"/>
+
+    <xsl:if test="number(startdate/month) != number(enddate/month) or
+		  number(startdate/day) != number(enddate/day) or
+		  number(startdate/year) != number(enddate/year)">
+DTEND;VALUE=DATE:<xsl:value-of select="concat(enddate/year,
+	format-number(enddate/month, '00'),
+	format-number(enddate/day, '00'))"/>
+
+     </xsl:if>
+  </xsl:template>
+</xsl:stylesheet>
Index: en/events/Makefile
===================================================================
RCS file: /home/dcvs/www/en/events/Makefile,v
retrieving revision 1.7
diff -u -r1.7 Makefile
--- en/events/Makefile	6 Apr 2004 11:36:12 -0000	1.7
+++ en/events/Makefile	17 Aug 2005 11:23:06 -0000
@@ -12,8 +12,10 @@
 
 DATA=	events.css
 DATA+=	events.html
+DATA+=	events.ics
 
 CLEANFILES+= events.html
+CLEANFILES+= events.ics
 CLEANFILES+= curdate.xml
 
 INDEXLINK= events.html
@@ -29,6 +31,10 @@
 	-${TIDY} ${TIDYOPTS} ${.TARGET}
 .endif
 
+events.ics: events.xml
+	${XSLTPROC} ${XSLTPROCOPTS} -o ${.TARGET} \
+		${WEB_PREFIX}/share/sgml/events2ics.xsl ${.CURDIR}/events.xml
+
 lint:
 	${XMLLINT} --valid -o /dev/null ${.CURDIR}/events.xml
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-doc/attachments/20050817/c0b99b68/attachment.sig>


More information about the freebsd-doc mailing list