#!/bin/sh # learn-plain-fases, a simple website documentation generator # Copyright 2021,2022 Ferass El Hafidi # 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. # Please see the LICENSE file for more details. usage() { echo "Usage: ./learn.sh [OPTIONS]" echo "-h : prints this help message" echo "-c : remove generated website" echo "-l : prints the license" } if [ "$1" = "-h" ]; then usage exit 0 elif [ "$1" = "-c" ]; then echo "Removing generated website ..." rm -rf www/* exit 0 elif [ "$1" = "-l" ]; then cat COPYING.GPLv3 exit 0 elif [ "$1" = "" ]; then echo "Generating website ..." else echo "/!\\ Invalid option." usage exit 1 fi # Insert header header() { sed "s/{this_page}$1/" "templates/header.html" } # Insert footer footer() { # There's a trailing slash - example: /CHAT sed "s/{this_page}$1/" "templates/footer.html" } docs="$(cd docs/ && find ./*.md|sed -e 's/\.md//' -e 's/.//')" list() { printf "\n" printf " \n" printf "\n" } for file in ${docs} do header ${file} > "www/${file}.html" list >> "www/${file}.html" #sed -e '1d' "docs/${file}.md" \ # -e 's,!\[\([^]]*\)\](\([^)]*\)),\1,g' \ # -e 's@\*\*\*.*.\*\*\*@&@g' \ # -e 's@\*\*.*.\*\*@&@g' \ # -e 's,\*\([^*<>][^*<>]*\)\*,\1,g' \ # -e 's,\[\([^]]*\)\](\([^)]*\)),\1,g' >> "www/${file}.html" echo "" >> "www/${file}.html" sed '1d' "docs/${file}.md" | markdown | sed -e 's_^\(.*\)_\2 _' >> "www/${file}.html" echo "" >> "www/${file}.html" footer "${file}" >> "www/${file}.html" done