feeds: simplify/abstract the OPML generation

This commit is contained in:
2022-10-14 09:37:40 -07:00
parent b25f270f48
commit 8a1ea79f1f
2 changed files with 39 additions and 45 deletions

View File

@@ -1,4 +1,6 @@
{
{ lib }:
rec {
# TODO: fold this into RSS, with an `audio` category
podcastUrls = [
"https://lexfridman.com/feed/podcast/"
@@ -118,4 +120,29 @@
# CODE
"https://github.com/Kaiteki-Fedi/Kaiteki/commits/master.atom" = tech // infrequent;
};
# return only the URLs which match this category
filterCat = cat: builtins.filter (url: rss."${url}".cat == cat) (builtins.attrNames rss);
# represents a single RSS feed.
opmlTerminal = url: ''<outline xmlUrl="${url}" type="rss"/>'';
# a list of RSS feeds.
opmlTerminals = urls: lib.strings.concatStringsSep "\n" (builtins.map opmlTerminal urls);
# one node which packages some flat grouping of terminals.
opmlGroup = title: urls: ''
<outline text="${title}" title="${title}">
${opmlTerminals urls}
</outline>
'';
# top-level OPML file which could be consumed by something else.
opmlToplevel = bodies:
let
body = lib.strings.concatStringsSep "\n" bodies;
in ''
<?xml version="1.0" encoding="utf-8"?>
<opml version="2.0">
<body>${body}
</body>
</opml>
'';
}

View File

@@ -17,7 +17,7 @@ let
# extract `persist-files` from `extraPackages`
persistfileslist = pkgspec: builtins.concatLists (builtins.map (e: if e ? "persist-files" then e.persist-files else []) pkgspec);
# TODO: dirlist and persistfileslist should be folded
feeds = import ./feeds.nix;
feeds = import ./feeds.nix { inherit lib; };
in
{
options = {
@@ -216,54 +216,21 @@ in
qt-privacy-ask=0
'';
xdg.configFile."gpodderFeeds.opml".text =
let
entries = builtins.toString (builtins.map
(url: "\n " + ''<outline xmlUrl="${url}" type="rss"/>'')
feeds.podcastUrls
);
in ''
<?xml version="1.0" encoding="utf-8"?>
<opml version="2.0">
<body>${entries}
</body>
</opml>
'';
xdg.configFile."gpodderFeeds.opml".text = with feeds;
opmlToplevel [(opmlTerminals podcastUrls)];
# news-flash RSS viewer
xdg.configFile."newsflashFeeds.opml".text =
xdg.configFile."newsflashFeeds.opml".text = with feeds;
let
entries = feeds.rss;
urlsForCat = cat: builtins.filter (rss: entries."${rss}".cat == cat) (builtins.attrNames entries);
outlineEntriesFor = cat: builtins.map (rss: ''
<outline type="rss" xmlUrl="${rss}" />
'') (urlsForCat cat);
outlineFor = cat: let
outlines = outlineEntriesFor cat;
in ''
<outline text="${cat}" title="${cat}">
${builtins.toString outlines}
</outline>
'';
opmlForCat = cat: opmlGroup cat (filterCat cat);
outlines = [
(outlineFor "uncat")
(outlineFor "rat")
(outlineFor "tech")
(outlineFor "pol")
(outlineFor "visual")
(opmlForCat "uncat")
(opmlForCat "rat")
(opmlForCat "tech")
(opmlForCat "pol")
(opmlForCat "visual")
];
in ''
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>NewsFlash OPML export</title>
</head>
<body>
${builtins.toString outlines}
</body>
</opml>
'';
in opmlToplevel outlines;
# gnome feeds RSS viewer
xdg.configFile."org.gabmus.gfeeds.json".text = builtins.toJSON {