add option to copy assets

This commit is contained in:
Václav Uruba 2023-09-09 14:57:56 +02:00
parent 1c779e4c63
commit 061d332228
Signed by: uruba
GPG Key ID: 9D8E987C4B2E1E9C

26
mige.sh
View File

@ -1,16 +1,29 @@
#!/bin/bash #!/bin/bash
DIR_ASSETS=${DIR_ASSETS:-assets}
DIR_CONTENT=${DIR_CONTENT:-in} DIR_CONTENT=${DIR_CONTENT:-in}
DIR_DIST=${DIR_DIST:-out} DIR_DIST=${DIR_DIST:-out}
TEMPLATE_HEADER=${TEMPLATE_HEADER:-templates/header.html} TEMPLATE_HEADER=${TEMPLATE_HEADER:-templates/header.html}
TEMPLATE_FOOTER=${TEMPLATE_FOOTER:-templates/footer.html} TEMPLATE_FOOTER=${TEMPLATE_FOOTER:-templates/footer.html}
SOURCEDIR=$( dirname -- $BASH_SOURCE ) SOURCEDIR=$( dirname -- $BASH_SOURCE )
OPTION_ASSETS=false
check_files () { check_files () {
if [ ! -f "$SOURCEDIR/$TEMPLATE_HEADER" ]; then echo "Header template '$TEMPLATE_HEADER' doesn't exist."; exit 2; fi if [ ! -f "$SOURCEDIR/$TEMPLATE_HEADER" ]; then echo "Header template '$TEMPLATE_HEADER' doesn't exist."; exit 2; fi
if [ ! -f "$SOURCEDIR/$TEMPLATE_FOOTER" ]; then echo "Header template '$TEMPLATE_FOOTER' doesn't exist."; exit 2; fi if [ ! -f "$SOURCEDIR/$TEMPLATE_FOOTER" ]; then echo "Header template '$TEMPLATE_FOOTER' doesn't exist."; exit 2; fi
if [ ! -d "$SOURCEDIR/$DIR_CONTENT" ]; then echo "Content directory '$DIR_CONTENT' doesn't exist. Create it and add some content!"; exit 2; fi if [ ! -d "$SOURCEDIR/$DIR_CONTENT" ]; then echo "Content directory '$DIR_CONTENT' doesn't exist. Create it and add some content!"; exit 2; fi
if [ ! -d "$SOURCEDIR/$DIR_DIST" ]; then mkdir "$SOURCEDIR/$DIR_DIST"; echo "Directory '$DIR_DIST' created."; fi if [ ! -d "$SOURCEDIR/$DIR_DIST" ]; then mkdir "$SOURCEDIR/$DIR_DIST"; echo "Directory '$DIR_DIST' created."; fi
if [[ $OPTION_ASSETS == true && ! -s "$SOURCEDIR/$DIR_ASSETS" ]]; then echo "Directory '$DIR_ASSETS' doesn't exist. Create it and add some assets!"; exit 2; fi
}
read_options() {
while getopts "a" opt; do
case "${opt}" in
a) OPTION_ASSETS=true;;
\?) ;;
esac
done
} }
process_file () { process_file () {
@ -33,12 +46,25 @@ process_file () {
echo -e "\e[32mFile $1 processed to $file_output ($timep ms).\e[0m" echo -e "\e[32mFile $1 processed to $file_output ($timep ms).\e[0m"
} }
process_assets () {
echo -e "Copying assets."
cp -vR "$SOURCEDIR/$DIR_ASSETS/." "$SOURCEDIR/$DIR_DIST"
echo -e "Assets copied."
}
main () { main () {
while IFS= read -d '' file_content; do while IFS= read -d '' file_content; do
process_file "${file_content}" </dev/null process_file "${file_content}" </dev/null
done < <(find "$SOURCEDIR/$DIR_CONTENT" -type f -print0) done < <(find "$SOURCEDIR/$DIR_CONTENT" -type f -print0)
if [ $OPTION_ASSETS = true ]; then
process_assets
fi
} }
read_options "$@"
check_files check_files
echo -e "\e[1m=== STARTING ===\e[0m" echo -e "\e[1m=== STARTING ===\e[0m"