forked from github/pelican
Create a Category class which has a url property
This commit is contained in:
parent
2de789325f
commit
6754099730
6 changed files with 27 additions and 5 deletions
|
|
@ -143,6 +143,26 @@ class Quote(Page):
|
|||
base_properties = ('author', 'date')
|
||||
|
||||
|
||||
class Category(object):
|
||||
def __init__(self, category):
|
||||
self.category = unicode(category)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.category)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.category == unicode(other)
|
||||
|
||||
def __str__(self):
|
||||
return str(self.category)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.category
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return 'category/%s.html' % self
|
||||
|
||||
def is_valid_content(content, f):
|
||||
try:
|
||||
content.check_properties()
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ class ArticlesGenerator(Generator):
|
|||
category_template = self.get_template('category')
|
||||
for cat, articles in self.categories:
|
||||
dates = [article for article in self.dates if article in articles]
|
||||
write('category/%s.html' % cat, category_template, self.context,
|
||||
write(cat.url, category_template, self.context,
|
||||
category=cat, articles=articles, dates=dates,
|
||||
paginated={'articles': articles, 'dates': dates},
|
||||
page_name='category/%s' % cat)
|
||||
|
|
@ -228,7 +228,7 @@ class ArticlesGenerator(Generator):
|
|||
category = os.path.basename(os.path.dirname(f)).decode('utf-8')
|
||||
|
||||
if category != '':
|
||||
metadata['category'] = unicode(category)
|
||||
metadata['category'] = Category(category)
|
||||
|
||||
if 'date' not in metadata.keys()\
|
||||
and self.settings['FALLBACK_ON_FS_DATE']:
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ except ImportError:
|
|||
Markdown = False
|
||||
import re
|
||||
|
||||
from pelican.contents import Category
|
||||
from pelican.utils import get_date, open
|
||||
|
||||
|
||||
|
|
@ -22,6 +23,7 @@ _METADATA_PROCESSORS = {
|
|||
'tags': lambda x: map(unicode.strip, unicode(x).split(',')),
|
||||
'date': lambda x: get_date(x),
|
||||
'status': unicode.strip,
|
||||
'category': Category,
|
||||
}
|
||||
|
||||
def _process_metadata(name, value):
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
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>
|
||||
<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>
|
||||
{% include 'taglist.html' %}
|
||||
{% include 'translations.html' %}
|
||||
</footer><!-- /.post-info -->
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
{% block content %}
|
||||
<ul>
|
||||
{% for category, articles in categories %}
|
||||
<li>{{ category }}</li>
|
||||
<li><a href="{{ category.url }}">{{ category }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
{% block content %}
|
||||
<ul>
|
||||
{% for category, articles in categories %}
|
||||
<li>{{ category }}</li>
|
||||
<li><a href="{{ SITEURL }}/{{ category.url }}">{{ category }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue