From ef463654f5645bd6e6130815a1181a748866f60c Mon Sep 17 00:00:00 2001 From: Fabian Gabel <fabian.gabel@tuhh.de> Date: Mon, 19 Apr 2021 11:10:24 +0200 Subject: [PATCH] add loops and necessary modifications for multiple topic files --- bin/preprocIndexMd.sh | 45 ++++++++++++++++++++++----------------- bin/preprocMd.sh | 49 +++++++++++++++++++++++-------------------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/bin/preprocIndexMd.sh b/bin/preprocIndexMd.sh index 4b47d87..b4985d4 100755 --- a/bin/preprocIndexMd.sh +++ b/bin/preprocIndexMd.sh @@ -1,34 +1,35 @@ #!/bin/bash -# generate namelist of collaborators from topic file -original="$RESEARCH_ROOT/index.md" -filename="index.md" -build_dir="$RESEARCH_ROOT/build" +RESEARCH_BUILD="$RESEARCH_ROOT/build" +mkdir -p $RESEARCH_BUILD baseurl='https://www.mat.tuhh.de' - -cd $RESEARCH_ROOT - +full_filename="$RESEARCH_ROOT/index.md" +filename=$(basename -- "$full_filename") #make output copy -mkdir -p build echo "Preprocessing $filename..." -cp $original $build_dir/$filename +cp $full_filename $RESEARCH_BUILD/$filename #replace working group echo "Replacing working group keys..." -for wg in {aa,cm,dm,nm,st} +namelist=`grep -h -i -m 1 -r "###\s*Working Groups:" $RESEARCH_BUILD/$filename | sed -e 's/^###\s*Working Groups:\s*//I' -e 's/\s*,\s*/\n/g' | sort -u` +echo "Found the following keys: " $namelist +for wg in $namelist 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" - echo "# $fullname" > ./build/$wg.md + echo "# $fullname" > $RESEARCH_BUILD/$wg.md # append research to staffiles - echo -e "\n$title\n" >> ./build/$wg.md - sed -i "s;### Working Groups:\(.*\)$wg\(.*\);### Working Groups:\1\[$fullname\]($wg.html)\2;g" $build_dir/$filename - #sed -i "s;### Working Groups:\(.*\)$wg\(.*\);### Working Groups:\1\[$fullname\]($baseurl/forschung/$wg)\2;g" $build_dir/$filename #uncomment this line for linking the mat.tuhh.de webpage -done + echo -e "\n$title\n" >> $RESEARCH_BUILD/$wg.md + sed -i "s;### Working Groups:\(.*\)$wg\(.*\);### Working Groups:\1\[$fullname\]($wg.html)\2;g" $RESEARCH_BUILD/$filename + #sed -i "s;### Working Groups:\(.*\)$wg\(.*\);### Working Groups:\1\[$fullname\]($baseurl/forschung/$wg)\2;g" $RESEARCH_BUILD/$filename #uncomment this line for linking the mat.tuhh.de webpage + #initialize wg file + echo "# $fullname" > $RESEARCH_BUILD/$wg.md +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` +namelist=`grep -h -i -m 1 -r "###\s*Collaborators (MAT):" $RESEARCH_BUILD/$filename | sed -e 's/^###\s*Collaborators (MAT):\s*//I' -e 's/\s*,\s*/\n/g' | sort -u` +echo "Found the following keys: " $namelist for name in $namelist do # pipeline to get full name of staff-member from mat-homepage @@ -39,10 +40,16 @@ do wget -qO- $baseurl/home/$name/?homepage_id=$name > page.html iconv -f WINDOWS-1252 -t UTF-8 ./page.html > ./utf.html fullname=`grep h1 ./utf.html | sed -e "s/<h1>\s*\(.*\)<\/h1>.*$/\1/g" | sed -e 's/^[ \t]*//'` + echo "Found collaborator $fullname" - # replace name in index.md file + # replace name in .md file + sed -i "s;$name;\[$fullname\]($name.html);g" $RESEARCH_BUILD/$filename + #sed -i "s;$name;\[$fullname\]($baseurl/home/$name);g" $RESEARCH_BUILD/$filename #uncomment this line for linking the mat.tuhh.de webpage - sed -i "s;$name;\[$fullname\]($name.html);g" $build_dir/$filename - #sed -i "s;$name;\[$fullname\]($baseurl/home/$name);g" $build_dir/$filename #uncomment this line for linking the mat.tuhh.de webpage + #initialize staff file + echo "# $fullname" > $RESEARCH_BUILD/$name.md done + +# adpat img path (prefix a dot) +sed -i "s;\](/img/;\](./img/;g" $RESEARCH_BUILD/$filename \ No newline at end of file diff --git a/bin/preprocMd.sh b/bin/preprocMd.sh index 1be03b8..0772880 100755 --- a/bin/preprocMd.sh +++ b/bin/preprocMd.sh @@ -1,41 +1,46 @@ #!/bin/bash - # generate namelist of collaborators from topic file - original="$RESEARCH_ROOT/topics/topic-template.md" - filename='topic-template.md' - build_dir="$RESEARCH_ROOT/build" - baseurl='https://www.mat.tuhh.de' +RESEARCH_BUILD="$RESEARCH_ROOT/build" +mkdir -p $RESEARCH_BUILD +baseurl='https://www.mat.tuhh.de' - cd $RESEARCH_ROOT +for f in $RESEARCH_ROOT/topics/*.md +do + echo $f + filename=$(basename -- "$f") #make output copy - mkdir -p $RESEARCH_ROOT/build echo "Preprocessing $filename..." - cp $original $build_dir/$filename + cp $f $RESEARCH_BUILD/$filename #extract title of topic - title="## `head -n 1 $build_dir/$filename | sed -e "s;#\s*;\[;g" -e "s;\(.*\);\1\](${filename%.md}.html);g"`" + title="## `head -n 1 $RESEARCH_BUILD/$filename | sed -e "s;#\s*;\[;g" -e "s;\(.*\);\1\](${filename%.md}.html);g"`" # prepare index # append research topic to index echo "Creating index.md ..." - echo -e "\n$title\n" >> ./build/index.md + echo -e "\n$title\n" >> $RESEARCH_BUILD/index.md #replace working group echo "Replacing working group keys..." - for wg in {aa,cm,dm,nm,st} + namelist=`grep -h -i -m 1 -r "###\s*Working Groups:" $RESEARCH_BUILD/$filename | sed -e 's/^###\s*Working Groups:\s*//I' -e 's/\s*,\s*/\n/g' | sort -u` + echo "Found the following keys: " $namelist + for wg in $namelist do + #extract full name from tuhh-webpage 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" - echo "# $fullname" > ./build/$wg.md + # append research to staffiles - echo -e "\n$title\n" >> ./build/$wg.md - sed -i "s;### Working Groups:\(.*\)$wg\(.*\);### Working Groups:\1\[$fullname\]($wg.html)\2;g" $build_dir/$filename - #sed -i "s;### Working Groups:\(.*\)$wg\(.*\);### Working Groups:\1\[$fullname\]($baseurl/forschung/$wg)\2;g" $build_dir/$filename #uncomment this line for linking the mat.tuhh.de webpage + echo -e "\n$title\n" >> $RESEARCH_BUILD/$wg.md + + sed -i "s;### Working Groups:\(.*\)$wg\(.*\);### Working Groups:\1\[$fullname\]($wg.html)\2;g" $RESEARCH_BUILD/$filename + #sed -i "s;### Working Groups:\(.*\)$wg\(.*\);### Working Groups:\1\[$fullname\]($baseurl/forschung/$wg)\2;g" $RESEARCH_BUILD/$filename #uncomment this line for linking the mat.tuhh.de webpage 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` + namelist=`grep -h -i -m 1 -r "###\s*Collaborators (MAT):" $RESEARCH_BUILD/$filename | sed -e 's/^###\s*Collaborators (MAT):\s*//I' -e 's/\s*,\s*/\n/g' | sort -u` echo "Found the following keys: " $namelist for name in $namelist do @@ -51,15 +56,13 @@ echo "Found collaborator $fullname" # replace name in .md file - sed -i "s;$name;\[$fullname\]($name.html);g" $build_dir/$filename - #sed -i "s;$name;\[$fullname\]($baseurl/home/$name);g" $build_dir/$filename #uncomment this line for linking the mat.tuhh.de webpage - - echo "# $fullname" > ./build/$name.md + sed -i "s;$name;\[$fullname\]($name.html);g" $RESEARCH_BUILD/$filename + #sed -i "s;$name;\[$fullname\]($baseurl/home/$name);g" $RESEARCH_BUILD/$filename #uncomment this line for linking the mat.tuhh.de webpage # append research to staffiles - echo -e "\n$title\n" >> ./build/$name.md - + echo -e "\n$title\n" >> $RESEARCH_BUILD/$name.md done # adpat img path (prefix a dot) -sed -i "s;\](/img/;\](./img/;g" $build_dir/$filename +sed -i "s;\](/img/;\](./img/;g" $RESEARCH_BUILD/$filename +done \ No newline at end of file -- GitLab