itsb/jq/convert/rss2rss3.jq

36 lines
1.1 KiB
Plaintext

# 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")