Summary Files Commits Branches @commit @diff @stats
path: root / generate-dev.sh
blob: df462f953f4c51b0d383ce11911f03608e24ce0d (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /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