OCS support, close #101
continuous-integration/drone/push Build is passing Details

This commit is contained in:
~lucidiot 2022-05-25 18:04:02 +02:00 committed by Lucidiot
parent a1d76308b5
commit fda5950f97
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
5 changed files with 151 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
feeds
feeds.opml
feeds.ocs
feeds.cdf
index.html
*~

View File

@ -8,6 +8,7 @@ xsltproc "$DIR/xslt/itsb.xsl" "$DIR/itsb.xml" > "$tmpfile"
xsltproc "$DIR/xslt/feedgen.xsl" "$tmpfile" | DIR="$DIR" bash -s -- "$@"
xsltproc "$DIR/xslt/opml.xsl" "$tmpfile" > "$DIR/feeds.opml"
xsltproc "$DIR/xslt/ocs.xsl" "$tmpfile" > "$DIR/feeds.ocs"
xsltproc "$DIR/xslt/html.xsl" "$tmpfile" > "$DIR/index.html"
"$DIR/bin/cdfmerge" < "$tmpfile"

BIN
img/ocs.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

View File

@ -16,6 +16,7 @@
<p>
you can get all the feeds at once:
<a href="./feeds.opml" target="_blank"><img src="img/opml.gif" alt="OPML" /></a>
<a href="./feeds.ocs" target="_blank"><img src="img/ocs.gif" alt="OCS" /></a>
<a href="./feeds.cdf" target="_blank"><img src="img/cdf.gif" alt="CDF" /></a>
</p>
]]>

148
xslt/ocs.xsl Normal file
View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:itsb="http://tilde.town/~lucidiot/itsb/itsb.xsd"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ocs="http://InternetAlchemy.org/ocs/directory#"
>
<xsl:output method="xml" indent="yes"/>
<xsl:param name="itsbRootUrl" select="'https://tilde.town/~lucidiot/itsb/'" />
<xsl:template match="/">
<rdf:RDF>
<xsl:apply-templates select=".//itsb:source" />
</rdf:RDF>
</xsl:template>
<xsl:template match="itsb:source">
<rdf:description about="{./itsb:url/text()}">
<xsl:apply-templates select="itsb:name | itsb:description | itsb:type | itsb:region | itsb:license | itsb:feed" />
</rdf:description>
</xsl:template>
<xsl:template match="itsb:name">
<dc:title>
<xsl:value-of select="text()" />
</dc:title>
</xsl:template>
<xsl:template match="itsb:description">
<dc:description>
<xsl:value-of select="text()" />
</dc:description>
</xsl:template>
<xsl:template match="itsb:type">
<dc:subject>
<xsl:value-of select="text()" />
</dc:subject>
</xsl:template>
<xsl:template match="itsb:region">
<dc:coverage>
<xsl:value-of select="text()" />
</dc:coverage>
</xsl:template>
<xsl:template match="itsb:license">
<dc:rights>
<xsl:value-of select="text()" />
</dc:rights>
</xsl:template>
<xsl:template match="itsb:feed">
<rdf:description>
<xsl:choose>
<xsl:when test="itsb:link">
<xsl:attribute name="about">
<xsl:value-of select="itsb:link/text()" />
</xsl:attribute>
<dc:publisher>
<xsl:value-of select="ancestor::itsb:source/itsb:name/text()" />
</dc:publisher>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="about">
<xsl:value-of select="$itsbRootUrl" />
<xsl:text>feeds/</xsl:text>
<xsl:value-of select="itsb:output/text()" />
</xsl:attribute>
<dc:publisher>International Transport Safety Bureau</dc:publisher>
<ocs:updatePeriod>daily</ocs:updatePeriod>
<ocs:updateFrequency>1</ocs:updateFrequency>
<ocs:updateBase>1970-01-01T14:00</ocs:updateBase>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="@type">
<dc:subject>
<xsl:value-of select="@type" />
</dc:subject>
</xsl:if>
<!-- TODO: Add dc:language - might require updating itsb.xsd to require ISO language codes -->
<ocs:format>
<xsl:choose>
<xsl:when test="@format = 'atom'">
<xsl:text>http://www.w3.org/2005/Atom</xsl:text>
</xsl:when>
<xsl:when test="@format = 'cdf'">
<xsl:text>https://msdn.microsoft.com/workshop/standards/cdf/</xsl:text>
</xsl:when>
<xsl:when test="@format = 'echo'">
<xsl:text>http://purl.org/echo/</xsl:text>
</xsl:when>
<xsl:when test="@format = 'json'">
<xsl:text>https://www.jsonfeed.org/version/1.1/</xsl:text>
</xsl:when>
<xsl:when test="@format = 'rdf'">
<xsl:text>https://web.resource.org/rss/1.0/spec</xsl:text>
</xsl:when>
<xsl:when test="@format = 'rss'">
<xsl:text>https://www.rssboard.org/rss-2-0-1</xsl:text>
</xsl:when>
<xsl:when test="@format = 'rss3'">
<xsl:text>http://www.aaronsw.com/2002/rss30</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
<xsl:text>Unsupported feed format: </xsl:text>
<xsl:value-of select="@format" />
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</ocs:format>
<ocs:contentType>
<xsl:choose>
<xsl:when test="@format = 'atom'">
<xsl:text>application/atom+xml</xsl:text>
</xsl:when>
<xsl:when test="@format = 'cdf' or @format = 'echo'">
<xsl:text>application/xml</xsl:text>
</xsl:when>
<xsl:when test="@format = 'json'">
<xsl:text>application/json</xsl:text>
</xsl:when>
<xsl:when test="@format = 'rdf'">
<xsl:text>application/rdf+xml</xsl:text>
</xsl:when>
<xsl:when test="@format = 'rss'">
<xsl:text>application/rss+xml</xsl:text>
</xsl:when>
<xsl:when test="@format = 'rss3'">
<xsl:text>text/plain</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
<xsl:text>Unsupported feed format: </xsl:text>
<xsl:value-of select="@format" />
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</ocs:contentType>
</rdf:description>
</xsl:template>
</xsl:stylesheet>