commit 7aef084d35e29568ad8f1aee23bb6c3296533c24 parent 6fae183f001a001310f4e86a1cc1696da84ef454 Author: JayVii <jayvii[AT]posteo[DOT]de> Date: Sat, 8 Jun 2024 16:33:48 +0200 feat: generate proper summary index page Diffstat:
M | bin/git_update_repo_html.sh | | | 59 | +++++++++++++++++++++++++++++++++++++++++++---------------- |
1 file changed, 43 insertions(+), 16 deletions(-)
diff --git a/bin/git_update_repo_html.sh b/bin/git_update_repo_html.sh @@ -30,28 +30,55 @@ find "${1}/${2}/${3}" \ # build HTML stagit "${1}/${2}/${3}.git" -# if readme exists, use as index, otherwise use the repository log -if [ -z $(find "${1}/${2}/${3}/file" -type f -name "README*.html") ]; then - # use log.html as index - ln -sf "${1}/${2}/${3}/log.html" "${1}/${2}/${3}/index.html" -else - # use readme as index +# create summary index page +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" 2>/dev/null) +RURL=$(cat "${1}/${2}/${3}.git/url" 2>/dev/null) +RDME=$( find "${1}/${2}/${3}/file" \ - -type f \ - -name "README*.html" \ - -exec cp {} "${1}/${2}/${3}/index.html" \; - # adjust relative paths accordingly - sed -e 's/\.\.\///g' \ - -e 's/href=\"\"/href=\"..\/\"/g' \ - -i "${1}/${2}/${3}/index.html" -fi + -type f \ + -name "README*.html" \ + -exec basename {} \; +) + +## generate summary injection content +SUMR=" + <h2>${3}</h2> + <p>${RDESC}</p> + <span>Clone this repository via:</span> + <pre>git clone ${RURL}</pre> + <ul> + <li><a href=\"log.html\">Log</a></li> + <li><a href=\"files.html\">Files</a></li> + <li><a href=\"refs.html\">Refs</a></li> + <li><a href=\"exports/\">Exports</a></li> + <li><a href=\"file/${RDME:-..}\">README</a></li> + </ul> + </div> + </body> + </html> +" + +## Inject Summary into content +echo "$SUMR" >> "${1}/${2}/${3}/index.html" # Protect Mail-Adresses in HTML MAILEXP='s/([a-zA-Z0-9\.]+)\@([a-zA-Z0-9\-]+)\.([a-z]+)/\1\[AT\]\2\[DOT\]\3/g' find "${1}/${2}/${3}/" -type f -exec sed -E -e ${MAILEXP} -i {} \; -# Add Exports to menu -INJEXP="s/(>Refs<\/a>)/\1 \| <a href=\"\/${2}\/${3}\/exports\/\">Exports<\/a> /" +# Add Exports to menu (behind Files) +INJEXP="s/(>Files<\/a>\ \|)/\1 <a href=\"\/${2}\/${3}\/exports\/\">Exports<\/a> \|/" +find "${1}/${2}/${3}/" -type f -name "*.html" -exec sed -E "${INJEXP}" -i {} \; + +# Add Summary to menu (before Log) +INJEXP="s/^(<a\ href=\"log.html\">)/<a\ href=\"\/${2}\/${3}\/index.html\">Summary<\/a>\ \| \1/" find "${1}/${2}/${3}/" -type f -name "*.html" -exec sed -E "${INJEXP}" -i {} \; # Replace "git clone" href