Files
personal-website/scripts/build-website.sh

94 lines
2.4 KiB
Bash
Executable File

#! /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<CONTENTNUM;i++))
do
# separate files by respective static pages
padint="$(printf %03d "$i")"
contentname="content-$padint"
quotename="quote-$padint"
tailname="tail-$padint"
blogname="blog-$padint.html"
# interactive tail
if (( 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
padint=$( printf %03d $(( CONTENTNUM -i )) )
export padint
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}/'
) \
<(
printf '<![CDATA['"%s"']]>' \
"$(
cat content-$padint quote-$padint |
tidy -q -asxhtml |
sed '2 s/xmlns=".*"//g' |
xmllint --noblanks --xpath '//body' -
)"
) \
<(
tail -n +$(( itemlinereplace +1 )) .rss.item.template |
pubdate=$(jq -r '.data | .['"$padint"'].published_date' .data.json ) \
guid=$(jq -r '.data | .['"$padint"'].guid' .data.json ) \
perl -pe 's/PUBDATE/$ENV{pubdate}/; s/GUID/$ENV{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 {} \;