Permalink
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
Showing with 18 additions and 9 deletions.
  1. +2 −2 pelican/contents.py
  2. +5 −4 pelican/generators.py
  3. +1 −1 pelican/readers.py
  4. +10 −2 pelican/tools/pelican_import.py
View
@@ -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):
return self.name
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."""
View
@@ -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):
continue
# 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
- self.categories[article.category].append(article)
+ for category in article.categories:
+ self.categories[category].append(article)
# ignore blank authors as well as undefined
if hasattr(article,'author') and article.author.name != '':
self.authors[article.author].append(article)
View
@@ -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):
+ os.makedirs(month_dir)
+ out_filename = os.path.join(month_dir, filename+ext)
else:
out_filename = os.path.join(output_path, filename+ext)

0 comments on commit 697c627

Please sign in to comment.