From 558cde37c66b29807c8cb536f0a2236a8acad49e Mon Sep 17 00:00:00 2001 From: Soispha Date: Fri, 28 Apr 2023 16:12:08 +0200 Subject: Refactor(hm/conf/firefox): For a cleaner default.nix --- .../config/firefox/functions/bookmarks/default.nix | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 home-manager/config/firefox/functions/bookmarks/default.nix (limited to 'home-manager/config/firefox/functions/bookmarks') diff --git a/home-manager/config/firefox/functions/bookmarks/default.nix b/home-manager/config/firefox/functions/bookmarks/default.nix new file mode 100644 index 00000000..d1d89dd2 --- /dev/null +++ b/home-manager/config/firefox/functions/bookmarks/default.nix @@ -0,0 +1,49 @@ +{ + lib, + pkgs, +}: bookmarks: let + indent = level: + lib.concatStringsSep "" (map (lib.const " ") (lib.range 1 level)); + + bookmarkToHTML = indentLevel: bookmark: '' + ${indent indentLevel}
${lib.escapeXML bookmark.name}''; + + directoryToHTML = indentLevel: directory: '' + ${indent indentLevel}
${ + if directory.toolbar + then ''

Bookmarks Toolbar'' + else "

${lib.escapeXML directory.name}" + }

+ ${indent indentLevel}

+ ${allItemsToHTML (indentLevel + 1) directory.bookmarks} + ${indent indentLevel}

''; + + itemToHTMLOrRecurse = indentLevel: item: + if item ? "url" + then bookmarkToHTML indentLevel item + else directoryToHTML indentLevel item; + + allItemsToHTML = indentLevel: bookmarks: + lib.concatStringsSep "\n" + (map (itemToHTMLOrRecurse indentLevel) bookmarks); + + bookmarkEntries = allItemsToHTML 1 bookmarks; +in + pkgs.writeText "firefox-bookmarks.html" '' + + + + Bookmarks +

Bookmarks Menu

+ +

+

Bookmarks Toolbar

+

+ ${bookmarkEntries} +

+

+ '' -- cgit 1.4.1