commit 5e6a9ec9d5515775fe3dc78c23f63434b8436dd4
parent a29c42b09f044a697b3f3c3a7ac88910a3aebdd2
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Mon, 10 Jun 2024 20:28:45 +0200
feat: generate summary from template
Diffstat:
4 files changed, 104 insertions(+), 17 deletions(-)
diff --git a/.htaccess b/.htaccess
@@ -15,6 +15,7 @@ RedirectMatch 404 ^/.config/.*$
RedirectMatch 404 ^/.local/.*$
RedirectMatch 404 ^/.cache/.*$
RedirectMatch 404 ^/bin/.*$
+RedirectMatch 404 ^/templates/.*$
RedirectMatch 404 ^/url$
RedirectMatch 404 ^/.bash_history$
@@ -23,4 +24,4 @@ IndexStyleSheet /assets/index.css
# Workaround: new directory for private repos
RewriteEngine On
-RewriteRule ^priv(.*)$ /prv$1 [R=301,L]
-\ No newline at end of file
+RewriteRule ^priv(.*)$ /prv$1 [R=301,L]
diff --git a/bin/git_update_repo_html.sh b/bin/git_update_repo_html.sh
@@ -40,36 +40,75 @@ fi
# Summary Page -----------------------------------------------------------------
-# create summary index page
+# remove pre-existing index
if [ -f "${1}/${2}/${3}/index.html" ]; then
rm "${1}/${2}/${3}/index.html"
fi
-cp "${1}/${2}/${3}/log.html" "${1}/${2}/${3}/index.html"
-## remove content-field from new index
-sed -i "${1}/${2}/${3}/index.html" \
- -e '/^<div\ id="content">/,/^<\/div>/{/^<div\ id="content">/!{/^<\/div>/!d}}' \
- -e 's/<title>Log\ -\ /<title>/'
-
-## fetch repo description, URL and README
-RDESC=$(cat "${1}/${2}/${3}.git/description_full" 2>/dev/null)
-RURL=$(cat "${1}/${2}/${3}.git/url" 2>/dev/null)
+## fetch repo description, URL and menu-line
+RDESCF=$(
+ cat "${1}/${2}/${3}.git/description_full" 2>/dev/null | \
+ sed -e 's/\//\\\//g'
+)
+RDESCS=$(
+ cat "${1}/${2}/${3}.git/description" 2>/dev/null | \
+ sed -e 's/\//\\\//g'
+)
+RURL=$(
+ cat "${1}/${2}/${3}.git/url" 2>/dev/null | \
+ sed -e 's/\//\\\//g')
+RMENU=$(
+ grep -E "^.*<a\ href=\"log.html\">.*$" \
+ --only-matching "${1}/${2}/${3}/log.html" | \
+ sed -e 's/\//\\\//g'
+)
+
+# read template sections
+THEAD=$(
+ cat "${1}/templates/head.html" | \
+ sed \
+ -e "s/<\!--TITLE-->/${3}/g" \
+ -e "s/<\!--DESC-->/${RDESCS}/g" \
+ -e "s/<\!--DIR-->/\./g" \
+ -e "s/<\!--REPO-->/${RURL}/g"
+)
+TMENU=$(
+ cat "${1}/templates/menu.html" | \
+ sed \
+ -e "s/<\!--TITLE-->/${3}/g" \
+ -e "s/<\!--DESC-->/${RDESCS}/g" \
+ -e "s/<\!--REPO-->/${RURL}/g" \
+ -e "s/<\!--MENU-->/${RMENU}/g"
+)
## generate summary injection content
SUMR="
${ACTIVITY_HTML}
- <pre id=\"description\">${RDESC}</pre>
+ <pre id=\"description\">${RDESCF}</pre>
<hr>
<span>Clone this repository via:</span><br>
<pre>git clone <a href=\"$RURL\">$RURL</a></pre>
</a>
</div>
- </body>
- </html>
"
-## Inject Summary into content
-echo "$SUMR" >> "${1}/${2}/${3}/index.html"
+## Write template
+echo "<!DOCTYPE html>
+<html>
+${THEAD}
+<body>
+${TMENU}
+<div id=\"content\">
+${ACTIVITY_HTML}
+<pre id=\"description\">${RDESCF}</pre>
+<hr>
+<span>Clone this repository via:</span><br>
+<pre>git clone <a href=\"$RURL\">$RURL</a></pre>
+</a>
+</div>
+</body>
+</html>
+" > "${1}/${2}/${3}/index.html"
# Replacements -----------------------------------------------------------------
diff --git a/templates/head.html b/templates/head.html
@@ -0,0 +1,19 @@
+<!--
+ SPDX-License-Identifier: AGPL-3.0-or-later
+ SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de>
+ Variables
+ - TITLE: title of the repository
+ - DESC: description of the repository
+ - DIR: subdirectory relative to the repository-root
+ - REPO: url of the repository
+-->
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+<title><!--TITLE--> - <!--DESC--></title>
+<link rel="icon" type="image/png" href="<!--DIR-->/favicon.png" />
+<link rel="alternate" type="application/atom+xml" title="<!--REPO--> Atom Feed" href="<!--DIR-->/atom.xml" />
+<link rel="alternate" type="application/atom+xml" title="<!--REPO--> Atom Feed (tags)" href="<!--DIR-->/tags.xml" />
+<link rel="stylesheet" type="text/css" href="<!--DIR-->/style.css" />
+</head>
+
diff --git a/templates/menu.html b/templates/menu.html
@@ -0,0 +1,29 @@
+<!--
+ SPDX-License-Identifier: AGPL-3.0-or-later
+ SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de>
+ Variables
+ - TITLE: title of the repository
+ - DESC: description of the repository
+ - REPO: url of the repository
+ - MENU: menu line as generated by stagit
+-->
+<table>
+<tr>
+<td><a href="../"><img src="logo.png" alt="back" width="32" height="32" /></a></td>
+<td>
+<h1><!--TITLE--></h1>
+<span class="desc"><!--DESC--></span>
+</td>
+</tr>
+<tr class="url">
+<td></td>
+<td>git clone <a href="<!--REPO-->";><!--REPO--></a></td>
+</tr>
+<tr>
+<td></td>
+<td>
+<!--MENU-->
+</td>
+</tr>
+</table>
+<hr/>