CDF support, closes #54

This commit is contained in:
Lucidiot 2021-03-18 21:47:19 +01:00
parent 6d97869d19
commit 0a401bd6c8
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
5 changed files with 100 additions and 3 deletions

BIN
img/cdf.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

View File

@ -311,6 +311,7 @@
<xs:enumeration value="atom" />
<xs:enumeration value="rdf" />
<xs:enumeration value="json" />
<xs:enumeration value="cdf" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>

42
jq/convert/rss2cdf.jq Normal file
View File

@ -0,0 +1,42 @@
# RSS->CDF converter
# Expects xmltodict JSON output as input, outputs a CDF feed
# Supports MediaRSS.
def ensure_string: if type == "array" then .[0] else . end | if type == "object" then .["#text"] else . end;
def ensure_array: (. // []) | if type == "array" then . else [.] end;
def parse_date: ensure_string | strptime("%a, %d %b %Y %T %Z") | mktime | todateiso8601[:16];
{"CHANNEL": (
.rss.channel | . as $channel | {
"A": {
"@HREF": (.link | ensure_string)
},
"ABSTRACT": (.description | ensure_string),
"TITLE": (.title | ensure_string),
"ITEM": [
.item | ensure_array[] | . as $item | {
"TITLE": .title,
"USAGE": {"@VALUE": "Channel"},
"@SHOW": "Channel"
}
| if $item.description then .ABSTRACT = ($item.description | ensure_string) else . end
| if $item.link then
.A = {"@HREF": ($item.link | ensure_string)}
elif $item.enclosure then
.A = {"@HREF": $item.enclosure["@url"]}
else . end
| if $item.pubDate then .["@LASTMOD"] = ($item.pubDate | parse_date) else . end
| if $item["media:thumbnail"] then .LOGO = {
"@HREF": $item["media:thumbnail"]["@url"],
"@STYLE": "IMAGE"
} else . end
]
}
| if $channel.lastBuildDate // $channel.pubDate then .["@LASTMOD"] = (
$channel.lastBuildDate // $channel.pubDate | parse_date
) else . end
| if $channel.image then .LOGO = {
"@HREF": $channel.image.url,
"@STYLE": "IMAGE"
} else . end
)}

View File

@ -78,10 +78,12 @@
</feed>
<xsl:call-template name="jsonfeed" />
<xsl:call-template name="cdf" />
</xsl:when>
<xsl:when test="@format = 'rss'">
<xsl:call-template name="jsonfeed" />
<xsl:call-template name="cdf" />
</xsl:when>
</xsl:choose>
</xsl:template>
@ -140,4 +142,56 @@
</output>
</feed>
</xsl:template>
<xsl:template name="cdf">
<feed format="cdf">
<xsl:if test="@lang">
<xsl:attribute name="lang">
<xsl:value-of select="@lang" />
</xsl:attribute>
</xsl:if>
<xsl:if test="@type">
<xsl:attribute name="type">
<xsl:value-of select="@type" />
</xsl:attribute>
</xsl:if>
<xsl:attribute name="id">
<xsl:value-of select="@id" />
<xsl:text>-cdf</xsl:text>
</xsl:attribute>
<xsl:choose>
<xsl:when test="itsb:output">
<shell>
<xsl:text>cat $DIR/feeds/</xsl:text>
<xsl:choose>
<xsl:when test="@format = 'atom'">
<xsl:text>_rss/</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>.xml</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="itsb:output/text()" />
</xsl:otherwise>
</xsl:choose>
</shell>
</xsl:when>
<xsl:otherwise>
<curl>
<url>
<xsl:value-of select="itsb:link/text()" />
</url>
</curl>
</xsl:otherwise>
</xsl:choose>
<xml2json />
<jq path="convert/rss2cdf.jq" />
<output>
<xsl:text>_cdf/</xsl:text>
<xsl:value-of select="@id" />
<xsl:text>.cdf</xsl:text>
</output>
</feed>
</xsl:template>
</xsl:stylesheet>

View File

@ -89,9 +89,9 @@
<xsl:when test="@format = 'rdf'">
<xsl:text>RSS1</xsl:text>
</xsl:when>
<xsl:when test="@format = 'json'">
<xsl:text>JSON</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="translate(@format, $lower, $upper)" />
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="xmlUrl">