#!/usr/bin/env bash wai=$(dirname $(readlink -f "$0")) # Current script directory projects_dir=${wai}/projects www_dir=${wai}/public 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"''${name}'' 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