🢀 stagit :: ff47333


commit ff473330fd04b0d7c4383d50339cde76bd0fcae9
Author: acidvegas <acid.vegas@acid.vegas>
Date:   Mon Jun 17 23:23:30 2019 -0400

    Initial commit

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d0e76b2
--- /dev/null
+++ b/README.md
@@ -0,0 +1,37 @@
+# stagit
+> static git page generator
+
+###### Information
+This is basically a shell script clone of [stagit](https://git.2f30.org/stagit/).
+
+It is meant to be hosted on [Github](https://github.com) using [Github Pages](https://pages.github.com) with a [Custom domain](https://help.github.com/en/articles/using-a-custom-domain-with-github-pages).
+
+A live demo of this script can be seen [here](https://acid.vegas).
+
+###### Settings
+| Setting        | Default   | Description                                                        |
+| -------------- | --------- | ------------------------------------------------------------------ |
+| CLONE_URL      | remote    | base url for cloning repositories *(remote = remote.origin.url)*   |
+| CNAME          | empty     | create a CNAME file with a custom domain *(empty = do not create)* |
+| 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                                             |
+
+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
+* Convert SSH remote urls to HTTPS for Github & Github-like domains.
+* Remove default settings & parse command line arguments instead.
+* Parse repository owner in a better way & add support for detecting organization names.
+* Create an index per-user to view specific users repos & key information.
+* Use 🔒 to show if a commit was signed.
+* Pagination support.
+* Option to minify HTML & CSS.
+* Create a local preview *(of both themes)* using the docs directory.
\ No newline at end of file
diff --git a/stagit b/stagit
new file mode 100755
index 0000000..c07fb10
--- /dev/null
+++ b/stagit
@@ -0,0 +1,123 @@
+#!/bin/sh
+
+set -e
+
+##### settings ######################################################################
+CLONE_URL='remote' # base url for cloning repositories ('remote' = remote.origin.url)
+CNAME=''           # create a CNAME file with a custom domain (empty = do not create)
+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
+#####################################################################################
+
+if [ ! -d $REPO_DIR ]; then
+	echo "'$REPO_DIR' directory does not exist"
+elif [ -z "$(find $REPO_DIR -name .git -type d -prune)" ]; then
+	echo "'$REPO_DIR' contains no repositories"
+fi
+
+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"\
+				"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"\
+				".item:hover{background-color:#eee}\n"\
+				".item td{white-space:nowrap}\n"\
+				"#main{border-collapse:collapse;table-layout:fixed}\n"\
+				"#main td,th{padding-left:5px;padding-right:5px}\n"\
+				"#navigation{color:#000;font-weight:900;text-align:left}" >> $WWW_DIR/style.css
+	else
+		echo -e "a{color:#8dc}\n"\
+				"a:hover{color:#8cd}\n"\
+				"body{background-color:#111;color:#fff;font-family:monospace;margin-top:0px}\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"\
+				".item:hover{background-color:#1a1a1a}\n"\
+				".item td{white-space:nowrap}\n"\
+				"#main{border-collapse:collapse;table-layout:fixed}\n"\
+				"#main td,th{padding-left:5px;padding-right:5px}\n"\
+				"#navigation{color:#fff;font-weight:900;text-align:left}" >> $WWW_DIR/style.css
+	fi
+}
+
+generate_index() {
+	generate_css
+	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>Repositories</title>\n"\
+			"<h1><a href=\"index.html\">&#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
+}
+
+generate_repository_index() {
+	local REPO_NAME=$1
+	local REPO_URL=$2
+	local REPO_DESC=${@:3}
+	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</title>\n"\
+			"<h1><a href=\"index.html\">&#8962;</a> $REPO_NAME</h1>\n"\
+			"<h4>$REPO_DESC</h4>\n"\
+			"<h5>git clone <a href=\"$REPO_URL\">$REPO_URL</a></h5>\n"\
+			"<hr>\n"\
+			"<table id=\"main\" cellpadding=\"0\" cellspacing=\"0\">\n"\
+			"<tr id=\"navigation\"><td>Hash</td><td>Commit message</td><td>Author</td><td>Date</td></tr>" >> $WWW_DIR/$REPO_NAME$EX
+}
+
+mkdir -p $WWW_DIR && rm -rf $WWW_DIR/*
+[ $SHOW_HTML_EX -eq 1 ] && EX=".html"
+[ ! -z $CNAME ] && echo $CNAME >> $WWW_DIR/CNAME
+generate_index
+for d in $(find $REPO_DIR -name .git -type d -prune | sort); do
+	REPO_NAME=$(basename -s .git `git --git-dir $d config --get remote.origin.url`)
+	if [ -f $d/description ]; then
+		REPO_DESC=$(head -n 1 $d/description)
+		if [ "$REPO_DESC" = "Unnamed repository; edit this file 'description' to name the repository." ]; then
+			echo "edit description for $REPO_NAME ($d/description)"
+			REPO_DESC="no description available"
+		fi
+	else
+		echo "missing description file for $REPO_NAME ($d/description)"
+		REPO_DESC="no description available"
+	fi
+	REPO_OWNER=$(git --git-dir $d log --reverse --pretty=format:'%an' | head -n 1) # todo: find a better way to do this
+	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
+	if [ $CLONE_URL = 'remote' ]; then
+		REPO_URL=$(git --git-dir $d config --get remote.origin.url) # todo: handle ssh urls
+	else
+		REPO_URL=$CLONE_URL/$REPO_NAME.git
+	fi
+	generate_repository_index $REPO_NAME $REPO_URL $REPO_DESC
+	if [ $MAX_COMMITS -eq 0 ]; then
+		REPO_COMMITS=$(git --git-dir $d log --all --date=relative --pretty=format:"%h|%s|%cn|%cd")
+	else
+		REPO_COMMITS=$(git --git-dir $d log --all --date=relative --pretty=format:"%h|%s|%cn|%cd" | head -n $MAX_COMMITS)
+	fi
+	echo "$REPO_COMMITS" | while IFS= read -r line; do
+		COMMIT_HASH=$(echo $line | cut -d'|' -f1)
+		COMMIT_MESSAGE=$(echo $line | cut -d'|' -f2 | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/"/\&quot;/g;')
+		if [ $MAX_COMMIT_MSG -ne 0 -a ${#COMMIT_MESSAGE} -gt $MAX_COMMIT_MSG ]; then
+			COMMIT_MESSAGE=${COMMIT_MESSAGE:0:$MAX_COMMIT_MSG}...
+		fi
+		COMMIT_AUTHOR=$(echo $line | cut -d'|' -f3)
+		COMMIT_DATE=$(echo $line | cut -d'|' -f4)
+		echo "<tr class=\"item\"><td>$COMMIT_HASH</td><td>$COMMIT_MESSAGE</td><td>$COMMIT_AUTHOR</td><td>$COMMIT_DATE</td></tr>" >> $WWW_DIR/$REPO_NAME$EX
+	done
+done
\ No newline at end of file