🢀︎ stagit :: 0ff7457


commit 0ff7457355b418e4719df8875bb5c62aaabcf2cc
Author: acidvegas <acid.vegas@acid.vegas>
Date:   Mon Jun 24 00:33:12 2019 -0400

    Small code cleanup

diff --git a/stagit b/stagit
index abea858..f704de3 100755
--- a/stagit
+++ b/stagit
@@ -1,5 +1,4 @@
 #!/bin/sh
-
 set -e
 
 ##### settings ######################################################################
@@ -13,12 +12,6 @@ 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"\
@@ -51,7 +44,6 @@ generate_css() {
 }
 
 generate_index() {
-	generate_css
 	echo -e "<!DOCTYPE html>\n"\
 			"<html lang=\"en-US\">\n"\
 			"<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n"\
@@ -80,11 +72,13 @@ generate_repository_index() {
 			"<tr id=\"navigation\"><td>&nbsp; Hash</td><td>Commit message</td><td>Author</td><td>Date</td></tr>" >> $WWW_DIR/$REPO_NAME.html
 }
 
+[ ! -d $REPO_DIR ] && echo "'$REPO_DIR' directory does not exist" && exit
+[ -z "$(find $REPO_DIR -name .git -type d -prune)" ] && echo "'$REPO_DIR' contains no repositories" && exit
 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
+generate_css && generate_index
+for d in $(find $REPO_DIR -name .git -type d -prune | sort); do # todo: sort by basename
 	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)