commit ffeb55a9363f303a0bc06476af4dc3b52fac487f
parent ad3d3212d4059aa4e5521b75aa115671feba3bb1
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date: Fri, 30 Oct 2020 22:28:11 +0100
Add support for categories
Diffstat:
4 files changed, 74 insertions(+), 10 deletions(-)
diff --git a/example_create.sh b/example_create.sh
@@ -5,6 +5,7 @@
# NOTE, things to do manually (once) before running this script:
# - copy style.css, logo.svg and favicon.ico manually, a style.css example
# is included.
+# - modify the categories in the for loop with your own.
#
# - write clone url, for example "git://git.codemadness.org/dir" to the "url"
# file for each repo.
@@ -32,12 +33,11 @@ for dir in "$webdir/"*/; do
rm -rf "$dir"
done
-repos=""
-
# make files per repo
for dir in "$reposdir/"*.git/; do
+ dir="${dir%/}"
[ ! -f "$dir/git-daemon-export-ok" ] && continue
- repos="$repos $dir"
+ [ ! -f "$dir/category" ] && [ -z "$stagit_uncat" ] && stagit_uncat="1"
# strip .git suffix
r=$(basename "$dir")
@@ -57,5 +57,26 @@ for dir in "$reposdir/"*.git/; do
echo "done"
done
+# generate index arguments
+args=""
+for cat in "Projects" "Miscellanea"; do
+ args="$args -c \"$cat\""
+ for dir in "$reposdir/"*.git/; do
+ dir="${dir%/}"
+ [ -f "$dir/git-daemon-export-ok" ] && [ -f "$dir/category" ] && \
+ [ "$(cat "$dir/category")" = "$cat" ] && \
+ args="$args $dir"
+ done
+done
+
+if [ -n "$stagit_uncat" ]; then
+ args="$args -c Uncategorized"
+ for dir in "$reposdir/"*.git/; do
+ dir="${dir%/}"
+ [ -f "$dir/git-daemon-export-ok" ] && [ ! -f "$dir/category" ] && \
+ args="$args $dir"
+ done
+fi
+
# make index
-echo "$repos" | xargs stagit-index > "$webdir/index.html"
+echo "$args" | xargs stagit-index > "$webdir/index.html"
diff --git a/example_post-receive.sh b/example_post-receive.sh
@@ -3,6 +3,9 @@
# change the config options below and call this script in your post-receive
# hook or symlink it.
#
+# NOTE, things to do manually (once) before running this script:
+# - modify the categories in the for loop with your own.
+#
# usage: $0 [name]
#
# if name is not set the basename of the current directory is used,
@@ -62,11 +65,31 @@ stagit -c "${cachefile}" "${reposdir}/${r}"
|| ln -sf log.html index.html
ln -sf "${dir}" .git
-# make index
-repos=""
-for dir in "$reposdir/"*.git/; do
- [ -f "$dir/git-daemon-export-ok" ] && repos="$repos $dir"
+# generate index arguments
+args=""
+for cat in "Projects" "Miscellanea"; do
+ args="$args -c $cat"
+ for dir in "$reposdir/"*.git/; do
+ dir="${dir%/}"
+ [ ! -f "$dir/git-daemon-export-ok" ] && continue
+ if [ -f "$dir/category" ]; then
+ [ "$(cat "$dir/category")" = "$cat" ] && args="$args $dir"
+ else
+ stagit_uncat="1"
+ fi
+ done
done
-echo "$repos" | xargs stagit-index > "${destdir}/index.html"
+
+if [ -n "$stagit_uncat" ]; then
+ args="$args -c Uncategorized"
+ for dir in "$reposdir/"*.git/; do
+ dir="${dir%/}"
+ [ -f "$dir/git-daemon-export-ok" ] && [ ! -f "$dir/category" ] && \
+ args="$args $dir"
+ done
+fi
+
+# make index
+echo "$args" | xargs stagit-index > "${destdir}/index.html"
echo "done"
diff --git a/stagit-index.c b/stagit-index.c
@@ -15,6 +15,7 @@ static const char *relpath = "";
static char description[255] = "Oscar Benedito's Git repositories";
static char *name = "";
static char owner[255];
+static char category[255];
void
joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
@@ -119,7 +120,7 @@ writelog(FILE *fp)
if (!strcmp(p, ".git"))
*p = '\0';
- fputs("<tr><td><a href=\"", fp);
+ fputs("<tr class=\"repo\"><td><a href=\"", fp);
xmlencode(fp, stripped_name, strlen(stripped_name));
fputs("/\">", fp);
xmlencode(fp, stripped_name, strlen(stripped_name));
@@ -161,6 +162,17 @@ main(int argc, char *argv[])
writeheader(stdout);
for (i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "-c")) {
+ i++;
+ if (i == argc)
+ err(1, "missing argument");
+ repodir = argv[i];
+ fputs("<tr class=\"cat\"><td>", stdout);
+ xmlencode(stdout, repodir, strlen(repodir));
+ fputs("</td><td></td><td></td></tr>\n", stdout);
+ continue;
+ }
+
repodir = argv[i];
if (!realpath(repodir, repodirabs))
err(1, "realpath");
diff --git a/style.css b/style.css
@@ -201,3 +201,11 @@ pre a.d:hover {
padding: 0.25em 1em;
border: 1px solid var(--border);
}
+
+#index .cat td {
+ font-style: italic;
+}
+
+#index .repo td:first-child {
+ padding-left: 1.5em;
+}