Summary Files Commits Branches @commit @diff @stats
path: root / generate.sh
blob: 3da2c1e90a78921b84c0077bbe82f7523a25c588 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash

: ${REPO_FOLDER:=.}
: ${GEN_FOLDER:=./website}
: ${GEN_TINY_FOLDER:=./website.tiny}
: ${AWK_FOLDER:=./awk-edits}

# 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!"
	
	/usr/bin/env dash ./csg/csg "$REPO_FOLDER/src" "$GEN_FOLDER" '& \\— Syndamia' 'https://syndamia.com' "$AWK_FOLDER"
# }}}
# 2. 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 "$GEN_FOLDER"/* "$GEN_TINY_FOLDER"

	# Remove unnecessary files
	rm -f  "$GEN_TINY_FOLDER"/*.css
	rm -rf "$GEN_TINY_FOLDER"/fonts/
	rm -f  "$GEN_TINY_FOLDER"/.files

	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
	}

	echo "[Stage 3] Tiny website"
	if [ $# -eq 0 ]; then
		improveForTINY

	
	else
		improveForTINY
	fi
# }}}