Skip to content
Browse files
Added support for multiple categories, WARNING: this will break the
current themes, just did it because I needed it.
  • Loading branch information
fitoria committed Jan 6, 2013
1 parent 355842c commit 697c6271d5193aa3b63788848b127a7596ba2a43
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
@@ -236,7 +236,7 @@ def relative_dir(self):

class Article(Page):
mandatory_properties = ('title', 'date', 'category')
mandatory_properties = ('title', 'date', 'categories')
default_template = 'article'

@@ -266,7 +266,7 @@ def __unicode__(self):

def _from_settings(self, key, get_page_name=False):
"""Returns URL information as defined in settings.
"""Returns URL information as defined in settings.
When get_page_name=True returns URL without anything after {slug}
e.g. if in settings: CATEGORY_URL="cat/{slug}.html" this returns "cat/{slug}"
Useful for pagination."""
@@ -238,7 +238,7 @@ def generate_articles(self, write):
"""Generate the articles."""
for article in chain(self.translations, self.articles):
write(article.save_as, self.get_template(article.template),
self.context, article=article, category=article.category)
self.context, article=article, categories=article.categories)

def generate_direct_templates(self, write):
"""Generate direct templates pages"""
@@ -328,7 +328,7 @@ def generate_context(self):

# if no category is set, use the name of the path as a category
if 'category' not in metadata:
if 'categories' not in metadata:

if (self.settings['USE_FOLDER_AS_CATEGORY']
and os.path.dirname(f) != article_path):
@@ -340,7 +340,7 @@ def generate_context(self):
category = self.settings['DEFAULT_CATEGORY']

if category != '':
metadata['category'] = Category(category, self.settings)
metadata['categories'] = [Category(category, self.settings)]

if 'date' not in metadata and self.settings.get('DEFAULT_DATE'):
if self.settings['DEFAULT_DATE'] == 'fs':
@@ -374,7 +374,8 @@ def generate_context(self):

for article in self.articles:
# only main articles are listed in categories, not translations
for category in article.categories:
# ignore blank authors as well as undefined
if hasattr(article,'author') and != '':
@@ -29,7 +29,7 @@
'tags': lambda x, y: [Tag(tag, y) for tag in unicode(x).split(',')],
'date': lambda x, y: get_date(x),
'status': lambda x, y: unicode.strip(x),
'category': Category,
'categories': lambda x, y: [Category(cat, y) for cat in unicode(x).split(',')],
'author': Author,

@@ -203,9 +203,10 @@ def build_markdown_header(title, date, author, categories, tags, slug):
if date:
header += 'Date: %s\n' % date
if author:
header += 'Author: %s\n' % author
#header += 'Author: %s\n' % author
header += 'Author: fitoria\n'
if categories:
header += 'Category: %s\n' % ', '.join(categories)
header += 'Categories: %s\n' % ','.join(categories)
if tags:
header += 'Tags: %s\n' % ', '.join(tags)
if slug:
@@ -226,12 +227,19 @@ def fields2pelican(fields, out_markup, output_path, dircat=False, strip_raw=Fals

filename = os.path.basename(filename)

year, month = date.split('-')[:2]

# option to put files in directories with categories names
if dircat and (len(categories) > 0):
catname = slugify(categories[0])
out_filename = os.path.join(output_path, catname, filename+ext)
if not os.path.isdir(os.path.join(output_path, catname)):
os.mkdir(os.path.join(output_path, catname))
elif year and month:
month_dir = os.path.join(output_path, year, month)
if not os.path.exists(month_dir):
out_filename = os.path.join(month_dir, filename+ext)
out_filename = os.path.join(output_path, filename+ext)

0 comments on commit 697c627

Please sign in to comment.