mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Year and month in URL. Issue #145
This commit is contained in:
parent
6611107e48
commit
068a3d2f1d
4 changed files with 18 additions and 1 deletions
|
|
@ -61,6 +61,10 @@ Setting name (default value) what does it do?
|
||||||
on the output path "static". By default,
|
on the output path "static". By default,
|
||||||
pelican will copy the 'images' folder to the
|
pelican will copy the 'images' folder to the
|
||||||
output folder.
|
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.
|
||||||
================================================ =====================================================
|
================================================ =====================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ from collections import defaultdict
|
||||||
import os
|
import os
|
||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
|
import urlparse
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader, PrefixLoader, ChoiceLoader
|
from jinja2 import Environment, FileSystemLoader, PrefixLoader, ChoiceLoader
|
||||||
from jinja2.exceptions import TemplateNotFound
|
from jinja2.exceptions import TemplateNotFound
|
||||||
|
|
@ -159,6 +160,17 @@ class ArticlesGenerator(Generator):
|
||||||
# in writer, articles pass first
|
# in writer, articles pass first
|
||||||
article_template = self.get_template('article')
|
article_template = self.get_template('article')
|
||||||
for article in chain(self.translations, self.articles):
|
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,
|
write(article.save_as,
|
||||||
article_template, self.context, article=article,
|
article_template, self.context, article=article,
|
||||||
category=article.category)
|
category=article.category)
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ _DEFAULT_CONFIG = {'PATH': None,
|
||||||
'DEFAULT_METADATA': (),
|
'DEFAULT_METADATA': (),
|
||||||
'FILES_TO_COPY': (),
|
'FILES_TO_COPY': (),
|
||||||
'DEFAULT_STATUS': 'published',
|
'DEFAULT_STATUS': 'published',
|
||||||
|
'PERMALINK_STRUCTURE': ''
|
||||||
}
|
}
|
||||||
|
|
||||||
def read_settings(filename):
|
def read_settings(filename):
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section id="content" class="body">
|
<section id="content" class="body">
|
||||||
<article>
|
<article>
|
||||||
<header> <h1 class="entry-title"><a href="{{ article.url }}"
|
<header> <h1 class="entry-title"><a href="{{ pagename }}"
|
||||||
rel="bookmark" title="Permalink to {{ article.title }}">{{ article.title
|
rel="bookmark" title="Permalink to {{ article.title }}">{{ article.title
|
||||||
}}</a></h1> {% include 'twitter.html' %} </header>
|
}}</a></h1> {% include 'twitter.html' %} </header>
|
||||||
<div class="entry-content">
|
<div class="entry-content">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue