mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Fixed tags parsing, now it can parse tags like this "blah,minor, foo , bar". Also, code for metadata parsing was slightly refactored.
This commit is contained in:
parent
750e211649
commit
558038be32
1 changed files with 11 additions and 9 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue