c3d2-web/xsl/gemini.xsl

404 lines
12 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<stylesheet version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:crypto="http://exslt.org/crypto">
<output method="text" encoding="utf-8"/>
<strip-space elements="page item image event div p ul ol li blockquote"/>
<include href="date.xsl"/>
<template match="/page">
<variable name="title">
<choose>
<when test="/page/portal">
C3D2.de
</when>
<when test="/page/@pagetitle">
<value-of select="normalize-space(/page/@pagetitle)"/>
</when>
<when test="/page/@title">
<value-of select="normalize-space(/page/@title)"/>
</when>
<when test="/page/calendar-summary">
<call-template name="calendar-title"/>
</when>
<otherwise>
<comment><text> missing title </text></comment>
</otherwise>
</choose>
</variable>
<call-template name="body">
<with-param name="title" select="normalize-space($title)" />
</call-template>
</template>
<template match="/item">
<variable name="title">
<value-of select="/item/@title"/>
</variable>
<call-template name="body">
<with-param name="title" select="$title" />
</call-template>
</template>
<template name="body">
<param name="title" />
<text># </text><value-of select="$title"/><text>&#10;</text>
<text>&lt;&lt;&lt;/&gt;&gt; Chaos Computer Club Dresden | c3d2&#10;&#10;</text>
<if test="/page/portal">
<text>## Navigation&#10;&#10;</text>
<for-each select="document('../content/navigation.xml')/navigation/group">
<for-each select="file">
<text>=&gt; </text>
<value-of select="concat($baseurl, ., '.gmi')"/>
<text> </text>
<choose>
<when test="string-length(@title) = 0">
<value-of select="document(concat('../content/pages/', ., '.xml'))/page/@title"/>
</when>
<otherwise>
<value-of select="@title"/>
</otherwise>
</choose>
<text>&#10;</text>
</for-each>
</for-each>
<text>&#10;</text>
</if>
<apply-templates/>
<text>&#10;&#10;=> </text>
<value-of select="$baseurl"/>
<text>index.gmi Start&#10;</text>
</template>
<!-- news -->
<template match="/page/news">
<for-each select="newsfile">
<sort select="date:seconds(document(concat('../', .))/item/@date)" data-type="number" order="descending" />
<variable name="news" select="document(concat('../', .))"/>
<if test="position() &lt;= 10 and
starts-with(
date:difference(
date:date-time(),
concat($news/item/@date, '+02:00')
),
'-'
)">
<variable name="newsfile"><value-of select="."/></variable>
<variable name="itemposition" select="position()"/>
<for-each select="$news/item">
<text>## </text>
<value-of select="@title"/>
<text>&#10;</text>
<call-template name="get-datestring">
<with-param name="date" select="@date"/>
</call-template>
<text> von </text>
<value-of select="@author"/>
<text>&#10;</text>
<text>=> </text>
<value-of select="substring-before(substring-after($newsfile, 'content/'), '.xml')"/>
<text>.gmi News lesen&#10;</text>
</for-each>
</if>
</for-each>
<text>&#10;&#10;</text>
<text>=> news-atom.xml ATOM&#10;</text>
<text>=> news-rss.xml RSS&#10;</text>
<text>=> news-archiv.gmi Archiv&#10;</text>
</template>
<template match="news-list">
<variable name="prefix" select="@prefix"/>
<variable name="details" select="@details"/>
<for-each select="document('../news.xml')/page/news/newsfile">
<sort select="date:seconds(document(concat('../', .))/item/@date)" data-type="number" order="descending" />
<variable name="newsfile" select="."/>
<variable name="news" select="document(concat('../', $newsfile))"/>
<for-each select="$news/item">
<if test="((string-length($prefix) = 0) or
starts-with($newsfile, concat('content/news/', $prefix))) and
(($details != 'resources-only') or
(count(resource) &gt; 0)) and
starts-with(
date:difference(
date:date-time(),
concat($news/item/@date, '+02:00')
),
'-'
)">
<text>## </text>
<value-of select="@title"/>
<text>&#10;</text>
<call-template name="get-datestring">
<with-param name="date" select="@date"/>
</call-template>
<text> von </text>
<value-of select="@author"/>
<text>&#10;</text>
<text>=> </text>
<value-of select="substring-before(substring-after($newsfile, 'content/'), '.xml')"/>
<text>.gmi News lesen&#10;</text>
</if>
</for-each>
</for-each>
</template>
<!-- portal -->
<template match="/page/portal">
<text>## Kalender&#10;</text>
<call-template name="calendar-events">
<with-param name="limit" select="10"/>
</call-template>
<text>## Changelog&#10;</text>
<apply-templates/>
</template>
<template name="calendar-events">
<param name="limit" select="5"/>
<for-each select="document('../calendar-summary.xml')/page/calendar-summary/event[date:seconds(end) &gt;= date:seconds(date:date())]">
<sort select="date:seconds(start)" data-type="number" order="ascending" />
<if test="position() &lt;= $limit">
<choose>
<when test="string-length(link) &gt; 0">
<text>=> </text>
<call-template name="make-href">
<with-param name="href" select="link"/>
</call-template>
</when>
<otherwise>
<text>*</text>
</otherwise>
</choose>
<text> </text>
<call-template name="datespan-to-human">
<with-param name="start" select="start"/>
<with-param name="end" select="end"/>
</call-template>
<text>: </text>
<value-of select="title"/>
<text>&#10;</text>
</if>
</for-each>
</template>
<template match="/page/portal/item">
<text>=> </text>
<value-of select="link"/>
<text> </text>
<if test="content-text">
<call-template name="normalize-paragraph">
<with-param name="text" select="normalize-space(content-text)"/>
</call-template>
<text> (</text>
</if>
<call-template name="normalize-paragraph">
<with-param name="text" select="normalize-space(header)"/>
</call-template>
<text> </text>
<call-template name="normalize-paragraph">
<with-param name="text" select="normalize-space(footer)"/>
</call-template>
<if test="content-text">
<text>)</text>
</if>
<text>&#10;</text>
</template>
<!-- content templates -->
<template match="*[name() = 'resource' or name() = 'alternative']">
<variable name="url">
<call-template name="make-href">
<with-param name="href" select="@url"/>
</call-template>
</variable>
<text>=> </text>
<value-of select="$url"/>
<text> </text>
<value-of select="@type"/>
<text> (</text>
<call-template name="format-filesize">
<with-param name="value" select="@size"/>
</call-template>
<text>)&#10;</text>
</template>
<template match="event/start">
<text>* Beginn: </text>
<call-template name="get-datestring">
<with-param name="date" select="."/>
</call-template>
<text>&#10;</text>
</template>
<template match="event/end">
<text>* Ende: </text>
<call-template name="get-datestring">
<with-param name="date" select="."/>
</call-template>
<text>&#10;</text>
</template>
<template match="event/location">
<text>* Ort: </text>
<call-template name="normalize-paragraph">
<with-param name="text" select="normalize-space(.)"/>
</call-template>
<text>&#10;</text>
</template>
<template match="image"/>
<template match="ol">
<apply-templates/>
<text>&#10;</text>
</template>
<template match="ul">
<apply-templates/>
<text>&#10;</text>
</template>
<template match="li">
<text>* </text>
<call-template name="normalize-paragraph">
<with-param name="text" select="normalize-space(.)"/>
</call-template>
<text>&#10;</text>
</template>
<template match="p">
<if test="@title">
<text>## </text>
<value-of select="@title"/>
<text>&#10;</text>
</if>
<call-template name="normalize-paragraph">
<with-param name="text" select="normalize-space(.)"/>
</call-template>
<text>&#10;</text>
<call-template name="link-list"/>
<text>&#10;</text>
</template>
<template match="blockquote">
<text>```&#10;</text>
<apply-templates/>
<text>```&#10;</text>
</template>
<template name="normalize-paragraph">
<param name="text"/>
<choose>
<when test="contains($text, '&#13;')">
<value-of select="substring-before($text, '&#13;')"/>
<call-template name="normalize-paragraph">
<with-param name="text" select="substring-after($text, '&#13;')"/>
</call-template>
</when>
<otherwise>
<value-of select="$text"/>
</otherwise>
</choose>
</template>
<template name="link-list">
<for-each select=".//link">
<text>=> </text>
<value-of select="@href"/>
<text> </text>
<choose>
<when test="image/@title">
<call-template name="normalize-paragraph">
<with-param name="text" select="normalize-space(image/@title)"/>
</call-template>
</when>
<otherwise>
<call-template name="normalize-paragraph">
<with-param name="text" select="normalize-space(.)"/>
</call-template>
</otherwise>
</choose>
<text>&#10;</text>
</for-each>
</template>
<template match="xhtml:*">
</template>
<!-- helpers -->
<template name="make-href">
<param name="href"/>
<choose>
<when test="$href and not(contains($href, ':')) and substring($href, string-length($href) - 4) = '.html'">
<value-of select="concat($baseurl, substring-before($href, '.html'), '.gmi')"/>
</when>
<when test="$href and not(contains($href, ':'))">
<value-of select="concat($baseurl, $href)"/>
</when>
<when test="$href">
<value-of select="$href"/>
</when>
<otherwise>
<value-of select="."/>
</otherwise>
</choose>
</template>
<template name="format-filesize">
<param name="value"/>
<choose>
<when test="$value &gt; 1024 * 1024 * 1024">
<value-of select="format-number($value div (1024 * 1024 * 1024), '0.0')"/>
<text> GiB</text>
</when>
<when test="$value &gt; 1024 * 1024">
<value-of select="format-number($value div (1024 * 1024), '0.0')"/>
<text> MiB</text>
</when>
<when test="$value &gt; 1024">
<value-of select="format-number($value div (1024), '0.0')"/>
<text> KiB</text>
</when>
<otherwise>
<value-of select="$value"/>
<text> Byte</text>
</otherwise>
</choose>
</template>
</stylesheet>