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

49 lines
1.2 KiB
Bash
Raw Normal View History

2020-06-08 01:23:34 +08:00
#! /bin/bash
# just gonna assume you're executing in the scripts folder
# build the blog files
cd ../blog
2020-06-08 19:24:33 +08:00
CONTENTNUM=$(($(ls content-* | wc -l)-1))
for ((i=-1;i<$CONTENTNUM;i++))
2020-06-08 01:23:34 +08:00
do
2020-11-07 23:28:46 +08:00
# separate files by respective static pages
2020-06-08 18:42:50 +08:00
padint="$(printf %03d $i)"
contentname="content-$padint"
quotename="quote-$padint"
tailname="tail-$padint"
blogname="blog-$padint"
# interactive tail
2020-06-08 19:24:33 +08:00
if (( $i >= 0 )) ;then
2020-11-07 23:28:46 +08:00
# prepare tail template
cp filetail "$tailname"
2020-11-07 23:28:46 +08:00
# increment int if the page exists
2020-06-08 18:42:50 +08:00
padintprev="$(printf %03d $(($i - 1)) )"
2020-06-08 19:24:33 +08:00
if (( $(($i+1)) == $CONTENTNUM )) ;then
padintnext="$(printf %03d -1 )"
else
padintnext="$(printf %03d $(($i + 1)) )"
fi
2020-11-07 23:28:46 +08:00
# replace placeholders
sed -i "s/PREVPADINT/$padintprev/g" "$tailname"
sed -i "s/NEXTPADINT/$padintnext/g" "$tailname"
2020-06-08 18:42:50 +08:00
fi
# cat together
2020-06-08 19:24:33 +08:00
if [[ -f $contentname ]] ;then
cat filehead "$contentname" "$tailname" "$quotename" > "$blogname"
fi
2020-06-08 01:23:34 +08:00
done
2020-11-07 23:28:46 +08:00
# clean up non prod files, lock down permissions, and self-destruct
2020-06-08 18:42:50 +08:00
cd ../blog
2020-11-07 23:28:46 +08:00
\rm filehead filetail content* quote* .blog.* tail*
2020-06-08 01:23:34 +08:00
cd ../
2020-11-07 23:28:46 +08:00
\rm -rf .git scripts .index.html.* README.md
2020-06-08 01:23:34 +08:00
find . -type f | xargs chmod 600
find . -type d | xargs chmod 700