52
52
# Output formatting
53
53
from markdown2 import markdown
54
54
from BeautifulSoup import BeautifulSoup
55
+ from string import Template
55
56
56
57
# Available output text encodings (request parameter key => output format)
57
58
available_output_type = { 'html' : 'html' ,
@@ -67,6 +68,7 @@ def handler(req):
67
68
config = {
68
69
'gitblog.report_errors' : 'False' ,
69
70
'gitblog.www_repo' : '/dev/null' ,
71
+ 'gitblog.template_path' : 'templates' ,
70
72
'gitblog.default_ref' : 'HEAD' ,
71
73
'gitblog.default_output_type' : 'html' ,
72
74
'gitblog.footer' : 'True' ,
@@ -220,10 +222,10 @@ def handler(req):
220
222
for i , l in enumerate (requested_path [0 :- 1 ]):
221
223
breadcrumb += '[%s](/%s)/' % (l , '/' .join (requested_path [:i + 1 ]))
222
224
223
- content + = '\n \n ---\n '
225
+ footer = '\n \n ---\n '
224
226
if not output_type == 'plain' :
225
- content += '[Home](/) - '
226
- content += '%s%s - Updated on %s by %s - Git Reference [%s](?ref=%s)\n ' % \
227
+ footer += '[Home](/) - '
228
+ footer += '%s%s - Updated on %s by %s - Git Reference [%s](?ref=%s)\n ' % \
227
229
(breadcrumb , last_path_entry ,
228
230
datetime .fromtimestamp (git_obj .committed_date ).strftime (
229
231
config ['gitblog.date_format' ]),
@@ -233,25 +235,35 @@ def handler(req):
233
235
# Return markdown
234
236
if output_type == 'markdown' :
235
237
req .headers_out .add ('Content-Type' , 'text/markdown; charset=UTF-8' )
236
- req .headers_out .add ('Content-Length' , str (len (content )))
237
- req .write (content )
238
+ req .headers_out .add ('Content-Length' , str (len (content ) + len ( footer ) ))
239
+ req .write (content + footer )
238
240
return (apache .OK )
239
241
240
242
# Convert markdown to html
241
243
content = markdown (content , extras = config ['gitblog.markdown2_extras' ])
244
+ footer = markdown (footer , extras = config ['gitblog.markdown2_extras' ])
242
245
243
246
# Return plain
244
247
if output_type == 'plain' :
245
248
content = '' .join (BeautifulSoup (content ).findAll (text = True ))
246
249
req .headers_out .add ('Content-Type' , 'text/plain; charset=UTF-8' )
247
- req .headers_out .add ('Content-Length' , str (len (content )))
248
- req .write (content )
250
+ req .headers_out .add ('Content-Length' , str (len (content ) + len ( footer ) ))
251
+ req .write (content + footer )
249
252
return (apache .OK )
250
253
254
+ # Add templating
255
+ if not config ['gitblog.template_path' ] == '' :
256
+ try :
257
+ template = git_obj .tree [config ['gitblog.template_path' ] + '/site.tpl' ].data_stream .read ()
258
+ content = Template (template ).safe_substitute (dict (content = content , footer = footer ))
259
+ except :
260
+ content = content + footer
261
+ content = content .encode ('utf-8' )
262
+
251
263
# Return html
252
264
req .headers_out .add ('Content-Type' , 'text/html; charset=UTF-8' )
253
265
req .headers_out .add ('Content-Length' , str (len (content )))
254
- req .write (content . encode ( 'utf-8' ) )
266
+ req .write (content )
255
267
return (apache .OK )
256
268
257
269
# vim: set syntax=python tabstop=4 expandtab:
0 commit comments