pelican-md-metayaml/md_metayaml.py
pR0Ps 67e080a663 Major refactor, bordering on rewrite
- Rename the plugin (md_yaml -> md_metayaml)
- Rework directory structure for easier integration into Pelican
- Change markdown extension libary to a submodule
- Remove ugly path hacks
- Make the reader do less work (leverage the MarkdownReader class)
2015-02-18 12:33:19 -05:00

30 lines
1006 B
Python

from pelican import signals
from pelican.readers import MarkdownReader
from .markdown_metayaml.meta_yaml import MetaYamlExtension
class MarkdownYAMLReader(MarkdownReader):
"""Reader for Markdown files with YAML metadata"""
def __init__(self, *args, **kwargs):
super(MarkdownYAMLReader, self).__init__(*args, **kwargs)
self.extensions.append(MetaYamlExtension())
def _parse_metadata(self, meta):
"""Return the dict containing document metadata"""
# MarkdownReader _parse_metadata() expects a list of length 1
# containing a string of comma-seperated values for authors and tags
for x in ("tags", "authors"):
if x in meta:
meta[x] = [",".join(meta[x])]
return super(MarkdownYAMLReader, self)._parse_metadata(meta)
def add_reader(readers):
for k in MarkdownYAMLReader.file_extensions:
readers.reader_classes[k] = MarkdownYAMLReader
def register():
signals.readers_init.connect(add_reader)