mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Create a Author class which has a url property
This commit is contained in:
parent
f9ed01bb64
commit
ff9c786149
6 changed files with 28 additions and 30 deletions
|
|
@ -37,9 +37,9 @@ class Page(object):
|
|||
# default author to the one in settings if not defined
|
||||
if not hasattr(self, 'author'):
|
||||
if 'AUTHOR' in settings:
|
||||
self.author = settings['AUTHOR']
|
||||
self.author = Author(settings['AUTHOR'])
|
||||
else:
|
||||
self.author = getenv('USER', 'John Doe')
|
||||
self.author = Author(getenv('USER', 'John Doe'))
|
||||
warning(u"Author of `{0}' unknow, assuming that his name is `{1}'".format(filename or self.title, self.author))
|
||||
|
||||
# manage languages
|
||||
|
|
@ -142,47 +142,44 @@ class Article(Page):
|
|||
class Quote(Page):
|
||||
base_properties = ('author', 'date')
|
||||
|
||||
|
||||
class Category(object):
|
||||
def __init__(self, category):
|
||||
self.category = unicode(category)
|
||||
class URLWrapper(object):
|
||||
def __init__(self, name):
|
||||
self.name = unicode(name)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.category)
|
||||
return hash(self.name)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.category == unicode(other)
|
||||
return self.name == unicode(other)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.category)
|
||||
return str(self.name)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.category
|
||||
return self.name
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return '%s.html' % self.name
|
||||
|
||||
class Category(URLWrapper):
|
||||
@property
|
||||
def url(self):
|
||||
return 'category/%s.html' % self
|
||||
|
||||
class Tag(object):
|
||||
def __init__(self, tag):
|
||||
self.tag = unicode.strip(tag)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.tag)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.tag == unicode(tag)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.tag)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.tag
|
||||
class Tag(URLWrapper):
|
||||
def __init__(self, name):
|
||||
self.name = unicode.strip(name)
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return 'tag/%s.html' % self
|
||||
|
||||
class Author(URLWrapper):
|
||||
@property
|
||||
def url(self):
|
||||
return 'author/%s.html' % self
|
||||
|
||||
def is_valid_content(content, f):
|
||||
try:
|
||||
content.check_properties()
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ class ArticlesGenerator(Generator):
|
|||
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,
|
||||
write(aut.url, author_template, self.context,
|
||||
author=aut, articles=articles, dates=dates,
|
||||
paginated={'articles': articles, 'dates': dates},
|
||||
page_name='author/%s' % aut)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ except ImportError:
|
|||
Markdown = False
|
||||
import re
|
||||
|
||||
from pelican.contents import Category, Tag
|
||||
from pelican.contents import Category, Tag, Author
|
||||
from pelican.utils import get_date, open
|
||||
|
||||
|
||||
|
|
@ -24,6 +24,7 @@ _METADATA_PROCESSORS = {
|
|||
'date': lambda x: get_date(x),
|
||||
'status': unicode.strip,
|
||||
'category': Category,
|
||||
'author': Author,
|
||||
}
|
||||
|
||||
def _process_metadata(name, value):
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
{% if article.author %}
|
||||
<address class="vcard author">
|
||||
By <a class="url fn" href="{{ SITEURL }}/author/{{ article.author }}.html">{{ article.author }}</a>
|
||||
By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a>
|
||||
</address>
|
||||
{% endif %}
|
||||
<p>In <a href="{{ SITEURL }}/{{ article.category.url }}">{{ article.category }}</a>. {% if PDF_PROCESSOR %}<a href="{{ SITEURL }}/pdf/{{ article.slug }}.pdf">get the pdf</a>{% endif %}</p>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
</abbr>
|
||||
{% if article.author %}
|
||||
<address class="vcard author">
|
||||
By <a class="url fn" href="#">{{ article.author }}</a>
|
||||
By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a>
|
||||
</address>
|
||||
{% endif %}
|
||||
</footer><!-- /.post-info -->
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<header> <h2 class="entry-title"><a href="{{ SITEURL }}/{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title}}">{{ article.title }}</a></h2> </header>
|
||||
<footer class="post-info">
|
||||
<abbr class="published" title="{{ article.date.isoformat() }}"> {{ article.locale_date }} </abbr>
|
||||
{% if article.author %}<address class="vcard author">By <a class="url fn" href="{{ SITEURL }}/author/{{ article.author }}.html">{{ article.author }}</a></address>{% endif %}
|
||||
{% if article.author %}<address class="vcard author">By <a class="url fn" href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a></address>{% endif %}
|
||||
</footer><!-- /.post-info -->
|
||||
<div class="entry-content"> {{ article.summary }} </div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue