mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #146 from mviera/master
Year and month in URL. Fixes #145
This commit is contained in:
commit
89a48ecb1d
4 changed files with 46 additions and 1 deletions
16
pelican/generators.py
Normal file → Executable file
16
pelican/generators.py
Normal file → Executable file
|
|
@ -7,11 +7,13 @@ from collections import defaultdict
|
|||
import os
|
||||
import math
|
||||
import random
|
||||
import urlparse
|
||||
|
||||
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 *
|
||||
|
|
@ -159,6 +161,20 @@ 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 'ARTICLE_PERMALINK_STRUCTURE' in self.settings:
|
||||
article_permalink_structure = self.settings['ARTICLE_PERMALINK_STRUCTURE']
|
||||
article_permalink_structure = article_permalink_structure.lstrip('/')
|
||||
|
||||
# try to substitute any python datetime directive
|
||||
add_to_url = article.date.strftime(article_permalink_structure)
|
||||
# try to substitute any article metadata in rest file
|
||||
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,
|
||||
article_template, self.context, article=article,
|
||||
category=article.category)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ _DEFAULT_CONFIG = {'PATH': None,
|
|||
'DEFAULT_METADATA': (),
|
||||
'FILES_TO_COPY': (),
|
||||
'DEFAULT_STATUS': 'published',
|
||||
'ARTICLE_PERMALINK_STRUCTURE': ''
|
||||
}
|
||||
|
||||
def read_settings(filename):
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
{% block content %}
|
||||
<section id="content" class="body">
|
||||
<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
|
||||
}}</a></h1> {% include 'twitter.html' %} </header>
|
||||
<div class="entry-content">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue