1
0
Fork 0
forked from github/pelican

Genetare authors pages with all their posts

This commit is contained in:
Massimo Santini 2011-06-30 23:49:09 +02:00
commit d8da5ce590
2 changed files with 17 additions and 3 deletions

18
pelican/generators.py Executable file → Normal file
View file

@ -98,6 +98,7 @@ class ArticlesGenerator(Generator):
self.dates = {}
self.tags = defaultdict(list)
self.categories = defaultdict(list)
self.authors = defaultdict(list)
super(ArticlesGenerator, self).__init__(*args, **kwargs)
self.drafts = []
@ -182,6 +183,14 @@ class ArticlesGenerator(Generator):
paginated={'articles': articles, 'dates': dates},
page_name='category/%s' % cat)
author_template = self.get_template('author')
for aut, articles in self.authors:
dates = [article for article in self.dates if article in articles]
write('author/%s.html' % aut, author_template, self.context,
author=aut, articles=articles, dates=dates,
paginated={'articles': articles, 'dates': dates},
page_name='author/%s' % aut)
for article in self.drafts:
write('drafts/%s.html' % article.slug, article_template, self.context,
article=article, category=article.category)
@ -229,7 +238,7 @@ class ArticlesGenerator(Generator):
for article in self.articles:
# only main articles are listed in categories, not translations
self.categories[article.category].append(article)
self.authors[article.author].append(article)
# sort the articles by date
self.articles.sort(key=attrgetter('date'), reverse=True)
@ -269,7 +278,12 @@ class ArticlesGenerator(Generator):
# order the categories per name
self.categories = list(self.categories.items())
self.categories.sort(reverse=self.settings.get('REVERSE_CATEGORY_ORDER'))
self._update_context(('articles', 'dates', 'tags', 'categories', 'tag_cloud'))
self.authors = list(self.authors.items())
self.authors.sort()
self._update_context(('articles', 'dates', 'tags', 'categories', 'tag_cloud', 'authors'))
def generate_output(self, writer):

View file

@ -5,7 +5,7 @@
{% if article.author %}
<address class="vcard author">
By <a class="url fn" href="#">{{ article.author }}</a>
By <a class="url fn" href="{{ SITEURL }}/author/{{ article.author }}.html">{{ article.author }}</a>
</address>
{% endif %}
<p>In <a href="{{ SITEURL }}/category/{{ article.category }}.html">{{ article.category }}</a>. {% if PDF_PROCESSOR %}<a href="{{ SITEURL }}/pdf/{{ article.slug }}.pdf">get the pdf</a>{% endif %}</p>