stagit

improvements

- rename $logdir to $htmldir.
- use file .git/description as $description.
- use directory name of repodir as $name.
- set symlink for default page.

Hiltjo Posthuma contact@arjunchoudhary.com

commit: 706ba35 parent: 67e2d42
2 files changed, 55 insertions(+), 40 deletions(-)
MTODO+4-3
Murmoms+51-37
M · TODO +4, -3
 1@@ -6,11 +6,12 @@
 2 - escape < > ' " etc, maybe even use CDATA ?
 3 - shorter date format for logs.html page.
 4 - speed up generating files.
 5-x add stylesheet + 2f30/suckless logo.
 6 - for files link to the commit but make the filename a link anchor.
 7-- default to log view (stateless).
 8 - link to lines in file view! / commit log?
 9 - show all the tags and branches as list.
10 - show commits for all tags and branches???
11-x no tarballs, snapshots and such.
12 - able to add link to git url: git://url... per project.
13+
14+x default to log view (stateless).
15+x no tarballs, snapshots and such.
16+x add stylesheet + 2f30/suckless logo.
M · urmoms +51, -37
  1@@ -15,15 +15,16 @@ header() {
  2 <head>
  3 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4 <meta http-equiv="Content-Language" content="en" />
  5-<title>${description}</title>
  6+<title>${name} - ${description}</title>
  7 <base href="${baseurl}" />
  8 <link rel="stylesheet" type="text/css" href="style.css" />
  9 </head>
 10 <body>
 11 <center>
 12-<h1><img src="logo.png" alt="" /> ${description}</h1>
 13-<a href="index.html">Tree</a> |
 14+<h1><img src="logo.png" alt="" /> ${name}</h1>
 15+<span class="desc">${description}</span><br/>
 16 <a href="log.html">Log</a> |
 17+<a href="files.html">Files</a> |
 18 <a href="stats.html">Stats</a> |
 19 <a href="readme.html">README</a> |
 20 <a href="license.html">LICENSE</a>
 21@@ -43,57 +44,67 @@ footer() {
 22 !__EOF__
 23 }
 24 
 25+# usage: repodir and htmldir must be set.
 26 if test x"$1" = x"" || test x"$2" = x""; then
 27 	usage
 28 fi
 29 
 30+# make absolute path to htmldir.
 31+htmldir="$(readlink -f $2)"
 32+mkdir -p "${htmldir}"
 33+
 34 # repodir must be a directory to go to.
 35 cd "$1" || usage
 36 
 37+# project name
 38+# TODO: if bare repo just remove .git suffix?
 39+name=$(basename "$(pwd)")
 40+
 41+# read .git/description.
 42+description=""
 43+test -f ".git/description" && description="$(cat '.git/description')"
 44+
 45 # TODO: make configurable.
 46 baseurl="http://cow.codemadness.org/gitlog/"
 47-# TODO: read .git/description.
 48-description="sbase"
 49 
 50-# absolute path to logdir.
 51-logdir="$(readlink -f $2)"
 52-mkdir -p "${logdir}"
 53+indexpage="log.html"
 54+
 55 firstcommit=$(git log | grep '^commit ' | tail -n 1 | cut -f 2 -d ' ')
 56 
 57 # make log per file.
 58 # TODO: just link to commit/commit? save some space and time?
 59 git ls-tree -r --name-only master | while read -r file; do
 60-	test -e "${logdir}/file/${file}.html" && continue
 61+	test -e "${htmldir}/file/${file}.html" && continue
 62 
 63 	d=$(dirname "${file}")
 64-	mkdir -p "${logdir}/file/${d}"
 65+	mkdir -p "${htmldir}/file/${d}"
 66 
 67-	header > "${logdir}/file/${file}.html"
 68+	header > "${htmldir}/file/${file}.html"
 69 	git show "${firstcommit}"...master "${file}" | \
 70-		sed -E 's@^commit (.*)$@commit <a href="commit/\1.html">\1</a>@g' >> "${logdir}/file/${file}.html"
 71-	footer >> "${logdir}/file/${file}.html"
 72+		sed -E 's@^commit (.*)$@commit <a href="commit/\1.html">\1</a>@g' >> "${htmldir}/file/${file}.html"
 73+	footer >> "${htmldir}/file/${file}.html"
 74 done
 75 
 76 # make log with all commits.
 77-header > "${logdir}/log.html"
 78-printf '<table border="0">' >> "${logdir}/log.html"
 79-git log --pretty='<tr><td align="right">%cD</td><td><a href="commit/%H.html">%H</a></td><td>%an</td><td>%s</td></tr>' >> "${logdir}/log.html"
 80-printf '</table>' >> "${logdir}/log.html"
 81-footer >> "${logdir}/log.html"
 82+header > "${htmldir}/log.html"
 83+printf '<table border="0">' >> "${htmldir}/log.html"
 84+git log --pretty='<tr><td align="right">%cD</td><td><a href="commit/%H.html">%H</a></td><td>%an</td><td>%s</td></tr>' >> "${htmldir}/log.html"
 85+printf '</table>' >> "${htmldir}/log.html"
 86+footer >> "${htmldir}/log.html"
 87 
 88 # make diff for each commit (all files).
 89-mkdir -p "${logdir}/commit"
 90+mkdir -p "${htmldir}/commit"
 91 git log --pretty='%H' | while read -r commit; do
 92-	test -e "${logdir}/commit/${commit}.html" && continue
 93-	header > "${logdir}/commit/${commit}.html"
 94-	git show "${commit}" >> "${logdir}/commit/${commit}.html"
 95-	footer >> "${logdir}/commit/${commit}.html"
 96+	test -e "${htmldir}/commit/${commit}.html" && continue
 97+	header > "${htmldir}/commit/${commit}.html"
 98+	git show "${commit}" >> "${htmldir}/commit/${commit}.html"
 99+	footer >> "${htmldir}/commit/${commit}.html"
100 done 
101 
102 # make index with file links.
103-header >> "${logdir}/index.html"
104-git ls-tree -r master | sed -E 's@	(.*)$@	<a href="file/\1.html">\1</a>@g' >> "${logdir}/index.html"
105-footer >> "${logdir}/index.html"
106+header >> "${htmldir}/files.html"
107+git ls-tree -r master | sed -E 's@	(.*)$@	<a href="file/\1.html">\1</a>@g' >> "${htmldir}/files.html"
108+footer >> "${htmldir}/files.html"
109 
110 # readme page
111 # find README file.
112@@ -102,13 +113,13 @@ for f in README README.md readme.md; do
113 	test -e "${f}" && readme="${f}"
114 done
115 # make page.
116-header > "${logdir}/readme.html"
117+header > "${htmldir}/readme.html"
118 if test x"${readme}" != x""; then
119-	cat "${readme}" >> "${logdir}/readme.html"
120+	cat "${readme}" >> "${htmldir}/readme.html"
121 else
122-	echo "no README file found" >> "${logdir}/readme.html"
123+	echo "no README file found" >> "${htmldir}/readme.html"
124 fi
125-footer >> "${logdir}/readme.html"
126+footer >> "${htmldir}/readme.html"
127 
128 # license page
129 # find LICENSE file.
130@@ -117,15 +128,18 @@ for f in LICENSE LICENSE.md; do
131 	test -e "${f}" && license="${f}"
132 done
133 # make page.
134-header > "${logdir}/license.html"
135+header > "${htmldir}/license.html"
136 if test x"${readme}" != x""; then
137-	cat "${license}" >> "${logdir}/license.html"
138+	cat "${license}" >> "${htmldir}/license.html"
139 else
140-	echo "unknown license" >> "${logdir}/license.html"
141+	echo "unknown license" >> "${htmldir}/license.html"
142 fi
143-footer >> "${logdir}/license.html"
144+footer >> "${htmldir}/license.html"
145 
146 # stats (authors).
147-header > "${logdir}/stats.html"
148-git shortlog -n -s >> "${logdir}/stats.html"
149-footer >> "${logdir}/stats.html"
150+header > "${htmldir}/stats.html"
151+git shortlog -n -s >> "${htmldir}/stats.html"
152+footer >> "${htmldir}/stats.html"
153+
154+# symlink to index page.
155+ln -sf "$indexpage" "${htmldir}/index.html"