🢀 stagit :: 29afa3d


commit 29afa3dcf01b756d9c31496aae5aa68e7589ce80
Author: acidvegas <acid.vegas@acid.vegas>
Date:   Fri Jul 5 19:26:19 2019 -0400

    Added clickable commit hash links to view commit changes

diff --git a/README.md b/README.md
index 25f4d11..1fa7785 100644
--- a/README.md
+++ b/README.md
@@ -17,13 +17,10 @@ A live demo of this script can be seen [here](https://acid.vegas).
 | MAX_COMMIT_MSG | 100       | maximum characters in a commit message to display *(0 = all)*      |
 | REPO_DIR       | $HOME/git | directory containing repositories                                  |
 | THEME          | light     | default style used *(light or dark)*                               |
-| SHOW_HTML_EX   | 1         | include .html extension in `<a>` links                             |
 | WWW_DIR        | $HOME/www | directory to output to                                             |
 
 If the `CLONE_URL` was set to `https://github.com/acidvegas/` for exmaple, then it will display as `git clone https://github.com/acidvegas/REPO_NAME.git` on all repository indexes, otherwise if you leave it as `remote` it will just parse the remote url already setup for that repository.
 
-Also, the `SHOW_HTML_EX` can be set to `0` to hide the .html extension. This will work on Github pages by default, but if you are using your own web server, you will need to create a rule in your [HTACCESS](http://lmgtfy.com/?q=Hide+HTML+extension+with+HTACCESS) file.
-
 Lastly, the `CNAME` option is required if you are using a custom domain with Github pages. See [here](https://help.github.com/en/articles/troubleshooting-custom-domains#github-repository-setup-errors) for more information.
 
 ###### Todo
@@ -36,7 +33,6 @@ Lastly, the `CNAME` option is required if you are using a custom domain with Git
 * Create a local preview *(of both themes)* using the docs directory.
 * Add a footer to all pages with the last updated datetime and a link to this repository.
 * Hook git pushes to rebuild the repositories index.
-* Make commit hashs clickable links to view the commit changes.
 * Add support for displaying README files and convert Github-style markdown to HTML
 
 ###### Issues
diff --git a/stagit b/stagit
index 65de5a9..a7b3450 100755
--- a/stagit
+++ b/stagit
@@ -8,7 +8,6 @@ MAX_COMMITS=100    # maximum number of commits to show (0 = all)
 MAX_COMMIT_MSG=100 # maximum characters in a commit message to display (0 = all)
 REPO_DIR=$HOME/git # directory containing repositories
 THEME='light'      # default style used ('light' or 'dark')
-SHOW_HTML_EX=1     # include .html extension in <a> links
 WWW_DIR=$HOME/www  # directory to output to
 #####################################################################################
 
@@ -16,11 +15,14 @@ generate_css() {
 	if [ $THEME = 'light' ]; then
 		echo -e "a{color:blue}\n"\
 				"body{background-color:#fff;color:#000;font-family:monospace;margin-top:0px}\n"\
+				"code{counter-increment:line}\n"\
+				"code::before{border-right:1px solid #000;color:#000;content:counter(line);display:inline-block;margin-right:.5em;padding:0 .5em;width:1.5em;-webkit-user-select:none}\n"\
 				"h1{margin:0px}\n"\
 				"h1 a{color:#000;text-decoration:none}\n"\
 				"h4{color:#777;margin:0px}\n"\
 				"h5{margin:0px;font-style:italic;font-weight:normal}\n"\
 				"hr{border:none;border-bottom:1px solid #777}\n"\
+				"pre{counter-reset:line}\n"\
 				".item:hover{background-color:#eee}\n"\
 				".item td{white-space:nowrap}\n"\
 				"#main{border-collapse:collapse;table-layout:fixed}\n"\
@@ -30,11 +32,14 @@ generate_css() {
 		echo -e "a{color:#8dc}\n"\
 				"a:hover{color:#8cd}\n"\
 				"body{background-color:#111;color:#fff;font-family:monospace;margin-top:0px}\n"\
+				"code{counter-increment:line}\n"\
+				"code::before{border-right:1px solid #fff;color:#fff;content:counter(line);display:inline-block;margin-right:.5em;padding:0 .5em;width:1.5em;-webkit-user-select:none}\n"\
 				"h1{margin:0px}\n"\
 				"h1 a{color:#fff;text-decoration:none}\n"\
 				"h4{color:#777;margin:0px}\n"\
 				"h5{font-style:italic;font-weight:normal;margin:0px}\n"\
 				"hr{border:none;border-bottom:1px dashed #fff}\n"\
+				"pre{counter-reset:line}\n"\
 				".item:hover{background-color:#1a1a1a}\n"\
 				".item td{white-space:nowrap}\n"\
 				"#main{border-collapse:collapse;table-layout:fixed}\n"\
@@ -49,7 +54,7 @@ generate_index() {
 			"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n"\
 			"<meta charset=\"UTF-8\">\n"\
 			"<title>Repositories</title>\n"\
-			"<h1><a href=\"index.html\">&#8962;</a> Repositories</h1>\n"\
+			"<h1><a href=\"index.html\" title=\"Home\">&#8962;</a> Repositories</h1>\n"\
 			"<hr>\n"\
 			"<table id=\"main\" cellpadding=\"0\" cellspacing=\"0\">\n"\
 			"<tr id=\"navigation\"><th>Name</th><th>Description</th><th>Owner</th><th>Last commit</th></tr>" >> $WWW_DIR/index.html
@@ -59,23 +64,35 @@ generate_repository_index() {
 	local REPO_NAME=$1
 	local REPO_URL=$2
 	local REPO_DESC=${@:3}
+	mkdir -p $WWW_DIR/$REPO_NAME/commit
 	echo -e "<!DOCTYPE html>\n"\
 			"<html lang=\"en-US\">\n"\
-			"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n"\
+			"<link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\">\n"\
 			"<meta charset=\"UTF-8\">\n"\
 			"<title>$REPO_NAME</title>\n"\
-			"<h1><a href=\"index.html\">&#8962;</a> $REPO_NAME</h1>\n"\
+			"<h1><a href=\"../index.html\" title=\"Home\">&#8962;</a> $REPO_NAME</h1>\n"\
 			"<h4>$REPO_DESC</h4>\n"\
-			"<h5>git clone <a href=\"$REPO_URL\">$REPO_URL</a></h5>\n"\
+			"<h5>git clone <a href=\"$REPO_URL\" title=\"$REPO_NAME clone URL\">$REPO_URL</a></h5>\n"\
 			"<hr>\n"\
 			"<table id=\"main\" cellpadding=\"0\" cellspacing=\"0\">\n"\
-			"<tr id=\"navigation\"><td>&nbsp; Hash</td><td>Commit message</td><td>Author</td><td>Date</td></tr>" >> $WWW_DIR/$REPO_NAME.html
+			"<tr id=\"navigation\"><td>&nbsp;&nbsp; Hash</td><td>Commit message</td><td>Author</td><td>Date</td></tr>" >> $WWW_DIR/$REPO_NAME/index.html
+}
+
+generate_commit_index() {
+	local REPO_NAME=$1
+	local COMMIT_HASH=$2
+	echo -e "<!DOCTYPE html>\n"\
+			"<html lang=\"en-US\">\n"\
+			"<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style.css\">\n"\
+			"<meta charset=\"UTF-8\">\n"\
+			"<title>$REPO_NAME :: $COMMIT_HASH</title>\n"\
+			"<h1><a href=\"../index.html\" title=\"Back to Repository\">&#x1F880;</a> $REPO_NAME :: $COMMIT_HASH</h1>\n"\
+			"<hr><pre>" >> $WWW_DIR/$REPO_NAME/commit/$COMMIT_HASH.html
 }
 
 [ ! -d $REPO_DIR ] && echo "'$REPO_DIR' directory does not exist" && exit 1
 [ -z "$(find $REPO_DIR -name .git -type d -prune)" ] && echo "'$REPO_DIR' contains no repositories" && exit 1
 mkdir -p $WWW_DIR && rm -rf $WWW_DIR/*
-[ $SHOW_HTML_EX -eq 1 ] && EX=".html"
 [ ! -z $CNAME ] && echo $CNAME >> $WWW_DIR/CNAME
 generate_css && generate_index
 for d in $(find $REPO_DIR -name .git -type d -prune | sort); do # todo: sort by basename
@@ -92,7 +109,7 @@ for d in $(find $REPO_DIR -name .git -type d -prune | sort); do # todo: sort by
 	fi
 	REPO_OWNER=$(git --git-dir $d log --reverse --pretty=format:'%an' | head -n 1) # todo: find a better way to do this & handle organization name parsing
 	REPO_LAST_COMMIT=$(git --git-dir $d log -1 --date=relative --pretty=format:'%cd')
-	echo "<tr class=\"item\"><td><a href=\"$REPO_NAME$EX\">$REPO_NAME</a></td><td>$REPO_DESC</td><td>$REPO_OWNER</td><td>$REPO_LAST_COMMIT</td></tr>" >> $WWW_DIR/index.html
+	echo "<tr class=\"item\"><td><a href=\"$REPO_NAME\" title=\"$REPO_NAME\">$REPO_NAME</a></td><td>$REPO_DESC</td><td>$REPO_OWNER</td><td>$REPO_LAST_COMMIT</td></tr>" >> $WWW_DIR/index.html
 	if [ $CLONE_URL = 'remote' ]; then
 		REPO_URL=$(git --git-dir $d config --get remote.origin.url) # todo: handle ssh urls
 	else
@@ -122,6 +139,12 @@ for d in $(find $REPO_DIR -name .git -type d -prune | sort); do # todo: sort by
 		fi
 		COMMIT_AUTHOR=$(echo $line | cut -d'|' -f6)
 		COMMIT_DATE=$(echo $line | cut -d'|' -f7)
-		echo "<tr class=\"item\"><td>$COMMIT_SIGNED $COMMIT_HASH</td><td>$COMMIT_MESSAGE</td><td>$COMMIT_AUTHOR</td><td>$COMMIT_DATE</td></tr>" >> $WWW_DIR/$REPO_NAME.html
+		echo "<tr class=\"item\"><td>$COMMIT_SIGNED <a href=\"commit/$COMMIT_HASH.html\ title=\"View this commit\"">$COMMIT_HASH</a></td><td>$COMMIT_MESSAGE</td><td>$COMMIT_AUTHOR</td><td>$COMMIT_DATE</td></tr>" >> $WWW_DIR/$REPO_NAME/index.html
+		generate_commit_index $REPO_NAME $COMMIT_HASH
+		COMMIT_DIFF=$(git --git-dir $d show $COMMIT_HASH | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/"/\&quot;/g;')
+		echo "$COMMIT_DIFF" | while IFS= read -r line; do
+			echo "<code>$line</code>" >> $WWW_DIR/$REPO_NAME/commit/$COMMIT_HASH.html
+		done
+		echo "</pre>" >> $WWW_DIR/$REPO_NAME/commit/$COMMIT_HASH.html
 	done
 done
\ No newline at end of file