add option to copy assets
This commit is contained in:
parent
1c779e4c63
commit
061d332228
26
mige.sh
26
mige.sh
@ -1,16 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
DIR_ASSETS=${DIR_ASSETS:-assets}
|
||||
DIR_CONTENT=${DIR_CONTENT:-in}
|
||||
DIR_DIST=${DIR_DIST:-out}
|
||||
TEMPLATE_HEADER=${TEMPLATE_HEADER:-templates/header.html}
|
||||
TEMPLATE_FOOTER=${TEMPLATE_FOOTER:-templates/footer.html}
|
||||
SOURCEDIR=$( dirname -- $BASH_SOURCE )
|
||||
|
||||
OPTION_ASSETS=false
|
||||
|
||||
check_files () {
|
||||
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 [ ! -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 [[ $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 () {
|
||||
@ -33,12 +46,25 @@ process_file () {
|
||||
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 () {
|
||||
while IFS= read -d '' file_content; do
|
||||
process_file "${file_content}" </dev/null
|
||||
done < <(find "$SOURCEDIR/$DIR_CONTENT" -type f -print0)
|
||||
|
||||
if [ $OPTION_ASSETS = true ]; then
|
||||
process_assets
|
||||
fi
|
||||
}
|
||||
|
||||
read_options "$@"
|
||||
check_files
|
||||
|
||||
echo -e "\e[1m=== STARTING ===\e[0m"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user