From 38ae7dc43fad586d8ff49421df4497636c883aa9 Mon Sep 17 00:00:00 2001
From: Fabian Gabel <fabian.gabel@tuhh.de>
Date: Sun, 18 Apr 2021 11:10:21 +0200
Subject: [PATCH] add index building to gitlab

---
 index.md          | 19 +++++++++++++++++
 preprocIndexMd.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++
 preprocMd.sh      | 10 ++++++++-
 3 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100644 index.md
 create mode 100755 preprocIndexMd.sh

diff --git a/index.md b/index.md
new file mode 100644
index 0000000..635a523
--- /dev/null
+++ b/index.md
@@ -0,0 +1,19 @@
+# Welcome
+
+This page hopefully features all current research interests at our working group.
+
+You browse this Webpage either by research topics or by researchers.
+
+If you want to contribute, see the CONTRIBUTING.md
+
+% THE FOLLOWING IS BUILT AUTOMATICALLY. DON'T CHANGE THE FILE BELOW THIS LINE.
+
+## Working Groups: aa, cm, dm, nm, st
+
+## Collaborators (MAT): ataraz, cseifert, dclemens, dgallaun, druprecht, fboesch, fbuenger, fgabel, fhamann, hruan, hvoss, jangel, jdornemann, jfregin, jgrams, jgrossmann, jmeichsner, jpmzemke, jurizarna, kalbrecht, kklioba, kkruse, mjanssen, mlindner, mschulte, mwolkner, pbaasch, pgupta, rbeddig, rukena, sgoetschel, sleborne, sotten, tsaathoff, vgriem, vtrapp, wleinen, wmackens, ymogge
+
+## Research Topics
+
+
+
+
diff --git a/preprocIndexMd.sh b/preprocIndexMd.sh
new file mode 100755
index 0000000..0797046
--- /dev/null
+++ b/preprocIndexMd.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+# generate namelist of collaborators from topic file
+original="index.md"
+filename="index-output.md"
+build_dir="."
+baseurl='https://www.mat.tuhh.de'
+
+#make output copy
+mkdir -p build
+echo "Preprocessing $filename..."
+cp $original $build_dir/$filename
+
+#replace working group
+echo "Replacing working group keys..."
+for wg in {aa,cm,dm,nm,st}
+do
+    fullname=`wget -qO- $baseurl/forschung/$wg | grep h1 | sed -e "s/<h1>\s*\(.*\)<\/h1>.*$/\1/g" | sed -e 's/^[ \t]*//'`
+    echo "Found working group $fullname"
+    sed -i "s;## Working Groups:\(.*\)$wg\(.*\);## Working Groups:\1\[$fullname\]($baseurl/forschung/$wg)\2;g" $build_dir/$filename 
+done
+
+
+echo "Replacing collaborator keys..."
+namelist=`grep -h -i -m 1 -r "##\s*Collaborators (MAT):" $build_dir/$filename | sed -e 's/^###\s*Collaborators (MAT):\s*//I' -e 's/\s*,\s*/\n/g'  | sort -u`
+for name in $namelist
+do
+    # pipeline to get full name of staff-member from mat-homepage
+    # -> wget the staff homepage of $name
+    # -> grep the line with the <h1>-tag, something like <h1>Fabian Gabel, M. Sc.</h1><div class='staffIntro'><p><img src='/home/fgabel/images/portrait.png' title='Foto von Fabian Gabel, M. Sc.' class='staffPicture'></p><div class='staffContact'>
+    # -> strip the string such that only the portion between <h1></h1> remains
+    # -> remove leading spaces
+    fullname=`wget -qO- $baseurl/home/$name/?homepage_id=$name | grep h1 | sed -e "s/<h1>\s*\(.*\)<\/h1>.*$/\1/g" | sed -e 's/^[ \t]*//'`
+
+    # dirty replacement to avoid dealing with 
+    errstr='Binary file (standard input) matches'
+    if [ "$fullname" = "$errstr" ]; 
+    then
+        fullname=`echo "$name $fullname" | \
+         sed -e "s;jgrossmann $errstr;Dr. Julian Großmann;g" \
+             -e  "s;fbuenger $errstr;Dr. Florian Bünger;g" \
+             -e  "s;hvoss $errstr;Prof. Dr. Heinrich Voß;g" \
+             -e  "s;fboesch $errstr;Dipl. Ing. Frank Bösch;g" \
+             -e  "s;sgoetschel $errstr;Dr. Sebastian Götschel;g"`
+    fi
+    
+    echo "Found collaborator $fullname"
+
+    # replace name in .md file
+    sed -i "s;$name;\[$fullname\]($baseurl/home/$name);g" $build_dir/$filename
+
+done
diff --git a/preprocMd.sh b/preprocMd.sh
index 058a063..2cb5eed 100755
--- a/preprocMd.sh
+++ b/preprocMd.sh
@@ -11,6 +11,13 @@
     echo "Preprocessing $filename..."
     cp $original $build_dir/$filename
 
+    #extract title of topic
+    title="## `head -n 1 $build_dir/$filename | sed -e "s;#\s*;\[;g" -e "s;\(.*\);\1\](${filename%.md}.html);g"`"
+    # append research to index
+    echo $title
+    echo $itle >>  index.md
+    break
+
     #replace working group
     echo "Replacing working group keys..."
     for wg in {aa,cm,dm,nm,st}
@@ -52,7 +59,8 @@
         echo "# $fullname" > ./build/$name.md
 
         # append research to staffiles
-        title="## `head -n 1 $build_dir/$filename | sed -e "s;#\s*;\[;g" -e "s;\(.*\);\1\](${filename%.md}.html);g"`"
         echo $title >> ./build/$name.md
 
+
     done
+
-- 
GitLab