mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Genetare authors pages with all their posts
This commit is contained in:
parent
0a26fcbd0d
commit
d8da5ce590
2 changed files with 17 additions and 3 deletions
18
pelican/generators.py
Executable file → Normal file
18
pelican/generators.py
Executable file → Normal file
|
|
@ -98,6 +98,7 @@ class ArticlesGenerator(Generator):
|
||||||
self.dates = {}
|
self.dates = {}
|
||||||
self.tags = defaultdict(list)
|
self.tags = defaultdict(list)
|
||||||
self.categories = defaultdict(list)
|
self.categories = defaultdict(list)
|
||||||
|
self.authors = defaultdict(list)
|
||||||
super(ArticlesGenerator, self).__init__(*args, **kwargs)
|
super(ArticlesGenerator, self).__init__(*args, **kwargs)
|
||||||
self.drafts = []
|
self.drafts = []
|
||||||
|
|
||||||
|
|
@ -182,6 +183,14 @@ class ArticlesGenerator(Generator):
|
||||||
paginated={'articles': articles, 'dates': dates},
|
paginated={'articles': articles, 'dates': dates},
|
||||||
page_name='category/%s' % cat)
|
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:
|
for article in self.drafts:
|
||||||
write('drafts/%s.html' % article.slug, article_template, self.context,
|
write('drafts/%s.html' % article.slug, article_template, self.context,
|
||||||
article=article, category=article.category)
|
article=article, category=article.category)
|
||||||
|
|
@ -229,7 +238,7 @@ class ArticlesGenerator(Generator):
|
||||||
for article in self.articles:
|
for article in self.articles:
|
||||||
# only main articles are listed in categories, not translations
|
# only main articles are listed in categories, not translations
|
||||||
self.categories[article.category].append(article)
|
self.categories[article.category].append(article)
|
||||||
|
self.authors[article.author].append(article)
|
||||||
|
|
||||||
# sort the articles by date
|
# sort the articles by date
|
||||||
self.articles.sort(key=attrgetter('date'), reverse=True)
|
self.articles.sort(key=attrgetter('date'), reverse=True)
|
||||||
|
|
@ -269,7 +278,12 @@ class ArticlesGenerator(Generator):
|
||||||
# order the categories per name
|
# order the categories per name
|
||||||
self.categories = list(self.categories.items())
|
self.categories = list(self.categories.items())
|
||||||
self.categories.sort(reverse=self.settings.get('REVERSE_CATEGORY_ORDER'))
|
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):
|
def generate_output(self, writer):
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
{% if article.author %}
|
{% if article.author %}
|
||||||
<address class="vcard 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>
|
</address>
|
||||||
{% endif %}
|
{% 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>
|
<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>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue