mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #142 from mapio/master
Added author pages generation
This commit is contained in:
commit
ffbf5016ac
6 changed files with 49 additions and 3 deletions
|
|
@ -20,6 +20,8 @@ To make your own theme, you must follow the following structure::
|
|||
└── templates
|
||||
├── archives.html // to display archives
|
||||
├── article.html // processed for each article
|
||||
├── author.html // processed for each author
|
||||
├── authors.html // must list all the authors
|
||||
├── categories.html // must list all the categories
|
||||
├── category.html // processed for each category
|
||||
├── index.html // the index. List all the articles
|
||||
|
|
@ -85,6 +87,32 @@ dates_page The current page of articles, ordered by date,
|
|||
page_name 'index'. Useful for pagination links.
|
||||
=================== ===================================================
|
||||
|
||||
author.html
|
||||
-------------
|
||||
|
||||
This template will be processed for each of the existing authors, and will
|
||||
finally remain at output/author/`author_name`.html.
|
||||
|
||||
If pagination is active, next pages will remain at
|
||||
output/author/`author_name``n`.html.
|
||||
|
||||
=================== ===================================================
|
||||
Variable Description
|
||||
=================== ===================================================
|
||||
author The name of the author being processed.
|
||||
articles Articles of this author.
|
||||
dates Articles of this author, but ordered by date,
|
||||
ascending.
|
||||
articles_paginator A paginator object of article list.
|
||||
articles_page The current page of articles.
|
||||
dates_paginator A paginator object of article list, ordered by date,
|
||||
ascending.
|
||||
dates_page The current page of articles, ordered by date,
|
||||
ascending.
|
||||
page_name 'author/`author_name`'. Useful for pagination
|
||||
links.
|
||||
=================== ===================================================
|
||||
|
||||
category.html
|
||||
-------------
|
||||
|
||||
|
|
|
|||
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.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):
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
2
pelican/themes/notmyidea/templates/author.html
Normal file
2
pelican/themes/notmyidea/templates/author.html
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
{% extends "index.html" %}
|
||||
{% block title %}{{ SITENAME }} - {{ author }}{% endblock %}
|
||||
0
pelican/themes/notmyidea/templates/authors.html
Normal file
0
pelican/themes/notmyidea/templates/authors.html
Normal file
|
|
@ -1,3 +1,4 @@
|
|||
{% if WITH_PAGINATION %}
|
||||
<p class="paginator">
|
||||
{% if articles_page.has_previous() %}
|
||||
{% if articles_page.previous_page_number() == 1 %}
|
||||
|
|
@ -11,3 +12,4 @@
|
|||
<a href="{{ SITEURL }}/{{ page_name }}{{ articles_page.next_page_number() }}.html">»</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue