4 import os
, time
, datetime
5 from os
.path
import join
, abspath
8 from cfg
import o
, setup_cfg
10 o('-c', '--conf', dest
='conf',
11 help='Configuration file'),
12 o('-r', '--rstdir', dest
='rstdir',
13 help='Directory where source .rst files are found'),
14 o('-t', '--templatedir', dest
='templatedir',
15 help='Directory where mako templates can be found'),
16 o('-b', '--baseurl', dest
='baseurl',
17 help='The base URL of the site'),
18 o('-T', '--title', dest
='title',
19 help='Site title that goes into <title>'),
20 o('', '--regen', dest
='regen', action
="store_true",
21 help='Regenerate the whole site (all files)'),
22 o('-d', '--disqus-forum', dest
='disqus_forum',
23 help='The name of the disqus forum. For example, ' +
24 'if http://foo.disqus.com is the forum, then do --disqus-forum=foo'),
25 o('', '--blog-title', dest
='blog.title',
27 o('', '--blog-subtitle', dest
='blog.subtitle',
31 cfg
['rstdir'] = abspath(cfg
['rstdir'])
32 cfg
['templatedir'] = abspath(cfg
['templatedir'])
34 from util
import make_mako
39 def __init__(self
, rstfile
):
40 parts
, meta
= rst
.process(rstfile
)
42 self
.rstfile
= rstfile
43 self
.title
= parts
['title']
44 self
.fragment
= parts
['fragment']
48 return '%s - %s' % (self
.title
, cfg
['title'])
51 if '|' in self
.meta
['date']:
52 format
= '%Y-%m-%d|%H:%M'
56 return datetime
.datetime(
57 *time
.strptime(self
.meta
['date'],
61 tags
= self
.meta
.get('tags', '').split()
66 path_info
= rst
.htmlpath(self
.rstfile
[len(cfg
['rstdir']):])
67 return cfg
['baseurl'] + path_info
69 def commentable(self
):
77 def commentable(self
):
80 def __cmp__(self
, other
):
81 return cmp(self
.date(), other
.date())
84 return '<BlogPost "%s" on %s>' % (self
.title
, self
.date())
87 if __name__
== '__main__':
88 # Import Psyco if available
95 print '[%s - %s] rstdir:%s [using templatedir:%s]' % (
96 cfg
['baseurl'], cfg
['title'], cfg
['rstdir'], cfg
['templatedir'])
98 rstdir
= cfg
['rstdir']
100 blog_path
= join(rstdir
, 'blog')
102 for f
in rst
.rstfiles(rstdir
):
105 blog_posts
.append(page
)
109 make_mako(rst
.htmlpath(f
),
116 # generate blog index
117 make_mako(join(rstdir
, 'blog', 'index.html'),
118 [p
.rstfile
for p
in blog_posts
],
122 recent_blog_posts
= blog_posts
[:10]
123 make_mako(join(rstdir
, 'blog', 'atom.xml'),
124 [p
.rstfile
for p
in recent_blog_posts
],
125 'blog/atom.xml.mako')