From f2ffe55e4de134cb951b76db03093e4e6f2764db Mon Sep 17 00:00:00 2001 From: Jus de Patate_ Date: Wed, 4 Dec 2019 08:03:02 -0700 Subject: [PATCH] First release --- .gitignore | 4 ++++ README.md | 10 ++++++++++ mkhtml | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 mkhtml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8329eb4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +builds/* +src/* +pages/* +parts/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..182c808 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# `mkhtml` +Makes HTML files from `header.html` and `footer.html` + +## How to setup : + - put your header in `parts/header.html` + - put your footer in `parts/footer.html` + - put your css/js (not mandatory) in `src/` (you have to create this folder) + - put pages in `pages/` + +Now run `mkhtml.sh` and check `builds/` it should contains your pages, with the header and the footer you defined in `parts/` diff --git a/mkhtml b/mkhtml new file mode 100755 index 0000000..f36451a --- /dev/null +++ b/mkhtml @@ -0,0 +1,57 @@ +#!/bin/bash + +if [[ -d "$(pwd)/pages/" && -d "$(pwd)/parts/" && -d "$(pwd)/builds/" ]]; then + PAGESDIR="$(pwd)/pages/" + PARTSDIR="$(pwd)/parts/" + BUILDSDIR="$(pwd)/builds/" +else + mkdir {pages,parts,builds} + echo "pages, parts and builds folders were created by mkhtml in $(pwd)" + echo "now populate them" + exit 1 +fi + +if [ -d "$(pwd)/src/" ]; then + SRCDIR="$(pwd)/src/" +fi + +echo " _ _ _ _" +echo " _ __ ___ | | _| |__ | |_ _ __ ___ | |" +echo " | '_ \` _ \| |/ / '_ \| __| '_ \` _ \| |" +echo " | | | | | | <| | | | |_| | | | | | |" +echo " |_| |_| |_|_|\_\_| |_|\__|_| |_| |_|_|" +echo "" +echo "PAGESDIR: $PAGESDIR" +echo "PARTSDIR: $PARTSDIR" +echo "BUILDSDIR: $BUILDSDIR" +if [ -n "$SRCDIR" ]; then + echo "SRCDIR: $SRCDIR" +fi + +if [ ! -w "$BUILDSDIR" ]; then + echo "mkhtml (executed by $(whoami)) can't write in $BUILDSDIR" + echo "Ask your system admin to change permissions or move this whole folder" + exit 1 +fi + +echo "Building files..." + +# https://stackoverflow.com/a/54563899 +cd $PAGESDIR && find . -type f -print0 | while IFS= read -r -d $'\0' file; do + filename=$(echo $file | sed 's/.\///') + newloc="$BUILDSDIR$filename" + touch $newloc 2>/dev/null + echo "Building $file" + cat "$PARTSDIR/header.html" > "$newloc" + cat "$PAGESDIR$filename" >> "$newloc" + cat "$PARTSDIR/footer.html" >> "$newloc" +done + +if [ -n "$SRCDIR" ]; then + echo "Copying SRCDIR to BUILDSDIR" + cp "$SRCDIR" "$BUILDSDIR" +fi + +echo "" +echo "Looks like all files where built" +echo "Pro Tip: add a SRCDIR (create a src/ dir in $(pwd) for CSS/JS, it will get moved in BUILDSDIR as 'src/'"