site-inator/site-inator

92 lines
2.6 KiB
Bash
Executable file

#!/bin/bash
################################################################################
# SITE-INATOR
# simple www html web page maker. designed to make it easy to write html websites
# by hand!
########################
# Copyright (C) 2023 - yukijouu <Yuki Joou> -- yukijoou@laposte.net
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <https://www.gnu.org/licenses/>.
echo '==================================================';
echo '| SITE-INATOR Copyright (C) 2023 yukijoou |';
echo '| This program comes with ABSOLUTELY NO WARRANTY |';
echo '==================================================';
set -e;
TEMPLATES_PATH=template
OUTPUT_PATH=public
SOURCES_PATH=src
STATIC_RESOURCES_PATH=static
[[ -e $TEMPLATES_PATH ]] ||
(
echo 'Please create $TEMPLATES_PATH, and place your templates there!' &&
exit 1
);
[[ -e $SOURCES_PATH ]] ||
(
echo 'Please create $SOURCES_PATH, and place your source html there!' &&
exit 1
);
mkdir -p $OUTPUT_PATH;
[[ -e ./site-config ]] ||
(
echo 'site-config not found. Please create a ./site-config file!' &&
echo 'It needs to define a TITLE' &&
exit 1
);
echo 'Using the following configuration:';
cat ./site-config
echo -e '\n========================================='
DEFAULT_TITLE=$(source ./site-config && echo $TITLE)
echo ' Website generation will commence now!';
echo;
echo;
echo "Removing old data at $OUTPUT_PATH";
rm -rI $OUTPUT_PATH/;
for file in $(find $SOURCES_PATH/ -iname '*.html'); do
clean_path="${file#$SOURCES_PATH/}"
echo "Generating $clean_path!";
out_dir=$(dirname "$OUTPUT_PATH/$clean_path");
mkdir -p $out_dir;
page_title=$DEFAULT_TITLE
[[ -e $file.config ]] && page_title=$(source $file.config && echo $TITLE);
raw_page=$(cat $TEMPLATES_PATH/header.html $file $TEMPLATES_PATH/footer.html);
page="${raw_page//\[ title \]/$page_title}"
echo -n "$page" > $OUTPUT_PATH/$clean_path;
done;
echo 'Generation: done!'
[[ -e $STATIC_RESOURCES_PATH/ ]] && (echo "Copying static assets..." && find $STATIC_RESOURCES_PATH/ -maxdepth 1 -mindepth 1 -exec cp -r {} $OUTPUT_PATH/ ';')
echo "Check $OUTPUT_PATH/ for the processed files"