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

92 lines
2.3 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 |
sed "s/PUBDATE/$(date -R)/" ) \
2022-03-14 01:51:08 +08:00
<(
for ((i=1;i<10;i++))
do
2022-03-15 00:39:01 +08:00
export padint=$( printf %03d $(( CONTENTNUM -i )) )
2022-03-14 01:51:08 +08:00
cat \
2022-03-15 00:39:01 +08:00
<(
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}/'
2022-03-14 01:51:08 +08:00
) \
2022-03-15 00:39:01 +08:00
<(
2022-03-21 00:41:08 +08:00
printf '<![CDATA['"$( \
2022-03-15 00:39:01 +08:00
cat content-$padint quote-$padint |
2022-03-21 00:39:02 +08:00
tidy -q -ashtml |
sed '2 s/xmlns=".*"//g' |
2022-03-21 00:41:08 +08:00
xmllint --noblanks --xpath '//body' - \
2022-03-21 00:41:59 +08:00
)"']]>'
2022-03-15 01:08:59 +08:00
) \
2022-03-15 00:39:01 +08:00
<(
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}/'
2022-03-14 01:51:08 +08:00
)
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