Allow definition of custom metadata parsers for Pelican content
Project description
A plugin for Pelican that allows the easy definition of custom metadata parsers.
Install
To install the library, you can use pip
$ pip install pelican-metadataparsing
Usage
Update pelicanconf.py:
Add metadataparsing to PLUGINS.
You should add it before any metadata-affecting plugins.
PLUGINS = [..., 'metadataparsing', ...]
Define your custom metadata parsers through the METADATA_PARSERS setting:
METADATA_PARSERS = { "<metadata-field-name1>": <function parser1(x)>, "<metadata-field-name2>": <function parser2(x)> }
Corresponding fields of the page, article or entity object will have the value returned from the respective parser function.
Example
Gallery Metadata
pelicanconf.py:
import collections
import six
GalleryItem = collections.namedtuple("GalleryItem", ["url", "description"])
def parse_gallery(string):
if string is None or not isinstance(string, collections.Iterable):
return None
if not isinstance(string, six.string_types):
string = '\n'.join(string)
items = []
for line in string.split('\n'):
if not line:
continue
parts = line.split("||")
url = parts[0].strip()
if len(parts) == 1:
description = None
else:
description = parts[1].strip()
items.append(GalleryItem(url, description))
return items
METADATA_PARSERS = {
"Gallery": parse_gallery
}
Theme:
{% if article.gallery %}
<div class="article-gallery">
<h3>Gallery:</h3>
<ul>
{% for image in article.gallery %}
<li>{{ colorbox(image.url, image.description) }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
Multi-line metadata to simple string
import collections
import six
def parse_description(string):
if string is None or isinstance(string, six.string_types):
return string
if isinstance(string, collections.Iterable):
string = " ".join(string)
return string
METADATA_PARSERS = {
"Description": parse_description
}
For a working example check my site and my site’s source code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pelican-metadataparsing-0.1.0.tar.gz
.
File metadata
- Download URL: pelican-metadataparsing-0.1.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a36518c612570882f376ca184c3436ef024b35ea93d56556efbab1277df72ef |
|
MD5 | 6c685ff3ae7205c54ac5beaa1f63518e |
|
BLAKE2b-256 | 4bdb4abf2b78842861d3035b4de94919cd6ac39f7e84a8b5084af251c7934e6a |