#! /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 | sed "s/PUBDATE/$(date -R)/" ) \ <( for ((i=1;i<10;i++)) do export padint=$( printf %03d $(( CONTENTNUM -i )) ) cat \ <( head -n $(( itemlinereplace -1 )) .rss.item.template | title=$(jq -r '.data | .['"$padint"'].title' .data.json ) \ perl -pe 's/TITLE/$ENV{title}/; s/CURRENTINT/$ENV{padint}/' ) \ <( cat content-$padint quote-$padint | tidy -q -asxml | xq -cx '.html.body' | tr '\n' ' ' | printf " 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 {} \;