Add RSS 3.0 support

This commit is contained in:
Lucidiot 2021-04-05 22:59:33 +02:00
parent 45e5be4ef4
commit 6e86eee5fc
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
3 changed files with 44 additions and 1 deletions

BIN
img/rss3.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 935 B

35
jq/convert/rss2rss3.jq Normal file
View File

@ -0,0 +1,35 @@
# RSS 2.0 to RSS 3.0 converter
# Expects xmltodict JSON output, returns an RSS 3.0 feed
def ensure_array: (. // []) | if type == "array" then . else [.] end;
def ensure_string: if type == "array" then .[0] else . end | if type == "object" then .["#text"] else . end;
.rss.channel
| [{
"title": .title,
"link": .link,
"description": .description,
"generator": .generator,
"last-modified": .pubDate,
"language": .language,
"rights": .copyright,
"creator": (.managingEditor // .webMaster),
"errorsto": "lucidiot@brainshit.fr"
}] + [.item | ensure_array[] | {
"title": .title,
"link": .link,
"description": .description,
"creator": .author,
"last-modified": .pubDate,
"guid": .guid,
"uri": (if (.guid|type) == "string" or .guid?["@isPermaLink"] != "false" then .guid else null end)
}]
| map([
map_values(ensure_string)
| to_entries[]
| select(.value | . != null and length)
| "\(.key): \(.value)"
# Ensure there are spaces after all newlines
| gsub("\n"; "\n ")
] | join("\n"))
| join("\n\n")

View File

@ -102,6 +102,10 @@
<xsl:with-param name="format" select="'echo'" />
<xsl:with-param name="extension" select="'xml'" />
</xsl:call-template>
<xsl:call-template name="converter">
<xsl:with-param name="format" select="'rss3'" />
<xsl:with-param name="extension" select="'txt'" />
</xsl:call-template>
</xsl:template>
<xsl:template name="converter">
@ -182,9 +186,13 @@
<xsl:text>.json</xsl:text>
</arg>
</xsl:if>
<xsl:if test="$format = 'rss3'">
<xsl:attribute name="raw-output">true</xsl:attribute>
</xsl:if>
</jq>
<xsl:if test="$format != 'json'">
<xsl:if test="$format != 'json' and $format != 'rss3'">
<json2xml short-empty="true" />
</xsl:if>