aboutsummaryrefslogtreecommitdiff
path: root/sswg.sh
diff options
context:
space:
mode:
authorkeni7385 <andrea@andreacorsini.xyz>2022-06-04 00:09:16 +0300
committerkeni7385 <andrea@andreacorsini.xyz>2022-06-04 00:09:16 +0300
commitaa547f522941c9ba3c60dd0083305c59f717cedd (patch)
treee8ba86747892a89162288ec9be4eed738311190d /sswg.sh
Initial commit
Diffstat (limited to 'sswg.sh')
-rwxr-xr-xsswg.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/sswg.sh b/sswg.sh
new file mode 100755
index 0000000..6e7b42d
--- /dev/null
+++ b/sswg.sh
@@ -0,0 +1,50 @@
+# SSWG - Simple Static Website Generator
+#!/bin/sh
+
+SSWG_OUTPUT_DIR="_static"
+SSWG_ASSETS_DIR="_assets"
+SSWG_PAGES_DIR="_pages"
+SSWG_HEADER_TEMPLATE="_header.t.html"
+SSWG_FOOTER_TEMPLATE="_footer.t.html"
+
+rm -rf "$SSWG_OUTPUT_DIR"
+mkdir "$SSWG_OUTPUT_DIR"
+
+# Copy static assets
+cp -r "$SSWG_ASSETS_DIR"/* "$SSWG_OUTPUT_DIR"/.
+
+# Generate HTML pages
+for page in $(find "$SSWG_PAGES_DIR" -iname '*.html' -o \
+ -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png');
+do
+ filename="$SSWG_OUTPUT_DIR/${page##$SSWG_PAGES_DIR/}"
+ mkdir -p "`dirname $filename`"
+
+ if [ "${filename##*.}" = "html" ]; then
+ # prepose header
+ cat "$SSWG_HEADER_TEMPLATE" >> "$filename"
+
+ # Fix indentation in the generated source
+ cat "$page" | awk '
+ BEGIN {print ""}
+ FNR>3 {print " " $0}
+ END {print ""}' >> "$filename"
+
+ # append footer
+ cat "$SSWG_FOOTER_TEMPLATE" >> "$filename"
+
+ # macro substitution
+ eval `cat "$page" | awk 'FNR<3'`
+ sed -i'' "s@TITLE@$TITLE@g" "$filename"
+ sed -i'' "s@DESCRIPTION@$DESCRIPTION@g" "$filename"
+
+ # remove comments
+ sed -i'' "/^[ \t]*#/d" "$filename"
+
+ # remove indentation before whitespaces+pipe
+ # useful e.g. with <pre> tags
+ sed -i'' "s/^[ \t]*|//g" "$filename" # remove
+ else
+ cp $page $filename
+ fi;
+done;