dot

packages and services management
Log | Files | Refs | README

commit 5ee09ade210c5b27e5c3cc69f5214a49b66e8e84
parent 904d0f1890cdc7ed093dd1cbc4c626ca8c29fa58
Author: Josuah Demangeonā  ā µ <mail@josuah.net>
Date:   Thu, 16 Mar 2017 19:35:12 +0100

fixing git-index -> www-git

Diffstat:
Dbin/git-index | 219-------------------------------------------------------------------------------
Abin/www-git | 218+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 218 insertions(+), 219 deletions(-)

diff --git a/bin/git-index b/bin/git-index @@ -1,219 +0,0 @@ -# Static Git index generator inspired from git.2f30.org/stagit - - -# 1: path to the parent root -# 2: title of the page - -head() -{ - printf '<!DOCTYPE html> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<title>%s</title> -<link rel="icon" type="image/png" href="../%s/favicon.png" /> -<link rel="stylesheet" type="text/css" href="../%s/git.css" /> -</head> - -<body> -<pre> -<a href="%s/..">&lt;</a> <b>%s</b> - <span style="color: grey;">%s</span> -<a href="%s/files.html">Files</a> | <a href="%s/commits.html">Commits</a>' \ - "$2" "$1" "$1" "$1" "${PWD##*/}" "$(cat .git/description)" "$1" "$1" - - [ -f .gitmodules ] && - printf ' | <a href="file/%s/.gitmodules.html">Submodules</a>' "$1" - [ -f README ] && - printf ' | <a href="file/%s/README.html">README</a>' "$1" - [ -f LICENSE ] && - printf ' | <a href="file/%s/LICENSE.html">LICENSE</a>' "$1" - - printf '</pre>\n<hr>\n' -} - - -foot() -{ - printf '</body> -</html> -' -} - - -# 1: long hash of the commit - -commit() -{ - git show -s --format='<pre> -<b>commit</b> <a href="%H.html">%H</a> -<b>parent</b> <a href="%P.html">%P</a> -<b>author</b> %an &lt;<a href="mailto:%ae">%ae</a>&gt; -<b>date</b> %aD - -%s - -<b>diffstat</b> -' "$1" - - git show --stat --format='' "$1" | sed ' - s|\(+*\)\(-*\)$|<span style="color: green;">\1</span>\2| - s|-*$|<span style="color: red;">&</span>| - ' - - printf '</pre>\n<hr/>\n<pre>' - - git show "$1" --format='' | sed ' - s|&|\&amp;|g - s|<|\&lt;|g - /^diff/ { - s|a/\([^ ]*\)|a/<a href="../file/\1.html">\1</a>| - s|b/\([^ ]*\)|b/<a href="../file/\1.html">\1</a>| - s|.*|<b>&</b>| - } - /^+/ s|.*|<span style="color: green;">&</span>| - /^-/ s|.*|<span style="color: red;">&</span>| - ' - - printf '</pre>\n' -} - - -# 1: target base directory - -commits() -{ - mkdir -p "$1/commit" - - printf '<table>\n<thead>\n<tr>' - printf '<th>%s</th>' 'Date' 'Commit message' 'Author' - printf '</tr>\n</thead>\n<tbody>\n' - - for hash in $(git log --format='%H') - do - { - head '../..' "Files - ${PWD##*/}" - commit "$hash" - foot - } > "$1/commit/$hash.html" - - git log --format="<tr>$( - printf '<td>%s</td>' \ - '%ad' '<a href="commit/%H.html">%s</a>' '%an' - )</tr>" --date='short' "$hash" - done - - printf '\n</tbody>\n</table>\n' -} - - -# 1: path to the file to process. - -file() -{ - printf '<p>%s</p>\n<table>' - printf '<tr>\n<td>\n<pre id="num">\n' - - if grep -qI . "$1" 1>/dev/null - then - seq "$(wc -l < "$1")" | - sed 's|.*|<a id="&" href="#&">&</a>|' - - printf '</pre></td>\n<td id="file"><pre>\n' - - sed 's|&|\&amp;|g; s|<|\&lt;|g' "$1" - else - printf 'binary file' - fi - - printf '</pre></td></tr></table>' -} - - -# 1: target base directory - -files() -{ - mkdir -p "$1/file" - - printf '<table>\n<thead>\n<tr>' - printf '<th>%s</th>' 'Mode' 'Name' 'Size' - printf '</tr>\n</thead>\n<tbody>\n' - - git ls-files | while IFS='' read -r file - do - [ -z "${file##*/*}" ] && mkdir -p "$1/file/${file%/*}" - - root="$(printf %s "$file" | sed 's|[^/]*||g; s|.|../|g').." - - { - head "../$root" "$file - ${PWD##*/}" - file "$file" - foot - } > "$1/file/$file.html" - - printf '<tr>' - - printf '<td>%s</td>' \ - "$(stat -c %A "$file")" \ - "<a href=\"file/$file.html\">$file</a>" \ - "$(wc -l < "$file")L" - printf '</tr>\n' - done - - printf '\n</tbody>\n</table>\n' -} - - -# 1: target base directory - -repo() -{ - { - head '..' "Commits - ${1##*/}" - commits "$1" - foot - } > $1/commits.html - - { - head '..' "Files - ${1##*/}" - files "$1" - foot - } > $1/files.html - - ln -sf files.html "$1/index.html" - - printf '<li>%s <span style="color: grey;">%s</span>' "${PWD##*/}" "$( - grep "${PWD##*/}" "${1%/git/*}/description" | - sed 's/^[^ ]* //' - )" - printf '<span class="nav">' - printf '<a href="git/%s">%s</a>' "${PWD##*/}/files.html" 'files' - printf ' - <a href="git/%s">%s</a>' "${PWD##*/}/commits.html" 'commits' - printf '</span></li>\n' -} - - -# 1: source git directory - -repos() -{ - printf '<ul>\n' - - find "$1" -maxdepth 1 -mindepth 1 -type d | sort | - while IFS='' read -r repo - do - printf '%s\n' "$repo" 1>&2 - - mkdir -p "${repo##*/}" - - ( - pwd="$PWD" - cd "$repo" && repo "$pwd/${repo##*/}" || exit 1 - ) - done - - printf '</ul>\n' -} - - -repos "$@" diff --git a/bin/www-git b/bin/www-git @@ -0,0 +1,218 @@ +# Static Git index generator inspired from git.2f30.org/stagit + + +# 1: path to the parent root +# 2: title of the page + +head() +{ + printf '<!DOCTYPE html> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<title>%s</title> +<link rel="icon" type="image/png" href="../%s/favicon.png" /> +<link rel="stylesheet" type="text/css" href="../%s/git.css" /> +</head> + +<body> +<pre> +<b>%s</b> - <span style="color: grey;">%s</span> +' "$2" "$1" "$1" "${PWD##*/}" "$(cat .git/description)" + + [ -f .gitmodules ] && + printf ' | <a href="file/%s/.gitmodules.html">Submodules</a>' "$1" + [ -f README ] && + printf ' | <a href="file/%s/README.html">README</a>' "$1" + [ -f LICENSE ] && + printf ' | <a href="file/%s/LICENSE.html">LICENSE</a>' "$1" + + printf '</pre>\n<hr>\n' +} + + +foot() +{ + printf '</body> +</html> +' +} + + +# 1: long hash of the commit + +commit() +{ + git show -s --format='<pre> +<b>commit</b> <a href="%H.html">%H</a> +<b>parent</b> <a href="%P.html">%P</a> +<b>author</b> %an &lt;<a href="mailto:%ae">%ae</a>&gt; +<b>date</b> %aD + +%s + +<b>diffstat</b> +' "$1" + + git show --stat --format='' "$1" | sed ' + s|\(+*\)\(-*\)$|<span style="color: green;">\1</span>\2| + s|-*$|<span style="color: red;">&</span>| + ' + + printf '</pre>\n<hr/>\n<pre>' + + git show "$1" --format='' | sed ' + s|&|\&amp;|g + s|<|\&lt;|g + /^diff/ { + s|a/\([^ ]*\)|a/<a href="../file/\1.html">\1</a>| + s|b/\([^ ]*\)|b/<a href="../file/\1.html">\1</a>| + s|.*|<b>&</b>| + } + /^+/ s|.*|<span style="color: green;">&</span>| + /^-/ s|.*|<span style="color: red;">&</span>| + ' + + printf '</pre>\n' +} + + +# 1: target base directory + +commits() +{ + mkdir -p "$1/commit" + + printf '<table>\n<thead>\n<tr>' + printf '<th>%s</th>' 'Date' 'Commit message' 'Author' + printf '</tr>\n</thead>\n<tbody>\n' + + for hash in $(git log --format='%H') + do + { + head '../..' "Files - ${PWD##*/}" + commit "$hash" + foot + } > "$1/commit/$hash.html" + + git log --format="<tr>$( + printf '<td>%s</td>' \ + '%ad' '<a href="commit/%H.html">%s</a>' '%an' + )</tr>" --date='short' "$hash" + done + + printf '\n</tbody>\n</table>\n' +} + + +# 1: path to the file to process. + +file() +{ + printf '<p>%s</p>\n<table>' + printf '<tr>\n<td>\n<pre id="num">\n' + + if grep -qI . "$1" 1>/dev/null + then + seq "$(wc -l < "$1")" | + sed 's|.*|<a id="&" href="#&">&</a>|' + + printf '</pre></td>\n<td id="file"><pre>\n' + + sed 's|&|\&amp;|g; s|<|\&lt;|g' "$1" + else + printf 'binary file' + fi + + printf '</pre></td></tr></table>' +} + + +# 1: target base directory + +files() +{ + mkdir -p "$1/file" + + printf '<table>\n<thead>\n<tr>' + printf '<th>%s</th>' 'Mode' 'Name' 'Size' + printf '</tr>\n</thead>\n<tbody>\n' + + git ls-files | while IFS='' read -r file + do + [ -z "${file##*/*}" ] && mkdir -p "$1/file/${file%/*}" + + root="$(printf %s "$file" | sed 's|[^/]*||g; s|.|../|g').." + + { + head "../$root" "$file - ${PWD##*/}" + file "$file" + foot + } > "$1/file/$file.html" + + printf '<tr>' + + printf '<td>%s</td>' \ + "$(stat -c %A "$file")" \ + "<a href=\"file/$file.html\">$file</a>" \ + "$(wc -l < "$file")L" + printf '</tr>\n' + done + + printf '\n</tbody>\n</table>\n' +} + + +# 1: target base directory + +repo() +{ + { + head '..' "Commits - ${1##*/}" + commits "$1" + foot + } > $1/commits.html + + { + head '..' "Files - ${1##*/}" + files "$1" + foot + } > $1/files.html + + ln -sf files.html "$1/index.html" + + printf '<li>%s <span style="color: grey;">%s</span>' "${PWD##*/}" "$( + grep "${PWD##*/}" "${1%/git/*}/description" | + sed 's/^[^ ]* //' + )" + printf '<span class="nav">' + printf '<a href="git/%s">%s</a>' "${PWD##*/}/files.html" 'files' + printf ' - <a href="git/%s">%s</a>' "${PWD##*/}/commits.html" 'commits' + printf '</span></li>\n' +} + + +# 1: source git directory + +repos() +{ + printf '<ul>\n' + + find "$1" -maxdepth 1 -mindepth 1 -type d | sort | + while IFS='' read -r repo + do + printf '%s\n' "$repo" 1>&2 + + mkdir -p "${repo##*/}" + + ( + pwd="$PWD" + cd "$repo" && repo "$pwd/${repo##*/}" || exit 1 + ) + done + + printf '</ul>\n' +} + + +repos "$@"