easywebsite/easywebsite.sh

74 lines
1.4 KiB
Bash
Raw Normal View History

2023-08-27 23:06:41 +02:00
#!/bin/bash
#
## Easywebsite
#
# Create a html file out of your Markdownfiles.
# On top it will set a header and onto the botton a footer.
#
## Variables
#
# Workdir with the *.md files to convert
workdir="$1"
# HTML-template for pandoc
template="template/html.template"
# Head of Website
header="template/head.html"
footer="template/foot.html"
# Serverconfig
# Server to upload if there is none set "false"
webserver="false"
# User of webserver
webserveruser=""
# Port to connect with sftp
sftpport="22"
#
## Funktions
#
convertfiles() {
echo "Convert your Markdownfiles to HTML-Files..."
cd $workdir #Switch to workdir
find . -name \*.md -type f -exec pandoc --template=$template -B $header -A $footer -o {}.html {} \;
find . -depth -name '*.md.html' -execdir bash -c 'mv -i "$1" "${1//md.html/html}"' bash {} \;
echo "Files converted!"
}
cleaning() {
#Ask for permission to cleanup and cleanup
printf "Do you really want to clean up $workdir with all subdirs except *template/*? *Yes* or *No*: "
read cleanupok
if [[ $cleanupok == "Yes" ]]; then
echo "Cleaning up $workdir..."
cd $workdir #Switch to workdir
find . -name \*.html -type f ! -path '*/template/*' -delete
elif [[ $cleanupok == "No" ]]; then
echo "Don't clean up!"
else
echo "Don't clean up! Argument was wrong..."
fi
}
#
## Main
#
echo workdir
cleaning
convertfiles
echo="Files converted and uploaded!"