Docs » Pelican internals
Pelican internals
This section describe how Pelican works internally. As you’ll see, it’s quite simple, but a bit of documentation doesn’t hurt. :)
You can also find in the Some history about Pelican section an excerpt of a report the original author wrote with some software design information.
Overall structure
What Pelican does is take a list of files and process them into some sort of output. Usually, the input files are reStructuredText and Markdown files, and the output is a blog, but both input and output can be anything you want.
The logic is separated into different classes and concepts:
How to implement a new reader?
Is there an awesome markup language you want to add to Pelican? Well, the only thing you have to do is to create a class with a read method that returns HTML content and some metadata.
Take a look at the Markdown reader:
from pelican.readers import BaseReaderfrom pelican.utils import pelican_openfrom markdown import Markdownclass MarkdownReader​(​BaseReader​): enabled = True def read(self, source_path): """Parse content and metadata of markdown files""" with pelican_open(source_path) as text: md_extensions = {'markdown.extensions.meta': {}, 'markdown.extensions.codehilite'​: {}} md = Markdown​(​extensions​=​md_extensions​.​keys​(), extension_configs​=​md_extensions​) content = md.convert(text) metadata = {} for name, value in md.Meta.items(): name = name.lower() meta = self​.​process_metadata​(​name​, value[0]) metadata[name] = meta return content, metadata
Simple, isn’t it?
If your new reader requires additional Python dependencies, then you should wrap their import statements in a try...except block. 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 formats they don’t use.
How to implement a new generator?
Generators have two important methods. You’re not forced to create both; only the existing ones will be called.
DigitalOcean Managed MongoDB a fully managed DBaaS for modern apps. Try now with $100 credit.
Ad by EthicalAds   ·   Monetize your site
© Copyright 2010 – present, Justin Mayer, Alexis Metaireau, and contributors Revision 11633992.
Built with Sphinx using a theme provided by Read the Docs.
Pelican QuickstartInstalling PelicanWriting contentPublish your siteSettingsPluginsThemespelican-themesImporting an existing siteFrequently Asked Questions (FAQ)TipsContributing and feedback guidelinesOverall structureHow to implement a new reader?How to implement a new generator?Some history about PelicanRelease history