diff --git a/docs/settings.rst b/docs/settings.rst index 7eb1b12a..99899058 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -61,6 +61,10 @@ 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, + in case you specify a format as specified in the + example. Also, you can specify any other word + that you want. ================================================ ===================================================== diff --git a/pelican/generators.py b/pelican/generators.py index d91283f3..aafff068 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -7,6 +7,7 @@ from collections import defaultdict import os import math import random +import urlparse from jinja2 import Environment, FileSystemLoader, PrefixLoader, ChoiceLoader from jinja2.exceptions import TemplateNotFound @@ -159,6 +160,17 @@ class ArticlesGenerator(Generator): # in writer, articles pass first 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('/') + try: + add_to_url = article.date.strftime(permalink_structure) + except: + pass + + article.url = urlparse.urljoin(add_to_url, article.url) + article.save_as = urlparse.urljoin(add_to_url, article.save_as) write(article.save_as, article_template, self.context, article=article, category=article.category) diff --git a/pelican/settings.py b/pelican/settings.py index 125d0bb0..dc87728d 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -42,6 +42,7 @@ _DEFAULT_CONFIG = {'PATH': None, 'DEFAULT_METADATA': (), 'FILES_TO_COPY': (), 'DEFAULT_STATUS': 'published', + 'PERMALINK_STRUCTURE': '' } def read_settings(filename): diff --git a/pelican/themes/notmyidea/templates/article.html b/pelican/themes/notmyidea/templates/article.html index 14fffe4d..6615b63a 100644 --- a/pelican/themes/notmyidea/templates/article.html +++ b/pelican/themes/notmyidea/templates/article.html @@ -3,7 +3,7 @@ {% block content %}
-

{{ article.title }}

{% include 'twitter.html' %}