This section describe how pelican is working internally. As you’ll see, it’s quite simple, but a bit of documentation doesn’t hurt :)
What pelican does, is taking a list of files, and processing them, to some sort of output. Usually, the files are restructured text and markdown files, and the output is a blog, but it can be anything you want.
I’ve separated the logic in different classes and concepts:
There is an awesome markup language you want to add to pelican ? Well, the only thing you have to do is to create a class that have a read method, that is returning an HTML content and some metadata.
Take a look to the Markdown reader:
class MarkdownReader(Reader):
enabled = bool(Markdown)
def read(self, filename):
"""Parse content and metadata of markdown files"""
text = open(filename)
md = Markdown(extensions = ['meta', 'codehilite'])
content = md.convert(text)
metadata = {}
for name, value in md.Meta.items():
if name in _METADATA_FIELDS:
meta = _METADATA_FIELDS[name](value[0])
else:
meta = value[0]
metadata[name.lower()] = meta
return content, metadata
Simple isn’t it ?
If your new reader requires additional Python dependencies then you should wrap their import statements in try...except. Then inside the reader’s class set the enabled class attribute to mark import success or failure. This makes it possible for users to continue using their favourite markup method without needing to install modules for all the additional formats they don’t use.
Generators have basically two important methods. You’re not forced to create both, only the existing ones will be called.