Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitc6569f29f38627d553531f85cf5ea71cae23f897 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-04-28 16:19:27 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-04-28 16:19:27 +0300
Filescdc50e3fbea478ac9addb432850d14c499320385
syndamia.com-c6569f29f38627d553531f85cf5ea71cae23f897.tar
syndamia.com-c6569f29f38627d553531f85cf5ea71cae23f897.tar.gz
syndamia.com-c6569f29f38627d553531f85cf5ea71cae23f897.zip
Parentd869ed9684cd08d9b1bbd3c5f4c1264c39a3eb5c (diff)
[generate] Combined generate-dev into generate script and added features and flexbility
3 files changed, 94 insertions, 114 deletions
-rw-r--r--.gitignore1
-rwxr-xr-xgenerate-dev.sh78
-rwxr-xr-xgenerate.sh129
diff --git a/.gitignore b/.gitignore
index d1626c6..a328512 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
dst/
website/
tiny.website/
+website.tiny/
*.swp
diff --git a/generate-dev.sh b/generate-dev.sh
deleted file mode 100755
index df462f9..0000000
--- a/generate-dev.sh
+++ /dev/null
@@ -1,78 +0,0 @@
-#! /bin/sh
-
-# Make folder if it doesn't exist
-if [ ! -d "/var/www/synd" ]; then
- # User should be www-data (like in generate.sh), but I use Fedora and root is the default one
- mkdir /var/www/synd
-fi
-
-# Remove record of previously generated files
-rm -f /var/www/synd/.files
-
-# Generate files
-ssg src /var/www/synd/ "Syndamia" "https://syndamia.com" > /dev/null
-
-dur=0
-startTimer () {
- dur="$(date +%s%N)"
-}
-endTimer () {
- dur="$(echo "scale=4 ; ($(date +%s%N) - $dur) / 1000000000" | bc -l)"
- printf "%.3fs $1\n" $dur
-}
-
-combine() {
- startTimer
- find './awk-edits' -type f -name "#*.awk" -exec cat {} + > /tmp/syndamiadotcom-awk
- find './awk-edits' -type f -name "[A-Z]*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
- find './awk-edits' -type f -name "_*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
- find './awk-edits' -type f -name "[a-z]*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
- endTimer "generation of /tmp/syndamiadotcom-awk"
-
- startTimer
- for file in $(find '/var/www/synd' -type f -name "*.html"); do
- awk -f '/tmp/syndamiadotcom-awk' "$file" > tmp && mv -f tmp "$file"
- done
- endTimer "/tmp/syndamiadotcom-awk"
-}
-
-separated() {
- libs=""
- for l in $(find './awk-edits' -type f -name "#*.awk"); do
- libs+=" -f $l "
- done
-
- for i in $(find './awk-edits' -type f -name "[A-Z]*.awk") $(find './awk-edits' -type f -name "[a-z]*.awk"); do
- startTimer
- for file in $(find '/var/www/synd/' -type f -name "*.html"); do
- awk $libs -f "$i" -f './awk-edits/_print.awk' "$file" > tmp && mv -f tmp "$file"
- done
- endTimer "$i"
- done
-}
-
-[ -n "$1" ] && separated || combine
-
-#
-# Tiny version
-#
-
-if [ ! -d "/var/www/tiny.synd" ]; then
- # User should be www-data (like in generate.sh), but I use Fedora and root is the default one
- mkdir /var/www/tiny.synd
-fi
-
-# Just take what is already made, no need to regenerate everything
-cp -r /var/www/synd/* /var/www/tiny.synd/
-
-# Remove unnecessary files
-rm -f /var/www/tiny.synd/*.css
-rm -rf /var/www/tiny.synd/fonts/
-rm -f /var/www/tiny.synd/.files
-
-# Remove references to stylesheets in all files
-for file in $(find "/var/www/tiny.synd" -type f -name "*.html"); do
- sed -i -E 's/^.*(rel="stylesheet|\<script|btn).*//g' $file
- sed -i 's/<span>Content/<br><span>Content/g' $file
- sed -i 's/<\/head>/\t<style>img[src$="svg"] { max-height: 1em; } #index-contents-img { max-width: 7.6em; }<\/style>\n<\/head>/' $file
-done
diff --git a/generate.sh b/generate.sh
index 4af6c01..10630f3 100755
--- a/generate.sh
+++ b/generate.sh
@@ -1,48 +1,105 @@
-#! /bin/sh
+#!/bin/bash
-# Make sure this script is ran as www-data!
-# Also, the syndamiadotcom folder MUST be owned by www-data!
+: ${REPO_FOLDER:=.}
+: ${GEN_FOLDER:=./website}
+: ${GEN_TINY_FOLDER:=./website.tiny}
+: ${AWK_FILE:=/tmp/syndamiadotcom-awk}
-if [ ! -d "website" ]; then
- mkdir website
-fi
+# 0. Helper functions {{{
+ dur=0
+ startTimer() {
+ dur="$(date +%s%N)"
+ }
-# Remove record of previously generated files
-rm -f website/.files
+ endTimer() {
+ dur="$(echo "scale=4 ; ($(date +%s%N) - $dur) / 1000000000" | bc -l)"
+ printf "%.3fs $1\n" $dur
+ }
+# }}}
+# 1. Markdown source to HTML {{{
+ [ $# -eq 0 -a "$(id -u -n)" != "www-data" ] && echo "[Warning] Running in \"production\" by a user that isn't www-root!"
+
+ [ ! -d "$GEN_FOLDER" ] && mkdir "$GEN_FOLDER"
+ [ $# -eq 0 -a "$(stat -c %U "$GEN_FOLDER")" != "www-data" ] && echo "[Warning] Running in \"production\" while $GEN_FOLDER isn't owned by www-data!"
+
+ # Remove record of previously generated files
+ rm -f "$GEN_FOLDER/.files"
+ ssg "$REPO_FOLDER/src" "$GEN_FOLDER" "Syndamia" "https://syndamia.com" >/dev/null
+# }}}
+# 2. Editing HTML files with AWK {{{
+ createAWKscript() {
+ # "librarires"
+ find "$REPO_FOLDER/awk-edits" -type f -name "#*.awk" -exec cat {} + > "$AWK_FILE"
+ # Scripts
+ find "$REPO_FOLDER/awk-edits" -type f -name "[A-Z]*.awk" -exec cat {} + >> "$AWK_FILE"
+ echo '{if ($0 != 0) print}' >> "$AWK_FILE"
+ # Post-print part of scripts
+ find "$REPO_FOLDER/awk-edits" -type f -name "[a-z]*.awk" -exec cat {} + >> "$AWK_FILE"
+ }
+ # $1 - $libs, for devs
+ runAWKscript() {
+ for file in $(find "$GEN_FOLDER" -type f -name "*.html"); do
+ awk $1 -f "$AWK_FILE" "$file" > tmp && mv -f tmp "$file"
+ done
+ }
-# Generate files
-ssg src website "Syndamia" "https://syndamia.com"
+ if [ $# -eq 0 ]; then # Run in "production"
+ createAWKscript
+ runAWKscript
-allnormfiles=$(find './website' -type f -name "*.html")
-find './awk-edits' -type f -name "#*.awk" -exec cat {} + > /tmp/syndamiadotcom-awk
-find './awk-edits' -type f -name "[A-Z]*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
-find './awk-edits' -type f -name "_*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
-find './awk-edits' -type f -name "[a-z]*.awk" -exec cat {} + >> /tmp/syndamiadotcom-awk
+ elif [ "$1" == 'dev' ]; then
+ startTimer
+ createAWKscript
+ endTimer "generation of $AWK_FILE"
+ startTimer
+ runAWKscript
+ endTimer "$AWK_FILE"
-for file in $(find './website' -type f -name "*.html"); do
- awk -f '/tmp/syndamiadotcom-awk' "$file" > tmp && mv -f tmp "$file"
-done
-#
-# Tiny version
-#
+ elif [ "$1" == 'devs' ]; then
+ libs=""
+ for l in $(find "$REPO_FOLDER/awk-edits" -type f -name "#*.awk"); do
+ libs+=" -f $l "
+ done
-if [ ! -d "tiny.website" ]; then
- mkdir tiny.website
-fi
+ for i in $(find "$REPO_FOLDER/awk-edits" -type f -name "[A-Z]*.awk") $(find "$REPO_FOLDER/awk-edits" -type f -name "[a-z]*.awk"); do
+ AWK_FILE="$i"
+ startTimer
+ runAWKscript "$libs"
+ endTimer "$i"
+ done
+ fi
+# }}}
+# 3. Tiny version, strip away styles and other stuff {{{
+ [ ! -d "$GEN_TINY_FOLDER" ] && mkdir "$GEN_TINY_FOLDER"
+ [ $# -eq 0 -a "$(stat -c %U "$GEN_TINY_FOLDER")" != "www-data" ] && echo "[Warning] Running in \"production\" while $GEN_TINY_FOLDER isn't owned by www-data!"
-# Just take what is already made, no need to regenerate everything
-cp -r website/* tiny.website/
+ # Just take what is already made, no need to regenerate everything
+ cp -r "$GEN_FOLDER"/* "$GEN_TINY_FOLDER"
-# Remove unnecessary files
-rm -f tiny.website/*.css
-rm -rf tiny.website/fonts/
-rm -f tiny.website/.files
+ # Remove unnecessary files
+ rm -f "$GEN_TINY_FOLDER"/*.css
+ rm -rf "$GEN_TINY_FOLDER"/fonts/
+ rm -f "$GEN_TINY_FOLDER"/.files
-# Remove references to stylesheets in all files
-for file in $(find "tiny.website" -type f -name "*.html"); do
- sed -i -E 's/^.*(rel="stylesheet|\<script|btn).*//g' $file
- sed -i 's/<span>Content/<br><span>Content/g' $file
- sed -i 's/<\/head>/\t<style>img[src$="svg"] { max-height: 1em; } #index-contents-img { max-width: 7.6em; }<\/style>\n<\/head>/' $file
-done
+ improveForTINY() {
+ for file in $(find "$GEN_TINY_FOLDER" -type f -name "*.html"); do
+ # Remove references to stylesheets in all files
+ sed -i -E 's/^.*(rel="stylesheet|\<script|btn).*//g' $file
+ sed -i 's/<span>Content/<br><span>Content/g' $file
+ # Fix svg images being too big (scaling without limit)
+ sed -i 's/<\/head>/\t<style>img[src$="svg"] { max-height: 1em; } #index-contents-img { max-width: 7.6em; }<\/style>\n<\/head>/' $file
+ done
+ }
+
+ if [ $# -eq 0 ]; then
+ improveForTINY
+
+
+ else
+ startTimer
+ improveForTINY
+ endTimer "tiny website page improvements"
+ fi
+# }}}