From f9ed01bb643ab6ad30d06517751f9002568bd0fd Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Thu, 22 Dec 2011 15:43:44 +0000 Subject: [PATCH] Create a Tag class which has a url property --- pelican/contents.py | 20 +++++++++++++++++++ pelican/generators.py | 2 +- pelican/readers.py | 4 ++-- .../themes/notmyidea/templates/taglist.html | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index aab6b330..cca01911 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -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() diff --git a/pelican/generators.py b/pelican/generators.py index 116c0b0b..816a6755 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -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) diff --git a/pelican/readers.py b/pelican/readers.py index 1a62237a..6011c272 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -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, diff --git a/pelican/themes/notmyidea/templates/taglist.html b/pelican/themes/notmyidea/templates/taglist.html index 0f4862d0..c792fd7d 100644 --- a/pelican/themes/notmyidea/templates/taglist.html +++ b/pelican/themes/notmyidea/templates/taglist.html @@ -1,2 +1,2 @@ -{% if article.tags %}

tags: {% for tag in article.tags %}{{ tag }}{% endfor %}

{% endif %} +{% if article.tags %}

tags: {% for tag in article.tags %}{{ tag }}{% endfor %}

{% endif %} {% if PDF_PROCESSOR %}

get the pdf

{% endif %}