firefox: add support for nested bookmarks
Change type of `firefox.profile.<name>.bookmarks` to allow for nested bookmarks with user defined order.
This commit is contained in:
parent
4c5106ed0f
commit
64c745fe1c
|
@ -42,7 +42,7 @@ let
|
||||||
|
|
||||||
mkUserJs = prefs: extraPrefs: bookmarks:
|
mkUserJs = prefs: extraPrefs: bookmarks:
|
||||||
let
|
let
|
||||||
prefs' = lib.optionalAttrs ({ } != bookmarks) {
|
prefs' = lib.optionalAttrs ([ ] != bookmarks) {
|
||||||
"browser.bookmarks.file" = toString (firefoxBookmarksFile bookmarks);
|
"browser.bookmarks.file" = toString (firefoxBookmarksFile bookmarks);
|
||||||
"browser.places.importBookmarksHTML" = true;
|
"browser.places.importBookmarksHTML" = true;
|
||||||
} // prefs;
|
} // prefs;
|
||||||
|
@ -58,13 +58,36 @@ let
|
||||||
|
|
||||||
firefoxBookmarksFile = bookmarks:
|
firefoxBookmarksFile = bookmarks:
|
||||||
let
|
let
|
||||||
mapper = _: entry: ''
|
indent = level:
|
||||||
<DT><A HREF="${escapeXML entry.url}" ADD_DATE="0" LAST_MODIFIED="0"${
|
lib.concatStringsSep "" (map (lib.const " ") (lib.range 1 level));
|
||||||
lib.optionalString (entry.keyword != null)
|
|
||||||
" SHORTCUTURL=\"${escapeXML entry.keyword}\""
|
bookmarkToHTML = indentLevel: bookmark:
|
||||||
}>${escapeXML entry.name}</A>
|
''
|
||||||
'';
|
${indent indentLevel}<DT><A HREF="${
|
||||||
bookmarksEntries = lib.attrsets.mapAttrsToList mapper bookmarks;
|
escapeXML bookmark.url
|
||||||
|
}" ADD_DATE="0" LAST_MODIFIED="0"${
|
||||||
|
lib.optionalString (bookmark.keyword != null)
|
||||||
|
" SHORTCUTURL=\"${escapeXML bookmark.keyword}\""
|
||||||
|
}>${escapeXML bookmark.name}</A>'';
|
||||||
|
|
||||||
|
directoryToHTML = indentLevel: directory: ''
|
||||||
|
${indent indentLevel}<DT><H3>${escapeXML directory.name}</H3>
|
||||||
|
${indent indentLevel}<DL><p>
|
||||||
|
${allItemsToHTML (indentLevel + 1) directory.bookmarks}
|
||||||
|
${indent indentLevel}</p></DL>'';
|
||||||
|
|
||||||
|
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
|
||||||
|
(if isAttrs bookmarks then lib.attrValues bookmarks else bookmarks);
|
||||||
in pkgs.writeText "firefox-bookmarks.html" ''
|
in pkgs.writeText "firefox-bookmarks.html" ''
|
||||||
<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
<!DOCTYPE NETSCAPE-Bookmark-file-1>
|
||||||
<!-- This is an automatically generated file.
|
<!-- This is an automatically generated file.
|
||||||
|
@ -74,7 +97,7 @@ let
|
||||||
<TITLE>Bookmarks</TITLE>
|
<TITLE>Bookmarks</TITLE>
|
||||||
<H1>Bookmarks Menu</H1>
|
<H1>Bookmarks Menu</H1>
|
||||||
<DL><p>
|
<DL><p>
|
||||||
${concatStrings bookmarksEntries}
|
${bookmarkEntries}
|
||||||
</p></DL>
|
</p></DL>
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -226,37 +249,78 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
bookmarks = mkOption {
|
bookmarks = mkOption {
|
||||||
type = types.attrsOf (types.submodule ({ config, name, ... }: {
|
type = let
|
||||||
options = {
|
bookmarkSubmodule = types.submodule ({ config, name, ... }: {
|
||||||
name = mkOption {
|
options = {
|
||||||
type = types.str;
|
name = mkOption {
|
||||||
default = name;
|
type = types.str;
|
||||||
description = "Bookmark name.";
|
default = name;
|
||||||
};
|
description = "Bookmark name.";
|
||||||
|
};
|
||||||
|
|
||||||
keyword = mkOption {
|
keyword = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Bookmark search keyword.";
|
description = "Bookmark search keyword.";
|
||||||
};
|
};
|
||||||
|
|
||||||
url = mkOption {
|
url = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "Bookmark url, use %s for search terms.";
|
description = "Bookmark url, use %s for search terms.";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
}) // {
|
||||||
|
description = "bookmark submodule";
|
||||||
};
|
};
|
||||||
}));
|
|
||||||
default = { };
|
bookmarkType = types.addCheck bookmarkSubmodule (x: x ? "url");
|
||||||
|
|
||||||
|
directoryType = types.submodule ({ config, name, ... }: {
|
||||||
|
options = {
|
||||||
|
name = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = name;
|
||||||
|
description = "Directory name.";
|
||||||
|
};
|
||||||
|
|
||||||
|
bookmarks = mkOption {
|
||||||
|
type = types.listOf bookmarkType;
|
||||||
|
default = [ ];
|
||||||
|
description = "Bookmarks within directory.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}) // {
|
||||||
|
description = "directory submodule";
|
||||||
|
};
|
||||||
|
in with types;
|
||||||
|
either (attrsOf bookmarkType)
|
||||||
|
(listOf (either bookmarkType directoryType));
|
||||||
|
default = [ ];
|
||||||
example = literalExpression ''
|
example = literalExpression ''
|
||||||
{
|
[
|
||||||
wikipedia = {
|
{
|
||||||
|
name = "wikipedia";
|
||||||
keyword = "wiki";
|
keyword = "wiki";
|
||||||
url = "https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go";
|
url = "https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go";
|
||||||
};
|
}
|
||||||
"kernel.org" = {
|
{
|
||||||
|
name = "kernel.org";
|
||||||
url = "https://www.kernel.org";
|
url = "https://www.kernel.org";
|
||||||
};
|
}
|
||||||
}
|
{
|
||||||
|
name = "Nix sites";
|
||||||
|
bookmarks = [
|
||||||
|
{
|
||||||
|
name = "homepage";
|
||||||
|
url = "https://nixos.org/";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "wiki";
|
||||||
|
url = "https://nixos.wiki/";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
]
|
||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
Preloaded bookmarks. Note, this may silently overwrite any
|
Preloaded bookmarks. Note, this may silently overwrite any
|
||||||
|
|
|
@ -6,7 +6,11 @@
|
||||||
<TITLE>Bookmarks</TITLE>
|
<TITLE>Bookmarks</TITLE>
|
||||||
<H1>Bookmarks Menu</H1>
|
<H1>Bookmarks Menu</H1>
|
||||||
<DL><p>
|
<DL><p>
|
||||||
<DT><A HREF="https://www.kernel.org" ADD_DATE="0" LAST_MODIFIED="0">kernel.org</A>
|
<DT><A HREF="https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go" ADD_DATE="0" LAST_MODIFIED="0" SHORTCUTURL="wiki">wikipedia</A>
|
||||||
<DT><A HREF="https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go" ADD_DATE="0" LAST_MODIFIED="0" SHORTCUTURL="wiki">wikipedia</A>
|
<DT><A HREF="https://www.kernel.org" ADD_DATE="0" LAST_MODIFIED="0">kernel.org</A>
|
||||||
|
<DT><H3>Nix sites</H3>
|
||||||
|
<DL><p>
|
||||||
|
<DT><A HREF="https://nixos.org/" ADD_DATE="0" LAST_MODIFIED="0">homepage</A>
|
||||||
|
<DT><A HREF="https://nixos.wiki/" ADD_DATE="0" LAST_MODIFIED="0">wiki</A>
|
||||||
|
</p></DL>
|
||||||
</p></DL>
|
</p></DL>
|
||||||
|
|
|
@ -15,13 +15,30 @@ lib.mkIf config.test.enableBig {
|
||||||
profiles.bookmarks = {
|
profiles.bookmarks = {
|
||||||
id = 2;
|
id = 2;
|
||||||
settings = { "general.smoothScroll" = false; };
|
settings = { "general.smoothScroll" = false; };
|
||||||
bookmarks = {
|
bookmarks = [
|
||||||
wikipedia = {
|
{
|
||||||
|
name = "wikipedia";
|
||||||
keyword = "wiki";
|
keyword = "wiki";
|
||||||
url = "https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go";
|
url = "https://en.wikipedia.org/wiki/Special:Search?search=%s&go=Go";
|
||||||
};
|
}
|
||||||
"kernel.org" = { url = "https://www.kernel.org"; };
|
{
|
||||||
};
|
name = "kernel.org";
|
||||||
|
url = "https://www.kernel.org";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "Nix sites";
|
||||||
|
bookmarks = [
|
||||||
|
{
|
||||||
|
name = "homepage";
|
||||||
|
url = "https://nixos.org/";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "wiki";
|
||||||
|
url = "https://nixos.wiki/";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue