Last active
September 4, 2019 06:54
-
-
Save 4z3/5c8507b84efaba648a6d to your computer and use it in GitHub Desktop.
nix-haddock-index.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
set -euf | |
# TODO NIX_GHC=$(type -P ghc) NIX_GHC_DOCDIR=$(dirname $(dirname $(type -P ghc)))/share/doc/ghc/html | |
# if unset: this is for e.g. emse-hdsb | |
main() { | |
pkg=$(dirname $(dirname $NIX_GHC)) | |
hash=$(echo $pkg | sed -n 's|^/nix/store/\([a-z0-9]\+\).*|\1|p') | |
title="Haddock index for $pkg" | |
header=$(printf 'Haddock index for <a href="%s">%s</a>\n' $pkg $pkg) | |
suffix=${hash:+-$hash} | |
index_file=/tmp/haddock$suffix-index.html | |
svg_file=/tmp/haddock$suffix.svg | |
#if ! test -e $index_file; then | |
eval "$( | |
echo 'gen_index() {' | |
echo ' html_head' | |
ghc-pkg dump | sed -n ' | |
s/^---$/ reset/p | |
s/^\(name\|version\):\s*\([-A-Za-z0-9_.]\+\)$/ \1=\2/p | |
s/^haddock-html:\s*\([-A-Za-z0-9_./]\+\)$/ haddock_html \1/p | |
' | |
echo ' html_foot' | |
echo '}' | |
)" | |
gen_index > $index_file | |
#fi | |
ghc-pkg dot | tred | dot -Tsvg | sed ' | |
s/<svg width="[0-9]\+pt" height="[0-9]\+pt"/<svg width="3600px" height="100%"/ | |
' > $svg_file | |
echo $index_file | |
} | |
reset() { | |
unset name version | |
} | |
haddock_html() { | |
printf '<li>' | |
printf '<a href="%s/index.html">%s</a>' "$1" "$name-$version" | |
printf '</li>\n' | |
} | |
html_head() { | |
printf '<!doctype html>\n' | |
printf '<title>%s</title>\n' "$title" | |
printf '<link href="%s" rel="stylesheet" type="text/css">\n' \ | |
"$NIX_GHC_DOCDIR/libraries/ocean.css" | |
printf '<h1>%s</h1>\n' "$header" | |
printf '<ul>\n' | |
} | |
html_foot() { | |
printf '</ul>\n' | |
printf '<a href="%s">graph</a>\n' "$svg_file" | |
#printf '<object preserveAspectRatio="xMinYMin meet" viewBox="0 0 1366 0" data="%s" type="image/svg+xml">' "$svg_file" | |
## TODO printf '<img src="yourfallback.jpg" />' | |
#printf '</object>\n' | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment