mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge branch 'master' of https://github.com/svetlyak40wt/pelican
This commit is contained in:
commit
7873370583
3 changed files with 20 additions and 12 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
from functools import partial
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import os
|
import os
|
||||||
|
|
@ -114,7 +115,7 @@ class ArticlesGenerator(Generator):
|
||||||
self.settings['TAG_FEED_RSS'] % tag, feed_type='rss')
|
self.settings['TAG_FEED_RSS'] % tag, feed_type='rss')
|
||||||
|
|
||||||
translations_feeds = defaultdict(list)
|
translations_feeds = defaultdict(list)
|
||||||
for article in self.translations:
|
for article in chain(self.articles, self.translations):
|
||||||
translations_feeds[article.lang].append(article)
|
translations_feeds[article.lang].append(article)
|
||||||
|
|
||||||
for lang, items in translations_feeds.items():
|
for lang, items in translations_feeds.items():
|
||||||
|
|
@ -128,7 +129,10 @@ class ArticlesGenerator(Generator):
|
||||||
TODO: change the name"""
|
TODO: change the name"""
|
||||||
|
|
||||||
templates = self.get_templates()
|
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:
|
for template in _DIRECT_TEMPLATES:
|
||||||
write('%s.html' % template, templates[template], self.context,
|
write('%s.html' % template, templates[template], self.context,
|
||||||
blog=True)
|
blog=True)
|
||||||
|
|
@ -223,7 +227,8 @@ class PagesGenerator(Generator):
|
||||||
templates = self.get_templates()
|
templates = self.get_templates()
|
||||||
for page in chain(self.translations, self.pages):
|
for page in chain(self.translations, self.pages):
|
||||||
writer.write_file('pages/%s' % page.save_as, templates['page'],
|
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):
|
class StaticGenerator(Generator):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from docutils import core
|
from docutils import core
|
||||||
from markdown import Markdown
|
from markdown import Markdown
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
|
|
||||||
# import the directives to have pygments support
|
# import the directives to have pygments support
|
||||||
import rstdirectives
|
import rstdirectives
|
||||||
|
|
@ -8,11 +9,11 @@ import rstdirectives
|
||||||
from pelican.utils import get_date, open
|
from pelican.utils import get_date, open
|
||||||
|
|
||||||
|
|
||||||
_METADATAS_FIELDS = {'tags': lambda x: x.split(', '),
|
_METADATAS_PROCESSORS = {
|
||||||
'date': lambda x: get_date(x),
|
'tags': lambda x: map(string.strip, x.split(',')),
|
||||||
'category': lambda x: x,
|
'date': lambda x: get_date(x),
|
||||||
'author': lambda x: x,
|
'status': string.strip,
|
||||||
'status': lambda x:x.strip(),}
|
}
|
||||||
|
|
||||||
|
|
||||||
class RstReader(object):
|
class RstReader(object):
|
||||||
|
|
@ -20,10 +21,11 @@ class RstReader(object):
|
||||||
def _parse_metadata(self, content):
|
def _parse_metadata(self, content):
|
||||||
"""Return the dict containing metadatas"""
|
"""Return the dict containing metadatas"""
|
||||||
output = {}
|
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)
|
name, value = m.group(1).lower(), m.group(2)
|
||||||
if name in _METADATAS_FIELDS:
|
output[name] = _METADATAS_PROCESSORS.get(
|
||||||
output[name] = _METADATAS_FIELDS[name](value)
|
name, lambda x:x
|
||||||
|
)(value)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename):
|
||||||
|
|
@ -51,7 +53,7 @@ class MarkdownReader(object):
|
||||||
metadatas = {}
|
metadatas = {}
|
||||||
for name, value in md.Meta.items():
|
for name, value in md.Meta.items():
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
metadatas[name] = _METADATAS_FIELDS.get(
|
metadatas[name] = _METADATAS_PROCESSORS.get(
|
||||||
name, lambda x:x
|
name, lambda x:x
|
||||||
)(value[0])
|
)(value[0])
|
||||||
return content, metadatas
|
return content, metadatas
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ _DEFAULT_CONFIG = {'PATH': None,
|
||||||
'REVERSE_ARCHIVE_ORDER': False,
|
'REVERSE_ARCHIVE_ORDER': False,
|
||||||
'KEEP_OUTPUT_DIRECTORY': False,
|
'KEEP_OUTPUT_DIRECTORY': False,
|
||||||
'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls
|
'CLEAN_URLS': False, # use /blah/ instead /blah.html in urls
|
||||||
|
'RELATIVE_URLS': True,
|
||||||
'DEFAULT_LANG': 'en',
|
'DEFAULT_LANG': 'en',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue