feeds: include "title" in the output OPML -- when it exists

This commit is contained in:
colin 2023-01-13 04:13:44 +00:00
parent a829a8e027
commit b1741a18e1
3 changed files with 23 additions and 1 deletions

View File

@ -41,6 +41,8 @@ let
);
} // lib.optionalAttrs (raw.is_podcast or false) {
format = "podcast";
} // lib.optionalAttrs (raw.title or "" != "") {
title = lib.mkDefault raw.title;
};
podcasts = [

View File

@ -16,6 +16,10 @@ let
type = types.enum [ "text" "image" "podcast" ];
default = "text";
};
title = mkOption {
type = types.nullOr types.str;
default = null;
};
url = mkOption {
type = types.str;
description = ''

View File

@ -12,8 +12,24 @@ rec {
# transform a list of feeds into an attrs mapping cat => [ feed0 feed1 ... ]
partitionByCat = feeds: builtins.groupBy (f: f.cat) feeds;
xmlTag = tag: close: attrs:
let
fmt-attrs = builtins.concatStringsSep
" "
(lib.mapAttrsToList (name: value: ''${lib.escapeXML name}="${lib.escapeXML value}"'') attrs);
fmt-close = if close then "/" else "";
in
''<${tag} ${fmt-attrs} ${fmt-close}>'';
# represents a single RSS feed.
opmlTerminal = feed: ''<outline xmlUrl="${feed.url}" type="rss"/>'';
opmlTerminal = feed: xmlTag "outline" true (
{
xmlUrl = feed.url;
type = "rss";
} // lib.optionalAttrs (feed.title != null) {
title = feed.title;
}
);
# a list of RSS feeds.
opmlTerminals = feeds: lib.concatStringsSep "\n" (builtins.map opmlTerminal feeds);
# one node which packages some flat grouping of terminals.