diff --git a/crunch b/crunch index 629d751..6602059 100755 --- a/crunch +++ b/crunch @@ -14,6 +14,7 @@ import urllib2 import email import smtplib from email.mime.text import MIMEText +from email.Utils import formatdate try: import argparse @@ -71,6 +72,8 @@ if argparse_available: parser.add_argument('--no-http', dest='http', action='store_false', help='Prevents crunch from contacting external sources during the \ build.') + parser.add_argument('--pages', dest='pages', action='store_true', + help='Builds all static pages.') parser.add_argument('--posts', dest='posts', action='store_true', help='Builds all posts.') parser.add_argument('--serve', dest='serve', action='store_true', @@ -109,7 +112,8 @@ else: print 'ERROR: yaml is unavailable, please install and retry.' sys.exit(1) - + +# Define some variables for reuse. build_folder = base_folder + '/' + conf['build_folder'] posts_folder = base_folder + '/' + conf['posts_folder'] public_folder = base_folder + '/' + conf['public_folder'] @@ -129,11 +133,11 @@ class Page: base_url = conf['base_url'] - # return a formatted version of the page using the template function format_layout() + # Return a formatted version of the page using the template function format_layout() def formatted(self): return format_layout(self) - # return an xml formatted version of the page using the template function format_xml() + # Return an xml formatted version of the page using the template function format_xml() def xml(self): return format_xml(self) @@ -163,19 +167,24 @@ class Post: return time.strftime("posted on %Y-%m-%d", self.time) else: return time.strftime("posted on %Y-%m-%d at %I:%M %p", self.time) - + + # Generate a date in a specific format for the RSS feed. def date_2822(self): - return time.strftime("%a, %d %b %Y %H:%M:%S +0000", self.time) + return formatdate(time.mktime(self.time)) + + # Generate a date in the 8601 format. + def date_8601(self): + return time.strftime("%Y-%m-%dT%H:%M:%S", self.time) - # returns the relative url for the post. + # Returns the relative url for the post. def url(self): return '/' + self.year() + '/' + self.month() + '/' + self.slug - # returns the full short url for the post. + # Returns the full short url for the post. def url_short(self): return 'http://amd.im/' + self.short - # parses a string to populate the post object. + # Parses a string to populate the post object. def parse(self, string): header, body = string.split('\n\n', 1) @@ -244,9 +253,7 @@ def format_layout(page): - - - +