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 # TODO: fold this into RSS, with an `audio` category
podcastUrls = [ podcastUrls = [
"https://lexfridman.com/feed/podcast/" "https://lexfridman.com/feed/podcast/"
@@ -118,4 +120,29 @@
# CODE # CODE
"https://github.com/Kaiteki-Fedi/Kaiteki/commits/master.atom" = tech // infrequent; "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` # extract `persist-files` from `extraPackages`
persistfileslist = pkgspec: builtins.concatLists (builtins.map (e: if e ? "persist-files" then e.persist-files else []) pkgspec); persistfileslist = pkgspec: builtins.concatLists (builtins.map (e: if e ? "persist-files" then e.persist-files else []) pkgspec);
# TODO: dirlist and persistfileslist should be folded # TODO: dirlist and persistfileslist should be folded
feeds = import ./feeds.nix; feeds = import ./feeds.nix { inherit lib; };
in in
{ {
options = { options = {
@@ -216,54 +216,21 @@ in
qt-privacy-ask=0 qt-privacy-ask=0
''; '';
xdg.configFile."gpodderFeeds.opml".text = xdg.configFile."gpodderFeeds.opml".text = with feeds;
let opmlToplevel [(opmlTerminals podcastUrls)];
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>
'';
# news-flash RSS viewer # news-flash RSS viewer
xdg.configFile."newsflashFeeds.opml".text = xdg.configFile."newsflashFeeds.opml".text = with feeds;
let let
entries = feeds.rss; opmlForCat = cat: opmlGroup cat (filterCat cat);
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>
'';
outlines = [ outlines = [
(outlineFor "uncat") (opmlForCat "uncat")
(outlineFor "rat") (opmlForCat "rat")
(outlineFor "tech") (opmlForCat "tech")
(outlineFor "pol") (opmlForCat "pol")
(outlineFor "visual") (opmlForCat "visual")
]; ];
in '' in opmlToplevel outlines;
<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>NewsFlash OPML export</title>
</head>
<body>
${builtins.toString outlines}
</body>
</opml>
'';
# gnome feeds RSS viewer # gnome feeds RSS viewer
xdg.configFile."org.gabmus.gfeeds.json".text = builtins.toJSON { xdg.configFile."org.gabmus.gfeeds.json".text = builtins.toJSON {