@@ -77,6 +77,8 @@ def handler(req):
77
77
'gitblog.max_age_blob' : '1800' ,
78
78
'gitblog.max_age_tree' : '600' ,
79
79
'gitblog.denied_path' : 'private,templates' ,
80
+ 'gitblog.hidden_path' : 'private,templates,robots.txt' ,
81
+ 'gitblog.direct_path' : 'robots.txt' ,
80
82
'gitblog.redirect_code' : 'HTTP_MOVED_PERMANENTLY' ,
81
83
}
82
84
@@ -94,7 +96,9 @@ def handler(req):
94
96
config ['gitblog.' + c ] = False
95
97
96
98
for c in ['markdown2_extras' ,
97
- 'denied_path' ]:
99
+ 'denied_path' ,
100
+ 'hidden_path' ,
101
+ 'direct_path' ]:
98
102
config ['gitblog.' + c ] = config ['gitblog.' + c ].split (',' )
99
103
100
104
for c in ['max_age_blob' ,
@@ -180,7 +184,7 @@ def handler(req):
180
184
181
185
# Check if resource should NOT be delivered
182
186
for p in config ['gitblog.denied_path' ]:
183
- if p .strip ('/' ) == requested_path [0 :len (p )+ 1 ] :
187
+ if p .strip ('/' ) == '/' . join ( requested_path [0 :len (p )]) :
184
188
return (apache .HTTP_FORBIDDEN )
185
189
186
190
# Read blob object's content
@@ -193,6 +197,14 @@ def handler(req):
193
197
req .write (requested_object .data_stream .read ())
194
198
return (apache .OK )
195
199
200
+ # Check for direct delivery paths
201
+ content = ''
202
+ for p in config ['gitblog.direct_path' ]:
203
+ if p .strip ('/' ) == '/' .join (requested_path [0 :len (p )]):
204
+ req .content_type = requested_object .type
205
+ req .write (requested_object .data_stream .read ())
206
+ return (apache .OK )
207
+
196
208
# Get text blob content
197
209
content = requested_object .data_stream .read ()
198
210
content = content .decode ('utf-8' )
@@ -203,11 +215,27 @@ def handler(req):
203
215
204
216
content = []
205
217
for e in requested_object .trees :
206
- content += [ str ('* [/%s/](/%s/)' % (e .path , e .path )) ]
218
+ hidden = False
219
+ for p in config ['gitblog.hidden_path' ]:
220
+ if p .strip ('/' ) == e .path [0 :len (p )]:
221
+ hidden = True
222
+ break
223
+ if hidden == False :
224
+ content += [ str ('* [/%s/](/%s/)' % (e .path , e .path )) ]
207
225
for e in requested_object .blobs :
208
- content += [ str ('* [/%s](/%s)' % (e .path , e .path )) ]
226
+ hidden = False
227
+ for p in config ['gitblog.hidden_path' ]:
228
+ if p .strip ('/' ) == e .path [0 :len (p )]:
229
+ hidden = True
230
+ break
231
+ if hidden == False :
232
+ content += [ str ('* [/%s](/%s)' % (e .path , e .path )) ]
209
233
content .sort ()
210
- content = '# Directory Tree\n ' + '\n ' .join (content )
234
+
235
+ if config ['gitblog.template_path' ] == '' :
236
+ content = '# Directory Tree\n ' + '\n ' .join (content )
237
+ else :
238
+ content = '\n ' .join (content )
211
239
else :
212
240
return (apache .HTTP_UNSUPPORTED_MEDIA_TYPE )
213
241
except :
@@ -254,11 +282,16 @@ def handler(req):
254
282
# Add templating
255
283
if not config ['gitblog.template_path' ] == '' :
256
284
try :
257
- template = git_obj .tree [config ['gitblog.template_path' ] + '/site.tpl' ].data_stream .read ()
285
+ template_file = 'site.tpl'
286
+ if requested_object .type == 'tree' :
287
+ template_file = 'directory.tpl'
288
+ if len (requested_path ) == 0 :
289
+ template_file = 'home.tpl'
290
+
291
+ template = git_obj .tree [config ['gitblog.template_path' ] + '/' + template_file ].data_stream .read ()
258
292
content = Template (template ).safe_substitute (dict (content = content , footer = footer ))
259
293
except :
260
294
content = content + footer
261
- content = content .encode ('utf-8' )
262
295
263
296
# Return html
264
297
req .headers_out .add ('Content-Type' , 'text/html; charset=UTF-8' )
0 commit comments