Skip to content
This repository was archived by the owner on Dec 7, 2018. It is now read-only.

Commit 74bfa07

Browse files
committed
Fix denied_path, support direct delivery path and hidden path, separate template types
1 parent 3db4da1 commit 74bfa07

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

gitblog.py

+40-7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def handler(req):
7777
'gitblog.max_age_blob': '1800',
7878
'gitblog.max_age_tree': '600',
7979
'gitblog.denied_path': 'private,templates',
80+
'gitblog.hidden_path': 'private,templates,robots.txt',
81+
'gitblog.direct_path': 'robots.txt',
8082
'gitblog.redirect_code': 'HTTP_MOVED_PERMANENTLY',
8183
}
8284

@@ -94,7 +96,9 @@ def handler(req):
9496
config['gitblog.' + c] = False
9597

9698
for c in ['markdown2_extras',
97-
'denied_path']:
99+
'denied_path',
100+
'hidden_path',
101+
'direct_path']:
98102
config['gitblog.' + c] = config['gitblog.' + c].split(',')
99103

100104
for c in ['max_age_blob',
@@ -180,7 +184,7 @@ def handler(req):
180184

181185
# Check if resource should NOT be delivered
182186
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)]):
184188
return(apache.HTTP_FORBIDDEN)
185189

186190
# Read blob object's content
@@ -193,6 +197,14 @@ def handler(req):
193197
req.write(requested_object.data_stream.read())
194198
return(apache.OK)
195199

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+
196208
# Get text blob content
197209
content = requested_object.data_stream.read()
198210
content = content.decode('utf-8')
@@ -203,11 +215,27 @@ def handler(req):
203215

204216
content = []
205217
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)) ]
207225
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)) ]
209233
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)
211239
else:
212240
return(apache.HTTP_UNSUPPORTED_MEDIA_TYPE)
213241
except:
@@ -254,11 +282,16 @@ def handler(req):
254282
# Add templating
255283
if not config['gitblog.template_path'] == '':
256284
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()
258292
content = Template(template).safe_substitute(dict(content = content, footer = footer))
259293
except:
260294
content = content + footer
261-
content = content.encode('utf-8')
262295

263296
# Return html
264297
req.headers_out.add('Content-Type', 'text/html; charset=UTF-8')

0 commit comments

Comments
 (0)