From e585c83ac1f3c73f0c0eec3dd6cc61a2a44c4dd5 Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Wed, 18 Aug 2010 16:17:05 +0200 Subject: [PATCH] Get author information from settings if not specified in article's metadata. --- TODO | 1 - pelican/generator.py | 8 ++++++-- samples/test_settings.py | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/TODO b/TODO index d3d5c9ab..12d011b5 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,2 @@ -* Fall back to settings + date of files when no metadata available * Add RSS generation * package it ! diff --git a/pelican/generator.py b/pelican/generator.py index fa9006f7..f54ddf4c 100644 --- a/pelican/generator.py +++ b/pelican/generator.py @@ -51,7 +51,7 @@ def generate_output(path=None, theme=None, output_path=None, markup=None, # for each file, get the informations. for f in files: f = os.path.abspath(f) - article = Article(open(f, encoding='utf-8').read(), markup) + article = Article(open(f, encoding='utf-8').read(), markup, context) articles.append(article) if hasattr(article, 'date'): update_dict(dates, article.date.strftime('%Y-%m-%d'), article) @@ -175,7 +175,7 @@ class Article(object): :param markup: the markup language to use while parsing. """ - def __init__(self, string, markup=None): + def __init__(self, string, markup=None, config={}): if markup == None: markup = 'rst' @@ -189,6 +189,10 @@ class Article(object): self.title = rendered_content.get('title') self.content = rendered_content.get('body') + if not hasattr(self, 'author'): + if 'AUTHOR' in config: + self.author = config['AUTHOR'] + @property def url(self): return '%s.html' % slugify(self.title) diff --git a/samples/test_settings.py b/samples/test_settings.py index fcdb836f..7c0ffd4f 100644 --- a/samples/test_settings.py +++ b/samples/test_settings.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- PATH = 'samples/content' THEME = 'samples/themes/notmyidea' +AUTHOR = u'Alexis Métaireau' BLOGNAME = 'NotMyIdea.org' -BLOGSUBTITLE = u"Alexis Métaireau's weblog" +BLOGSUBTITLE = u"%s's weblog" % AUTHOR BLOGURL = 'http://blog.notmyidea.org' BLOGROLL = (('Biologeek', 'http://biologeek.org'),