mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-10-20 20:19:39 +03:00
a8d4cf149c
Move the manpage-to-URL mapping to `doc/manpage-urls.json` so that we can reuse that file elsewhere, and generate the `link-manpages.lua` filter from that file. Also modify the Pandoc filter so that it doesn't wrap manpages that are already inside a link. Keeping a Lua filter is essential for speed: a Python filter would increase the runtime `md-to-db.sh` from ~20s to ~30s (but Python is not to blame; marshalling Pandoc types to and from JSON is a costly operation). Parsing in Lua seems tedious, so I went with the Nix way.
29 lines
855 B
Nix
29 lines
855 B
Nix
{ pkgs ? import ../../.. {} }:
|
|
let
|
|
inherit (pkgs) lib;
|
|
manpageURLs = builtins.fromJSON (builtins.readFile (pkgs.path + "/doc/manpage-urls.json"));
|
|
in pkgs.writeText "link-manpages.lua" ''
|
|
--[[
|
|
Adds links to known man pages that aren't already in a link.
|
|
]]
|
|
|
|
local manpage_urls = {
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList (man: url:
|
|
" [${builtins.toJSON man}] = ${builtins.toJSON url},") manpageURLs)}
|
|
}
|
|
|
|
traverse = 'topdown'
|
|
|
|
-- Returning false as the second value aborts processing of child elements.
|
|
function Link(elem)
|
|
return elem, false
|
|
end
|
|
|
|
function Code(elem)
|
|
local is_man_role = elem.classes:includes('interpreted-text') and elem.attributes['role'] == 'manpage'
|
|
if is_man_role and manpage_urls[elem.text] ~= nil then
|
|
return pandoc.Link(elem, manpage_urls[elem.text]), false
|
|
end
|
|
end
|
|
''
|