From b1741a18e1fc92cc0ea682f73d0299f507cab30c Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 13 Jan 2023 04:13:44 +0000 Subject: [PATCH] feeds: include "title" in the output OPML -- when it exists --- hosts/common/feeds.nix | 2 ++ modules/feeds.nix | 4 ++++ modules/lib/feeds.nix | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hosts/common/feeds.nix b/hosts/common/feeds.nix index 5823dce7..f957e295 100644 --- a/hosts/common/feeds.nix +++ b/hosts/common/feeds.nix @@ -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 = [ diff --git a/modules/feeds.nix b/modules/feeds.nix index 9eaaae7e..f7d46ff8 100644 --- a/modules/feeds.nix +++ b/modules/feeds.nix @@ -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 = '' diff --git a/modules/lib/feeds.nix b/modules/lib/feeds.nix index e2baa7e9..6d9c1f61 100644 --- a/modules/lib/feeds.nix +++ b/modules/lib/feeds.nix @@ -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: ''''; + 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.