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

87 lines
2.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
2022-03-14 01:51:08 +08:00
sed " s/PREVPADINT/$padintprev/g;
s/NEXTPADINT/$padintnext/g" filetail > "$tailname"
2020-06-08 18:42:50 +08:00
fi
2022-03-14 01:51:08 +08:00
# cat together for blog page
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
2022-03-14 01:51:08 +08:00
# 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
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 {} \;
2022-03-14 01:51:08 +08:00