mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Create a Tag class which has a url property
This commit is contained in:
parent
6754099730
commit
f9ed01bb64
4 changed files with 24 additions and 4 deletions
|
|
@ -163,6 +163,26 @@ class Category(object):
|
|||
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
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return 'tag/%s.html' % self
|
||||
|
||||
def is_valid_content(content, f):
|
||||
try:
|
||||
content.check_properties()
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ class ArticlesGenerator(Generator):
|
|||
for tag, articles in self.tags.items():
|
||||
articles.sort(key=attrgetter('date'), reverse=True)
|
||||
dates = [article for article in self.dates if article in articles]
|
||||
write('tag/%s.html' % tag, tag_template, self.context, tag=tag,
|
||||
write(tag.url, tag_template, self.context, tag=tag,
|
||||
articles=articles, dates=dates,
|
||||
paginated={'articles': articles, 'dates': dates},
|
||||
page_name='tag/%s' % tag)
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ except ImportError:
|
|||
Markdown = False
|
||||
import re
|
||||
|
||||
from pelican.contents import Category
|
||||
from pelican.contents import Category, Tag
|
||||
from pelican.utils import get_date, open
|
||||
|
||||
|
||||
_METADATA_PROCESSORS = {
|
||||
'tags': lambda x: map(unicode.strip, unicode(x).split(',')),
|
||||
'tags': lambda x: map(Tag, unicode(x).split(',')),
|
||||
'date': lambda x: get_date(x),
|
||||
'status': unicode.strip,
|
||||
'category': Category,
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
{% if article.tags %}<p>tags: {% for tag in article.tags %}<a href="{{ SITEURL }}/tag/{{ tag }}.html">{{ tag }}</a>{% endfor %}</p>{% endif %}
|
||||
{% if article.tags %}<p>tags: {% for tag in article.tags %}<a href="{{ SITEURL }}/{{ tag.url }}">{{ tag }}</a>{% endfor %}</p>{% endif %}
|
||||
{% if PDF_PROCESSOR %}<p><a href="{{ SITEURL }}/pdf/{{ article.slug }}.pdf">get the pdf</a></p>{% endif %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue