commit 7736a9cc2f38502cc149fa7d0e7a26ff1d307a9e
parent 089ccc0264bbab059e88ce6f593893f88969c611
Author: Dan Callaghan <djc@djc.id.au>
Date: Thu, 5 Jun 2008 23:45:47 +1000
better handling of absent tags/categories
committer: Dan Callaghan <djc@djc.id.au>
--HG--
extra : convert_revision : f2526e4a2e18f56391e0b323093e987e5ec32656
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/blog.py b/blog.py
@@ -44,8 +44,16 @@ class Entry(object):
self.metadata = cleanup_metadata(md.Meta)
self.title = self.metadata['title']
- self.categories = [cat.strip() for cat in self.metadata.get('categories', '').split(',')]
- self.tags = [tag.strip() for tag in self.metadata.get('tags', '').split(',')]
+ raw_cats = self.metadata.get('categories', '').strip()
+ if raw_cats:
+ self.categories = [cat.strip() for cat in raw_cats.split(',')]
+ else:
+ self.categories = []
+ raw_tags = self.metadata.get('tags', '').strip()
+ if raw_tags:
+ self.tags = [tag.strip() for tag in raw_tags.split(',')]
+ else:
+ self.tags = []
self.modified_date = datetime.fromtimestamp(os.path.getmtime(os.path.join(self.dir, 'content.txt')))
self.publication_date = self.metadata.get('publication-date', None) or self.modified_date