mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
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')
|
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):
|
def is_valid_content(content, f):
|
||||||
try:
|
try:
|
||||||
content.check_properties()
|
content.check_properties()
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ class ArticlesGenerator(Generator):
|
||||||
category_template = self.get_template('category')
|
category_template = self.get_template('category')
|
||||||
for cat, articles in self.categories:
|
for cat, articles in self.categories:
|
||||||
dates = [article for article in self.dates if article in articles]
|
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,
|
category=cat, articles=articles, dates=dates,
|
||||||
paginated={'articles': articles, 'dates': dates},
|
paginated={'articles': articles, 'dates': dates},
|
||||||
page_name='category/%s' % cat)
|
page_name='category/%s' % cat)
|
||||||
|
|
@ -228,7 +228,7 @@ class ArticlesGenerator(Generator):
|
||||||
category = os.path.basename(os.path.dirname(f)).decode('utf-8')
|
category = os.path.basename(os.path.dirname(f)).decode('utf-8')
|
||||||
|
|
||||||
if category != '':
|
if category != '':
|
||||||
metadata['category'] = unicode(category)
|
metadata['category'] = Category(category)
|
||||||
|
|
||||||
if 'date' not in metadata.keys()\
|
if 'date' not in metadata.keys()\
|
||||||
and self.settings['FALLBACK_ON_FS_DATE']:
|
and self.settings['FALLBACK_ON_FS_DATE']:
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ except ImportError:
|
||||||
Markdown = False
|
Markdown = False
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from pelican.contents import Category
|
||||||
from pelican.utils import get_date, open
|
from pelican.utils import get_date, open
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,6 +23,7 @@ _METADATA_PROCESSORS = {
|
||||||
'tags': lambda x: map(unicode.strip, unicode(x).split(',')),
|
'tags': lambda x: map(unicode.strip, unicode(x).split(',')),
|
||||||
'date': lambda x: get_date(x),
|
'date': lambda x: get_date(x),
|
||||||
'status': unicode.strip,
|
'status': unicode.strip,
|
||||||
|
'category': Category,
|
||||||
}
|
}
|
||||||
|
|
||||||
def _process_metadata(name, value):
|
def _process_metadata(name, value):
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
By <a class="url fn" href="{{ SITEURL }}/author/{{ article.author }}.html">{{ 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 }}/{{ 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 'taglist.html' %}
|
||||||
{% include 'translations.html' %}
|
{% include 'translations.html' %}
|
||||||
</footer><!-- /.post-info -->
|
</footer><!-- /.post-info -->
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for category, articles in categories %}
|
{% for category, articles in categories %}
|
||||||
<li>{{ category }}</li>
|
<li><a href="{{ category.url }}">{{ category }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for category, articles in categories %}
|
{% for category, articles in categories %}
|
||||||
<li>{{ category }}</li>
|
<li><a href="{{ SITEURL }}/{{ category.url }}">{{ category }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue