blog/make.sh

71 lines
1.4 KiB
Bash
Raw Normal View History

#!/bin/bash
rootDir='./site/'
targetDir='post/'
source .creds
url="https://$user:$pass@neocities.org/api/upload"
2019-09-11 02:36:09 +00:00
# auto tools should be able to fix this
post() {
tmp=".swap"
full=".fullswap"
2019-09-11 02:36:09 +00:00
base=`basename $1`
# First build the content of the site
2019-09-11 02:36:09 +00:00
pandoc $1 > $tmp
# Title, images and tables get added/fixed here
2019-09-11 02:36:09 +00:00
sed "s/{TITLE}/<title>${base%.*}<\/title>/g" ./templates/post-header.html > $full
cat $tmp ./templates/post-footer.html >> $full
sed -i 's/<img/<img class="pure-img"/g;s/<table>/<table class="pure-table">/g' $full
2019-09-11 02:36:09 +00:00
# Move things to proper directory and cleanup
mv $full "$rootDir/$targetDir/${base%.*}.html"
2019-09-11 02:36:09 +00:00
rm -f $tmp
}
upload() {
cd $rootDir
name=''
# first the root pages
find -type f | xargs 'name=basename %';curl -f "$name=@%" $url
}
_help() {
echo 'Options:
-p [postDirectory/*]
-r (build root pages)
-s (copy stylesheets)'
}
mkdir -p "$rootDir/post"
2019-09-11 02:36:09 +00:00
if [ -z $1 ]
then
exit 0
fi
while getopts ":srhup:" opt;do
case "$opt" in
s)
cp style.css "$rootDir" # root stylesheet
cp style.css "$rootDir/$targetDir" # post stylesheet
exit 0
;;
r)
# Fix targetDir so that it points to the root of the site output
targetDir=''
post './prebuild/about.md'
post './prebuild/links.md'
post './prebuild/index.md'
exit 0
;;
p)
for file in ${@:2};do
#echo $file
post $file
done
;;
u)
2019-09-11 02:36:09 +00:00
upload;; # this needs a proper fix according to api
h)
_help;;
esac
done