69 lines
1.5 KiB
Bash
Executable File
69 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
rootDir='./site/'
|
|
targetDir='post/'
|
|
source .creds
|
|
url="https://$user:$pass@neocities.org/api/upload"
|
|
|
|
post() {
|
|
tmp=".swap"
|
|
full=".fullswap"
|
|
base=$(basename $1)
|
|
# First build the content of the site
|
|
pandoc $1 | sed '3i </div>' >> $tmp
|
|
sed -i '1i <div class="header">' $tmp
|
|
# next we glue together the header and footer
|
|
cat ./templates/post-header.html $tmp ./templates/post-footer.html > $full
|
|
rm -f $tmp
|
|
# Title, images and tables get added/fixed here
|
|
sed -i "5i <title>${base%.*}</title>" $full
|
|
sed -i "s/<img/<img class=\"pure-img\"/g" $full
|
|
sed -i 's/<table>/<table class="pure-table">/g' $full
|
|
|
|
# finally move this post to its proper location in the _rootDir
|
|
mv $full "$rootDir/$targetDir/${base%.*}.html"
|
|
rm -f $full
|
|
}
|
|
|
|
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"
|
|
|
|
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)
|
|
upload;;
|
|
h)
|
|
_help;;
|
|
esac
|
|
done
|