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
2022-02-21 20:37:26 +08:00
cd ../blog || exit
CONTENTNUM=$(($( find . -type f -name "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
2022-02-21 20:37:26 +08:00
padint="$(printf %03d "$i")"
2020-06-08 18:42:50 +08:00
contentname="content-$padint"
quotename="quote-$padint"
tailname="tail-$padint"
blogname="blog-$padint"
# interactive tail
2022-02-21 20:37:26 +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
2022-02-21 20:37:26 +08:00
padintprev="$(printf %03d $((i - 1)) )"
if (( $((i+1)) == CONTENTNUM )) ;then
padintnext="$(printf %03d -1 )"
else
2022-02-21 20:37:26 +08:00
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
2022-02-21 20:37:26 +08:00
cd ../blog || exit
2020-11-07 23:28:46 +08:00
\rm filehead filetail content* quote* .blog.* tail*
2022-02-21 20:37:26 +08:00
cd ../ || exit
2021-02-03 16:46:40 +08:00
\rm -rf .git scripts .index.html.* README.md Jenkinsfile
2022-02-21 20:37:26 +08:00
find . -type f -exec chmod 600 {} \;
find . -type d -exec chmod 700 {} \;