forked from flymia/EzBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.cgi
executable file
·161 lines (123 loc) · 4.31 KB
/
index.cgi
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
158
159
160
161
#!/usr/bin/env bash
#Sourcing the settings file, to get variables
source config/settings
#Getting the search term, if there is one
searchterm=${get[s]}
if [ -z "$searchterm" ]; then
search=false
else
search=true
fi
#Cutting out the title after the "title: " segment.
gettitle() {
head -5 $1 | grep '^title: ' | cut -d ':' -f 2
}
#Doing the same for the date
getdate() {
head -5 $1 | grep '^date: ' | cut -d ':' -f 2
}
#...and the author
getauthor() {
head -5 $1 | grep '^author: ' | cut -d ':' -f 2
}
#...and the content. This is printing out the contents auf POSTNUMBER.html
getcontent() {
cat "$ENCODED/$1.html"
}
search() {
grep -ri $ARTICLES/ -e $1 | eval "awk '//{print \$1}'" | cut -d ":" -f 1 | uniq
}
#Doing that for the webserver, so that it knows, which MIME type to display
echo -e 'Content-type: text/html\n'
echo '<!doctype html>
<html>
<head>
<meta charset="utf-8"> <title>'"$BLOGTITLE"' - Index</title>
<link rel="stylesheet" type="text/css" href="styles/'"$STYLESHEET"'">
</head>
<body>
<div id="title"><h1><a href="index.cgi">'"$BLOGTITLE"'</a></h1></div>'
#If the subtitle option is enabled, we show it.
if [ "$SHOWSUBTITLE" = true ]; then
echo '<div id="subtitle"><p>'"$SUBTITLE"'</p></div>'
fi
#If the search option is enabled, we show the search form
if [ "$SHOWSEARCH" = true ]; then
echo '<div id="search"><form action="index.cgi?s=" method="GET">
<input type="text" name="s" placeholder="'"$SEARCHTEXT"'"/>
<input type="submit" value="'"$SEARCHBUTTONTEXT"'">
</form></div>'
fi
echo '<div id="wrapper">'
if [ "$search" = true ]; then
results=$(search "$searchterm")
results=($results)
if [ ${#results[@]} -eq 0 ]; then
echo '<hr><div id="error">No results for found.'
else
echo '<hr>'
for i in ${results[@]}
do
((counter++))
if [ "$counter" -gt "$SHOWPOSTS" ]; then
echo '<a href="/?start=10">Weiter</a>'
break
else
echo '<hr>'
rawnumber=${i%%.md}
rawnumber=${rawnumber##*/}
echo '<h2 class="posttitle"><a href="viewarticle.cgi?article='"$rawnumber"'">'
gettitle "$i"
echo '</a></h2>'
if [ "$SHOWDATE" = true ]; then
echo '<div id="postdate">'
getdate "$i"
echo '</div>'
fi
if [ "$SHOWAUTHOR" = true ]; then
echo '<div id="postauthor"> <br> From '
getauthor "$i"
echo '</div>'
fi
getcontent "$rawnumber"
echo '<hr>'
fi
done
fi
else
for i in $(ls -t "$ARTICLES");
do
((counter++))
if [ "$counter" -gt "$SHOWPOSTS" ]; then
echo '<a href="/?start=10">Weiter</a>'
break
else
echo '<hr>'
currentart="$ARTICLES/$i"
rawnumber=${i%%.md}
rawnumber=${rawnumber##*/}
echo '<h2 class="posttitle"><a href="viewarticle.cgi?article='"$rawnumber"'">'
gettitle "$currentart"
echo '</a></h2>
<p>'
if [ "$SHOWDATE" = true ]; then
echo '<div id="postdate">'
getdate "$currentart"
echo '</div>'
fi
if [ "$SHOWAUTHOR" = true ]; then
echo '<div id="postauthor"> <br> From '
getauthor "$currentart"
echo '</div>'
fi
getcontent "$rawnumber"
echo '<hr>'
fi
done
fi
echo '</div>'
if [ "$SHOWCREDITS" = true ]; then
echo '<div id="credits">Made using <a href="https://github.com/flymia/EzBlog">EzBlog</a>.</div>'
fi
echo '</body>
</html>'