physics/refresh.sh
2021-10-03 18:41:52 +02:00

47 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
wai=$(dirname $(readlink -f "$0")) # Current script directory
projects_dir=${wai}/projects
www_dir=${wai}/www
projects_out_dir=${www_dir}/projects/
template_file=${wai}/template.html
# Clean before
rm -f $www_dir/*.html
rm -fr $projects_out_dir/*
# Build links
build_links() {
links=""
for p in $(find ${projects_dir}/ -maxdepth 1 -mindepth 1 -type d)
do
name=$(basename $p)
[ $name == $1 ] && active="active" || active=""
links="${links}\n"'<a href="'${name}'.html" class="btn btn-primary '$active'">'${name}'</a>'
done
tmp=$(mktemp)
echo -e "$links" > $tmp
echo $tmp
}
# Build html
for p in $(find ${projects_dir}/ -maxdepth 1 -mindepth 1 -type d)
do
name=$(basename $p)
html=$projects_out_dir/$name/index.html
js=$projects_out_dir/$name/index.js
page=${www_dir}/${name}.html
# Create html
echo $p
cp -r $p $projects_out_dir/
cat $template_file |sed "/\${CONTENT}/r $html"|sed '/\${CONTENT}/d' > $page
sed -i "s#\${JS}#${js}#g" $page
sed -i "s#\${project_name}#${name}#g" $page
# Add links
links_file=$(build_links $name)
sed -i "/\${LINKS}/r $links_file" $page
sed -i '/\${LINKS}/d' $page
done