#! /bin/bash # just gonna assume you're executing in the scripts folder # build the blog files cd ../blog || exit CONTENTNUM=$(($( find . -type f -name "content-*" | wc -l)-1)) for ((i=-1;i= 0 )) ;then # prepare tail template cp filetail "$tailname" # increment int if the page exists padintprev="$(printf %03d $((i - 1)) )" if (( $((i+1)) == CONTENTNUM )) ;then padintnext="$(printf %03d -1 )" else padintnext="$(printf %03d $((i + 1)) )" fi # replace placeholders sed " s/PREVPADINT/$padintprev/g; s/NEXTPADINT/$padintnext/g" filetail > "$tailname" fi # cat together for blog page if [[ -f $contentname ]] ;then cat filehead "$contentname" "$tailname" "$quotename" > "$blogname" fi done # compile items for rss cd ../blog || exit # get replace point in templates linereplace=$(grep -n '$itemlist' .rss.template | cut -f1 -d:) itemlinereplace=$(grep -n '$item' .rss.item.template | cut -f1 -d:) # build rss feed cat \ <(head -n $(( linereplace -1 )) .rss.template) \ <( for ((i=1;i<10;i++)) do itemnum=$(( CONTENTNUM - i )) padint=$(printf %03d $itemnum) title=$(jq '.data | .['"$padint"'].title' .data.json ) pubdate=$(jq '.data | .['"$padint"'].published_date' .data.json ) guid=$(jq '.data | .['"$padint"'].guid' .data.json ) cat \ <(head -n $(( itemlinereplace -1 )) .rss.item.template | sed "s/TITLE/$title/; s/CURRENTINT/$padint/" ) \ <(cat content-$padint quote-$padint | tidy -q -asxml | xq -cx '.html.body' ) \ <(tail -n +$(( itemlinereplace +1 )) .rss.item.template | sed "s/PUBDATE/$pubdate/; s/GUID/$guid/" ) done ) \ <(tail -n +$(( linereplace +1 )) .rss.template) \ > rss.xml # clean up non prod files, lock down permissions, and self-destruct cd ../blog || exit \rm filehead filetail content* quote* .blog.* tail* cd ../ || exit \rm -rf .git scripts .index.html.* README.md Jenkinsfile find . -type f -exec chmod 600 {} \; find . -type d -exec chmod 700 {} \;