-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.sh
executable file
·158 lines (141 loc) · 4.97 KB
/
generate.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/sh
mkdir -p web
. ./settings.sh
DateStamp() {
sed -i '$ d' "$1"
{
printf "<p>Page Last Edited: %s\n" "$2"
echo "</p>"
printf "</html>\n"
} >> "$1"
}
HashOver() {
sed -i '$ d' "$1"
{
echo "<div id=\"hashover\"></div>"
echo "<script type=\"text/javascript\" src=\"../../../hashover/comments.php\"></script>"
echo "<noscript>You must have javascript enabled for comments.</noscript>"
echo "</html>"
} >> "$1"
}
# CAT comes from settings.sh
GetCategory() {
USECATEGORY=$1
for i in $(seq 1 $CATCOUNT)
do
A=CAT$i
B=CATNAME$i
A=$(eval echo \$"$A")
B=$(eval echo \$"$B")
test "$1" = "$A" && USECATEGORY="$B"
test "$1" = "$B" && USECATEGORY="$1"
done
}
# create index page
rm index.groff
custom_index=$(cat index_custom.groff)
{
echo ".B \"""$SITETITLE""\""
echo ""
echo ".B \"""$SITEDESCRIPTION""\""
echo ""
echo ".MTO "$MAILTO
echo ""
} >> index.groff
for i in $(seq 1 $CATCOUNT)
do
A=CAT$i
B=CATNAME$i
A=$(eval echo \$"$A")
B=$(eval echo \$"$B")
PAGEFILENAME=$(echo "$A" | tr '[:upper:]' '[:lower:]')
{
printf ".URL %s.html" "$PAGEFILENAME"
printf " \""
printf "%s" "$B"
printf "\""
printf "\n"
printf "\n"
} >> index.groff
done
cat index_custom.groff >> index.groff
# generate index page
groff -ms -mwww -T html index.groff > web/index.html
# generate sub pages
for i in $(seq 1 $CATCOUNT)
do
A=CAT$i
B=CATNAME$i
A=$(eval echo \$"$A")
B=$(eval echo \$"$B")
PAGEFILENAME=$(echo "$A" | tr '[:upper:]' '[:lower:]')
rm -f "$PAGEFILENAME".groff
test -f "$PAGEFILENAME"_custom.groff && cat "$PAGEFILENAME"_custom.groff >> $PAGEFILENAME.groff
echo "" >> $PAGEFILENAME.groff
echo ".B \"Recent Posts\"" >> $PAGEFILENAME.groff
for f in $(ls -1r posts/*/*/*)
do
LINK=$(echo $f | sed "s/.groff/.html/g")
CATEGORY=$(grep -r -m1 ".CAT" "$f" | sed "s/.CAT //g")
TITLE=$(grep -r -m1 ".TL" "$f" | sed "s/.TL/ /g" | sed "s/_/ /g")
test "$CATEGORY" = "$A" && echo "" >> $PAGEFILENAME.groff
test "$CATEGORY" = "$B" && echo "" >> $PAGEFILENAME.groff
test "$CATEGORY" = "$A" && echo -n ".URL " >> $PAGEFILENAME.groff
test "$CATEGORY" = "$A" && echo -n $LINK" " >> $PAGEFILENAME.groff
test "$CATEGORY" = "$B" && echo -n ".URL " >> $PAGEFILENAME.groff
test "$CATEGORY" = "$B" && echo -n $LINK" " >> $PAGEFILENAME.groff
test "$CATEGORY" = "$A" && echo "\""$TITLE"\"" >> $PAGEFILENAME.groff
test "$CATEGORY" = "$B" && echo "\""$TITLE"\"" >> $PAGEFILENAME.groff
done
rm -f web/$PAGEFILENAME.html
groff -ms -mwww -T html $PAGEFILENAME.groff > web/$PAGEFILENAME.html
done
# turn posts into html
for f in posts/*/*/*
do
mkdir -p "web/"$(dirname $f)"/"
GENERATED="web/"$(dirname $f)"/"$(basename $f .groff).html
groff -ms -mwww -T html $f > $GENERATED
#groff -ms -mwww -T html $f > "web/"$(dirname $f)"/"$(basename $f .groff).html
HashOver $GENERATED
DateStamp $GENERATED "$(git log -1 --date=format:'%Y-%m-%d %H:%M:%S' -- $f | tail -n3 | head -n1)"
done
# datesstamp htmls
for f in web/*.html
do
useDate="$(git log --date=format:'%Y-%m-%d %H:%M:%S' -1 -- $(basename $f .html)_custom.groff | tail -n3 | head -n1)"
test "$useDate" = "" && useDate="$(date +'%Y-%m-%d %H:%M:%S')"
DateStamp $f "$useDate"
done
rm -f now.groff
grep -r ".TL" $(ls -1r posts/*/*/*) | sed "s/.groff/.html/g" | sed "s/posts/\n.URL posts/g" | sed "s/:.TL / /g" >> now.groff
groff -ms -mwww -T html now.groff > web/now.html
DateStamp web/now.html "$(date +'%Y-%m-%d %H:%M:%S')"
echo "<rss version=\"2.0\">
<channel>
<title>$SITENAME</title>
<link>$SITEADDRESS</link>
<description>$SITEDESCRIPTION</description>
<generator>BoomerCMS</generator>" > web/rss.xml
for f in posts/*/*/*
do
USECATEGORY=
GENERATED="/"$(dirname $f)"/"$(basename $f .groff).html
DATE=$(git log --date=rfc --diff-filter=A -- "$f" | grep "Date:"| sed "s/Date: //g")
echo " <item>" >> web/rss.xml
SPACES=" "
TITLE=$(grep -r -m1 ".TL" "$f" | sed "s/.TL //g" | sed "s/_/ /g")
CATEGORY=$(grep -r -m1 ".CAT" "$f" | sed "s/.CAT //g")
AUTHOR=$(grep -r -m1 ".AU" "$f" | sed "s/.AU //g")
GetCategory "$CATEGORY"
echo "$SPACES<title>$TITLE</title>" >> web/rss.xml
echo "$SPACES<link>$SITEADDRESS$GENERATED</link>" >> web/rss.xml
echo "$SPACES<description>$TITLE</description>" >> web/rss.xml
echo "$SPACES<author>$AUTHOR</author>" >> web/rss.xml
echo "$SPACES<category>$USECATEGORY</category>" >> web/rss.xml
echo "$SPACES<pubDate isPermaLink=\"true\">$DATE</pubDate>" >> web/rss.xml
echo "$SPACES<guid>$SITEADDRESS$GENERATED</guid>" >> web/rss.xml
echo " </item>" >> web/rss.xml
done
echo " </channel>" >> web/rss.xml
echo "</rss>" >> web/rss.xml