From 4144c8d76f473fc062082fc6529fb418f7dcf5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88kull=20So=CC=81lberg=20Au=C3=B0unsson?= Date: Wed, 23 Nov 2011 20:35:18 +0000 Subject: [PATCH 1/4] More forgiving date strings. --- pelican/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index cd7507ee..27159a89 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -17,8 +17,12 @@ def get_date(string): If no format matches the given date, raise a ValuEerror """ - formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M', '%Y-%m-%d', '%Y/%m/%d', - '%d/%m/%Y', '%d.%m.%Y', '%d.%m.%Y %H:%M', '%Y-%m-%d %H:%M:%S'] + string = re.sub(' +', ' ', string) + formats = ['%Y-%m-%d %H:%M', '%Y/%m/%d %H:%M', + '%Y-%m-%d', '%Y/%m/%d', + '%d-%m-%Y', '%Y-%d-%m', # Weird ones + '%d/%m/%Y', '%d.%m.%Y', + '%d.%m.%Y %H:%M', '%Y-%m-%d %H:%M:%S'] for date_format in formats: try: return datetime.strptime(string, date_format) From 499a67912fbc40a9402803881f6250d5a6eb2d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88kull=20So=CC=81lberg=20Au=C3=B0unsson?= Date: Wed, 23 Nov 2011 20:35:45 +0000 Subject: [PATCH 2/4] Never fail on generating posts, just skip and log exception. --- pelican/generators.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index f375011f..77fe55a7 100755 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -211,7 +211,12 @@ class ArticlesGenerator(Generator): files = self.get_files(self.path, exclude=['pages',]) all_articles = [] for f in files: - content, metadata = read_file(f, settings=self.settings) + + try: + content, metadata = read_file(f, settings=self.settings) + except Exception, e: + warning(u'Could not process %s\n%s' % (f, str(e))) + continue # if no category is set, use the name of the path as a category if 'category' not in metadata.keys(): @@ -324,7 +329,11 @@ class PagesGenerator(Generator): def generate_context(self): all_pages = [] for f in self.get_files(os.sep.join((self.path, 'pages'))): - content, metadata = read_file(f) + try: + content, metadata = read_file(f) + except Exception, e: + error(u'Could not process %s\n%s' % (filename, str(e))) + continue page = Page(content, metadata, settings=self.settings, filename=f) if not is_valid_content(page, f): From 082cc2a401ba4b6697e2ba8fa8aaf95c3c29b2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88kull=20So=CC=81lberg=20Au=C3=B0unsson?= Date: Sat, 26 Nov 2011 22:31:43 +0000 Subject: [PATCH 3/4] Warning string formatting needs unicode if filename is utf-8 --- pelican/contents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/contents.py b/pelican/contents.py index ddcb37b6..1587a1eb 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -38,7 +38,7 @@ class Page(object): self.author = settings['AUTHOR'] else: self.author = getenv('USER', 'John Doe') - warning("Author of `{0}' unknow, assuming that his name is `{1}'".format(filename or self.title, self.author).decode("utf-8")) + warning(u"Author of `{0}' unknow, assuming that his name is `{1}'".format(filename or self.title, self.author)) # manage languages self.in_default_lang = True From dc22d2b1310b9ac6afc8669640dea9ee965e94e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88kull=20So=CC=81lberg=20Au=C3=B0unsson?= Date: Sat, 26 Nov 2011 23:23:19 +0000 Subject: [PATCH 4/4] Added WITH_FUTURE_DATES settings, which if true treats future dated content as drafts. --- pelican/contents.py | 8 +++++--- pelican/settings.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index 1587a1eb..9c2327d4 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -2,6 +2,7 @@ from pelican.utils import slugify, truncate_html_words from pelican.log import * from pelican.settings import _DEFAULT_CONFIG +from datetime import datetime from os import getenv from sys import platform, stdin @@ -23,8 +24,6 @@ class Page(object): self._content = content self.translations = [] - self.status = "published" # default value - local_metadata = dict(settings.get('DEFAULT_METADATA', ())) local_metadata.update(metadata) @@ -87,7 +86,10 @@ class Page(object): # manage status if not hasattr(self, 'status'): self.status = settings['DEFAULT_STATUS'] - + if not settings['WITH_FUTURE_DATES']: + if hasattr(self, 'date') and self.date > datetime.now(): + self.status = 'draft' + # set summary if not hasattr(self, 'summary'): self.summary = truncate_html_words(self.content, 50) diff --git a/pelican/settings.py b/pelican/settings.py index c7ac35ff..f74e085d 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -21,6 +21,7 @@ _DEFAULT_CONFIG = {'PATH': None, 'PDF_GENERATOR': False, 'DEFAULT_CATEGORY': 'misc', 'FALLBACK_ON_FS_DATE': True, + 'WITH_FUTURE_DATES': True, 'CSS_FILE': 'main.css', 'REVERSE_ARCHIVE_ORDER': False, 'REVERSE_CATEGORY_ORDER': False,