diff --git a/docs/settings.rst b/docs/settings.rst index 99899058..ba7ebd72 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -61,10 +61,22 @@ Setting name (default value) what does it do? on the output path "static". By default, pelican will copy the 'images' folder to the output folder. -`PERMALINK_STRUCTURE` (``'/%Y/%m/'``) Allows to render URLs for articles sorted by date, +`ARTICLE_PERMALINK_STRUCTURE` (``'/%Y/%m/'``) Allows to render URLs for articles sorted by date, in case you specify a format as specified in the - example. Also, you can specify any other word - that you want. + example. It follows the python datetime directives: + * %Y: Year with century as a decimal number. + * %m: Month as a decimal number [01,12]. + * %d: Day of the month as a decimal number [01,31]. + + Check the python datetime documentation + at http://bit.ly/cNcJUC for more information. + + Also, you can use any metadata in the + restructured text files: + * category: '%(category)s' + * author: '%(author)s' + * tags: '%(tags)s' + * date: '%(date)s' ================================================ ===================================================== diff --git a/pelican/generators.py b/pelican/generators.py index aafff068..bc2bd574 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -13,6 +13,7 @@ from jinja2 import Environment, FileSystemLoader, PrefixLoader, ChoiceLoader from jinja2.exceptions import TemplateNotFound from pelican.utils import copy, get_relative_path, process_translations, open +from pelican.utils import slugify from pelican.contents import Article, Page, is_valid_content from pelican.readers import read_file from pelican.log import * @@ -161,14 +162,18 @@ class ArticlesGenerator(Generator): article_template = self.get_template('article') for article in chain(self.translations, self.articles): add_to_url = u'' - if self.settings.has_key('PERMALINK_STRUCTURE'): - permalink_structure = self.settings.get('PERMALINK_STRUCTURE') - permalink_structure = permalink_structure.lstrip('/') + if self.settings.has_key('ARTICLE_PERMALINK_STRUCTURE'): + article_permalink_structure = self.settings.get('ARTICLE_PERMALINK_STRUCTURE') + article_permalink_structure = article_permalink_structure.lstrip('/') try: - add_to_url = article.date.strftime(permalink_structure) + add_to_url = article.date.strftime(article_permalink_structure) except: pass + add_to_url = add_to_url % article.__dict__ + add_to_url = [slugify(i) for i in add_to_url.split('/')] + add_to_url = os.path.join(*add_to_url) + article.url = urlparse.urljoin(add_to_url, article.url) article.save_as = urlparse.urljoin(add_to_url, article.save_as) write(article.save_as, diff --git a/pelican/settings.py b/pelican/settings.py index dc87728d..af6b1bd9 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -42,7 +42,7 @@ _DEFAULT_CONFIG = {'PATH': None, 'DEFAULT_METADATA': (), 'FILES_TO_COPY': (), 'DEFAULT_STATUS': 'published', - 'PERMALINK_STRUCTURE': '' + 'ARTICLE_PERMALINK_STRUCTURE': '/%Y/%m/' } def read_settings(filename): diff --git a/samples/pelican.conf.py b/samples/pelican.conf.py index 2796d561..9b074416 100755 --- a/samples/pelican.conf.py +++ b/samples/pelican.conf.py @@ -9,6 +9,9 @@ PDF_GENERATOR = False REVERSE_CATEGORY_ORDER = True LOCALE = "" DEFAULT_PAGINATION = 2 +# Allows to construct an url like /2011/07/sample-post.html +# See documentation for more info. +ARTICLE_PERMALINK_STRUCTURE = '' FEED_RSS = 'feeds/all.rss.xml' CATEGORY_FEED_RSS = 'feeds/%s.rss.xml'