├── .gitignore ├── __init__.py ├── .gitmodules ├── md_metayaml.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *.py[cod] 3 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | from .md_metayaml import * 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "markdown_metayaml"] 2 | path = markdown_metayaml 3 | url = https://github.com/joachimneu/python-markdown-yaml-meta-data.git 4 | -------------------------------------------------------------------------------- /md_metayaml.py: -------------------------------------------------------------------------------- 1 | from pelican import signals 2 | from pelican.readers import MarkdownReader 3 | 4 | from .markdown_metayaml.meta_yaml import MetaYamlExtension 5 | 6 | class MarkdownYAMLReader(MarkdownReader): 7 | """Reader for Markdown files with YAML metadata""" 8 | 9 | def __init__(self, *args, **kwargs): 10 | super(MarkdownYAMLReader, self).__init__(*args, **kwargs) 11 | self.settings['MARKDOWN']['extensions'].append(MetaYamlExtension()) 12 | 13 | def _parse_metadata(self, meta): 14 | """Return the dict containing document metadata""" 15 | 16 | # MarkdownReader _parse_metadata() expects a list of length 1 17 | # containing a string of comma-seperated values for authors and tags 18 | for x in ("tags", "authors"): 19 | if x in meta: 20 | meta[x] = [",".join(meta[x])] 21 | 22 | return super(MarkdownYAMLReader, self)._parse_metadata(meta) 23 | 24 | def add_reader(readers): 25 | for k in MarkdownYAMLReader.file_extensions: 26 | readers.reader_classes[k] = MarkdownYAMLReader 27 | 28 | def register(): 29 | signals.readers_init.connect(add_reader) 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pelican-md-metayaml 2 | =================== 3 | 4 | This [Pelican](https://github.com/getpelican/pelican) plugin adds a reader for Markdown files with [YAML](https://en.wikipedia.org/wiki/YAML) metadata. 5 | As the well-known static site generator [Jekyll](https://github.com/jekyll/jekyll) uses Markdown files with YAML metadata, this eases migration from Jekyll to Pelican. 6 | Also, YAML metadata allows for easier specification of more complex metadata, such as nested lists or dictionaries. 7 | 8 | Dependencies 9 | ------------ 10 | 11 | (to be installed via `pip`) 12 | 13 | * [`Markdown`](https://pypi.python.org/pypi/Markdown) 14 | * [`PyYAML`](https://pypi.python.org/pypi/PyYAML) 15 | 16 | Installation 17 | ------------ 18 | 19 | Clone this repo (and its submodules) into a `pelican-md-metayaml` directory inside the `plugins` directory of your Pelican project (or whatever directory you specified for plugins in Pelican's `PLUGIN_PATHS` setting) and add `'pelican-md-metayaml'` to the list of plugins (Pelican setting `PLUGINS`) of your project. Or just use it as part of [`pelican-plugins`](https://github.com/getpelican/pelican-plugins). 20 | 21 | To make sure the submodule is included, use `git clone --recursive [repo] [path]`. 22 | Alternatively, clone without `--recursive`, then run `git submodule update --init` to checkout the submodule. 23 | 24 | Usage 25 | ----- 26 | 27 | All your Markdown files (ending in `.md`, `.markdown`, `.mkd` and `.mdown`) will now be interpreted as using YAML for their metadata. 28 | 29 | The following example shows a very simple article (only one line of text at the bottom) but with quite complex metadata (everything between the `---`): 30 | 31 | ``` 32 | --- 33 | title: Some title 34 | author: Some person 35 | tags: 36 | - tag 1 37 | - tag 2 38 | date: 2014-12-25 00:00 39 | data: 40 | - name: some name 41 | options: 42 | - opt 1 43 | - opt 2 44 | - opt 3 45 | steps: 46 | - Step 1 47 | - Step 2 48 | - Step 3 49 | --- 50 | 51 | This is the only text in the article. 52 | ``` 53 | --------------------------------------------------------------------------------