Usable, albeit slightly hackish, solution for YAML metadata.
This commit is contained in:
parent
e078420af2
commit
0afed4a026
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from pelican import signals
|
from pelican import signals
|
||||||
@ -8,6 +9,7 @@ try:
|
|||||||
import yaml
|
import yaml
|
||||||
except ImportError:
|
except ImportError:
|
||||||
yaml = None
|
yaml = None
|
||||||
|
logging.warning("YAML is not installed; the YAML reader will not work.")
|
||||||
|
|
||||||
|
|
||||||
class PandocReader(BaseReader):
|
class PandocReader(BaseReader):
|
||||||
@ -21,25 +23,25 @@ class PandocReader(BaseReader):
|
|||||||
if use_YAML:
|
if use_YAML:
|
||||||
# Load the data we need to parse
|
# Load the data we need to parse
|
||||||
to_parse = []
|
to_parse = []
|
||||||
text = text[1:]
|
for i, line in enumerate(text[1:]):
|
||||||
for i, line in enumerate(text):
|
|
||||||
# When we find a terminator (`---` or `...`), stop.
|
# When we find a terminator (`---` or `...`), stop.
|
||||||
if line == '---' or line == '...':
|
if line in ('---', '...'):
|
||||||
# Do not include the terminator itself.
|
# Do not include the terminator itself.
|
||||||
content = "\n".join(text[i+1:])
|
|
||||||
break
|
break
|
||||||
|
|
||||||
# Otherwise, just keep adding the lines to the parseable.
|
# Otherwise, just keep adding the lines to the parseable.
|
||||||
to_parse.append(line)
|
to_parse.append(line)
|
||||||
|
|
||||||
to_parse = "\n".join(to_parse)
|
parsed = yaml.load("\n".join(to_parse))
|
||||||
parsed = yaml.load(to_parse)
|
|
||||||
|
|
||||||
# Postprocess to make the data usable by Pelican.
|
# Postprocess to make the data usable by Pelican.
|
||||||
for k in parsed:
|
for k in parsed:
|
||||||
name, value = k.lower(), str(parsed[k]).strip()
|
name, value = k.lower(), parsed[k]
|
||||||
metadata[name] = self.process_metadata(name, value)
|
metadata[name] = self.process_metadata(name, value)
|
||||||
|
|
||||||
|
# Return the text entirely.
|
||||||
|
content = "\n".join(text)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for i, line in enumerate(text):
|
for i, line in enumerate(text):
|
||||||
kv = line.split(':', 1)
|
kv = line.split(':', 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user