From 51df7459819995359e2f30492f42aade724ba93d Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Mon, 5 Mar 2018 17:50:52 +0100
Subject: [PATCH] Updated pug to also use make

---
 Makefile                        |  8 ++++++++
 assets/css/generate_makefile.sh |  3 ---
 generate_makefile.sh            | 36 +++++++++++++++++++++++++++++++++
 package.json                    |  2 +-
 4 files changed, 45 insertions(+), 4 deletions(-)
 create mode 100644 Makefile
 create mode 100755 generate_makefile.sh

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0103148
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+PUG = $(shell pwd)/node_modules/pug-cli/index.js --basedir .
+all: index.html privacy-policy/index.html releases/index.html
+index.html: index.pug
+	$(PUG) index.pug
+privacy-policy/index.html: privacy-policy/index.pug
+	$(PUG) privacy-policy/index.pug
+releases/index.html: releases/index.pug
+	$(PUG) releases/index.pug
diff --git a/assets/css/generate_makefile.sh b/assets/css/generate_makefile.sh
index 6755fe4..c82f4a3 100755
--- a/assets/css/generate_makefile.sh
+++ b/assets/css/generate_makefile.sh
@@ -1,7 +1,4 @@
 #!/bin/bash
-QUALITY=85
-THUMB_QUALITY_PNG=70
-THUMB_QUALITY_JPG=50
 
 cd $(dirname $(realpath -s ${0}))
 
diff --git a/generate_makefile.sh b/generate_makefile.sh
new file mode 100755
index 0000000..ac4ae61
--- /dev/null
+++ b/generate_makefile.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+cd $(dirname $(realpath -s ${0}))
+
+RULES=()
+
+function generate_rule() {
+  file=${1}
+  filename=${2}
+
+  RULES+=("${filename}.html")
+  echo "${filename}.html: ${file}" >> Makefile.wip
+  echo "	\$(PUG) ${file}" >> Makefile.wip
+}
+
+function finalize() {
+  echo -n "all:" >> Makefile
+  for rule in "${RULES[@]}"; do
+    echo -n " $rule" >> Makefile
+  done
+  echo >> Makefile
+  cat Makefile.wip >> Makefile
+  rm Makefile.wip
+}
+
+cat <<EOF > Makefile
+PUG = \$(shell pwd)/node_modules/pug-cli/index.js --basedir .
+EOF
+for file in *.pug **/*.pug; do
+  filename=${file##*/}
+  if [[ ${filename} != _* ]]; then
+    generate_rule ${file} ${file%.*}
+  fi
+done
+
+finalize
\ No newline at end of file
diff --git a/package.json b/package.json
index 6844649..bda365e 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,7 @@
   "version": "3.0.0",
   "description": "This is a websearch frontend for a quassel database.",
   "scripts": {
-    "pug": "node_modules/pug-cli/index.js --basedir . **/index.pug index.pug",
+    "pug": "./generate_makefile.sh && make",
     "sass": "assets/css/generate_makefile.sh  && cd assets/css && make",
     "images": "assets/images/generate_makefile.sh && cd assets/images && make",
     "build": "npm run images && npm run sass && npm run pug"
-- 
GitLab