-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.sh
157 lines (116 loc) · 6.32 KB
/
compile.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#! /bin/bash
rm -rf ./www/* > /dev/null 2>&1
mkdir -p ./www/entries
mkdir -p ./www/media
mkdir -p ./tmp
cp ./entries/media/* ./www//media/
cp ./templates/current.html ./tmp/current.html
cp ./templates/recent.html ./tmp/recent.html
cp ./templates/soon.html ./tmp/soon.html
cp ./templates/archive.html ./tmp/archive.html
cp ./templates/header.html ./www/index.html
cp ./templates/header.html ./www/about.html
cp ./templates/header.html ./www/archive.html
cp ./templates/rss.xml ./www/rss.xml
rss_date=$(date '+%a, %d %b %Y %H:%M:%S %z')
sed -i "s/<!-- last-build-date-marker -->/$rss_date/g" ./www/rss.xml
cp ./styles/style.css ./www/style.css
cp ./styles/fonts/* ./www/
cp -r ./entries/code ./www/code
tmp_file=$(mktemp)
# no current entries check
current_entries_count=$(ls ./entries/current/ | wc -l)
if [ $current_entries_count -eq 0 ]; then
echo "<tr><td style=\"text-align: left;\">Nothing currently in the making. :^)</td></tr>" >> ./tmp/current_table.html
insert_line=$(( $(grep -n "auto-generate-marker" ./tmp/current.html | cut -f1 -d: | head -1)))
sed -i -e "${insert_line}r ./tmp/current_table.html" "./tmp/current.html"
sorted_tmp_file=""
else
awk -v RS='\r?\n' 'FNR==1 {print $0 ":" FILENAME}' ./entries/current/* > "$tmp_file"
sorted_tmp_file=$(sort -r -t '/' -k 2,2 -k 1,1 "$tmp_file")
fi
# current entries
while IFS=':' read -r entry_date file; do
if [ -z "$entry_date" ] || [ -z "$file" ]; then
break
fi
basefilename="$(basename $file)"
title_of_entry=$(echo "$basefilename" | sed 's/\..*$//;s/_/ /g')
echo "<tr><td style=\"text-align: left;\">$entry_date</td><td style=\"text-align: left;\">$title_of_entry</td></tr>" >> ./tmp/current_table.html
insert_line=$(( $(grep -n "auto-generate-marker" ./tmp/current.html | cut -f1 -d: | head -1)))
sed -i -e "${insert_line}r ./tmp/current_table.html" "./tmp/current.html"
rm ./tmp/current_table.html
done <<< "$sorted_tmp_file"
# standalone entries
for file in $(ls -t ./entries/standalone/*.md); do
basefilename="$(basename $file)"
basefilename=$(echo "$basefilename" | sed 's/\..*$//')
pandoc -f markdown -t html "$file" > "./tmp/bare_${basefilename}.html"
cp "./templates/header.html" "./www/${basefilename}.html"
insert_line=$(( $(grep -n "auto-generate-marker" ./www/"${basefilename}".html | cut -f1 -d: | head -1) ))
sed -i -e "${insert_line}r ./tmp/bare_${basefilename}.html" ./www/${basefilename}.html
done
awk -v RS='\r?\n' 'FNR==1 {print $0 ":" FILENAME}' ./entries/recent/* > "$tmp_file"
sorted_tmp_file=$(sort -r -t '/' -k 3,3 -k 2,2 -k 1,1 "$tmp_file")
# recent and archive entries
index=0
while IFS=':' read -r entry_date file; do
basefilename="$(basename $file)"
title_of_entry=$(echo "$basefilename" | sed 's/\..*$//;s/_/ /g')
pandoc -s --metadata title=" " -t slidy --highlight-style my.theme -f markdown -t html "$file" > ./tmp/bare_"${basefilename%.*}".html
cp ./templates/header.html ./www/entries/"${basefilename%.*}".html
insert_line=$(( $(grep -n "auto-generate-marker" ./www/entries/"${basefilename%.*}".html | cut -f1 -d: | head -1) ))
sed -i -e "${insert_line}r ./tmp/bare_${basefilename%.*}.html" "./www/entries/${basefilename%.*}.html"
echo "<tr><td style=\"text-align: left;\">$entry_date</td><td style=\"text-align: left;\"><a href=\"entries/${basefilename%.*}.html\">$title_of_entry</a></td></tr>" >> ./tmp/archive_table.html
insert_line=$(( $(grep -n "auto-generate-marker" ./tmp/archive.html | cut -f1 -d: | head -1) ))
insert_line=$((insert_line-1))
sed -i "${insert_line}r ./tmp/archive_table.html" ./tmp/archive.html
rm ./tmp/archive_table.html
# RSS feed generation
insert_line=$(( $(grep -n "auto-generate-marker" ./www/rss.xml | cut -f1 -d: | head -1) ))
markdown_to_text=$(pandoc -f markdown -t plain "$file")
# | sed 's/"/\"/g')
line_to_insert="<item><title>"$title_of_entry"</title><link>http://mirza.town/entries/"${basefilename%.*}.html"</link><guid>http://mirza.town/entries/"${basefilename%.*}.html"</guid><description>"${markdown_to_text}"</description></item>"
echo $line_to_insert > ./tmp/rss_entry.xml
sed -i "${insert_line}r ./tmp/rss_entry.xml" ./www/rss.xml
# current entries count check
if [ $index -gt 9 ]; then
continue
fi
echo "<tr><td style=\"text-align: left;\">$entry_date</td><td style=\"text-align: left;\"><a href=\"entries/${basefilename%.*}.html\">$title_of_entry</a></td></tr>" >> ./tmp/recent_table.html
insert_line=$(( $(grep -n "auto-generate-marker" ./tmp/recent.html | cut -f1 -d: | head -1) ))
insert_line=$((insert_line-1))
sed -i "${insert_line}r ./tmp/recent_table.html" "./tmp/recent.html"
rm ./tmp/recent_table.html
index=$((index+1))
done <<< "$sorted_tmp_file"
# no soon entries check
soon_entries_count=$(ls ./entries/soon/ | wc -l)
if [ $soon_entries_count -eq 0 ]; then
echo "<tr><td style=\"text-align: left;\">Nothing planned. :^)</td></tr>" >> ./tmp/soon_table.html
insert_line=$(( $(grep -n "auto-generate-marker" ./tmp/soon.html | cut -f1 -d: | head -1)))
sed -i -e "${insert_line}r ./tmp/soon_table.html" "./tmp/soon.html"
sorted_tmp_file=""
else
awk -v RS='\r?\n' 'FNR==1 {print $0 ":" FILENAME}' ./entries/soon/* > "$tmp_file"
sorted_tmp_file=$(sort -r -t '/' -k 2,2 -k 1,1 "$tmp_file")
fi
while IFS=':' read -r entry_date file; do
if [ -z "$entry_date" ] || [ -z "$file" ]; then
break
fi
basefilename="$(basename $file)"
title_of_entry=$(echo "$basefilename" | sed 's/\..*$//;s/_/ /g')
echo "<tr><td style=\"text-align: left;\">$entry_date</td><td style=\"text-align: left;\">$title_of_entry</td></tr>" >> ./tmp/soon_table.html
insert_line=$(($(grep -n "auto-generate-marker" ./tmp/soon.html | cut -f1 -d: | head -1 )))
sed -i "${insert_line}r ./tmp/soon_table.html" ./tmp/soon.html
rm ./tmp/soon_table.html
done <<< "$sorted_tmp_file"
cat ./tmp/recent.html ./tmp/current.html ./tmp/soon.html > ./tmp/index_body.html
insert_line=$(($(grep -n "auto-generate-marker" ./www/index.html | cut -f1 -d: | head -1 )))
sed -i "${insert_line}r ./tmp/index_body.html" ./www/index.html
sed -i "${insert_line}r ./tmp/archive.html" ./www/archive.html
pandoc -f markdown -t html ./templates/about.md > ./tmp/about_body.html
sed -i "${insert_line}r ./tmp/about_body.html" ./www/about.html
rm -rf ./tmp
rm "$tmp_file"