1
0
Fork 0
forked from github/pelican
This commit is contained in:
Alexis Metaireau 2010-12-22 19:07:30 +00:00
commit 7873370583
3 changed files with 20 additions and 12 deletions

View file

@ -1,5 +1,6 @@
from operator import attrgetter
from itertools import chain
from functools import partial
from datetime import datetime
from collections import defaultdict
import os
@ -114,7 +115,7 @@ class ArticlesGenerator(Generator):
self.settings['TAG_FEED_RSS'] % tag, feed_type='rss')
translations_feeds = defaultdict(list)
for article in self.translations:
for article in chain(self.articles, self.translations):
translations_feeds[article.lang].append(article)
for lang, items in translations_feeds.items():
@ -128,7 +129,10 @@ class ArticlesGenerator(Generator):
TODO: change the name"""
templates = self.get_templates()
write = writer.write_file
write = partial(
writer.write_file,
relative_urls = self.settings.get('RELATIVE_URLS')
)
for template in _DIRECT_TEMPLATES:
write('%s.html' % template, templates[template], self.context,
blog=True)
@ -223,7 +227,8 @@ class PagesGenerator(Generator):
templates = self.get_templates()
for page in chain(self.translations, self.pages):
writer.write_file('pages/%s' % page.save_as, templates['page'],
self.context, page=page)
self.context, page=page,
relative_urls = self.settings.get('RELATIVE_URLS'))
class StaticGenerator(Generator):

View file

@ -1,6 +1,7 @@
from docutils import core
from markdown import Markdown
import re
import string
# import the directives to have pygments support
import rstdirectives
@ -8,11 +9,11 @@ import rstdirectives
from pelican.utils import get_date, open
_METADATAS_FIELDS = {'tags': lambda x: x.split(', '),
'date': lambda x: get_date(x),
'category': lambda x: x,
'author': lambda x: x,
'status': lambda x:x.strip(),}
_METADATAS_PROCESSORS = {
'tags': lambda x: map(string.strip, x.split(',')),
'date': lambda x: get_date(x),
'status': string.strip,
}
class RstReader(object):
@ -20,10 +21,11 @@ class RstReader(object):
def _parse_metadata(self, content):
"""Return the dict containing metadatas"""
output = {}
for m in re.compile(':([a-z]+): (.*)\s', re.M).finditer(content):
for m in re.compile('^:([a-z]+): (.*)\s', re.M).finditer(content):
name, value = m.group(1).lower(), m.group(2)
if name in _METADATAS_FIELDS:
output[name] = _METADATAS_FIELDS[name](value)
output[name] = _METADATAS_PROCESSORS.get(
name, lambda x:x
)(value)
return output
def read(self, filename):
@ -51,7 +53,7 @@ class MarkdownReader(object):
metadatas = {}
for name, value in md.Meta.items():
name = name.lower()
metadatas[name] = _METADATAS_FIELDS.get(
metadatas[name] = _METADATAS_PROCESSORS.get(
name, lambda x:x
)(value[0])
return content, metadatas

View file

@ -20,6 +20,7 @@ _DEFAULT_CONFIG = {'PATH': None,
'REVERSE_ARCHIVE_ORDER': False,
'KEEP_OUTPUT_DIRECTORY': False,
'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls
'RELATIVE_URLS': True,
'DEFAULT_LANG': 'en',
}