From charlesreid1

This page contains some examples of Pelican configuration files to go beyond the basics.

Group Apps Into Directories

If you have a Pelican page that is serving up an app, or multiple apps, and you want to structure your directory such that all files related to the app are contained in their own, separate directory, you can accomplish this as follows:

  • Add the separate directory containing app files to the EXTRA_TEMPLATE_PATHS list in pelicanconf.py
  • Add any pages or files that you wish to put in the final static content folder by adding it to the TEMPLATE_PAGES dictionary in pelicanconf.py
  • Repeat as needed for any additional apps

Here is an example of what that might look like:

# projects
EXTRA_TEMPLATES_PATHS.append('projects')
TEMPLATE_PAGES['projects.html'] = 'projects/index.html'
TEMPLATE_PAGES['projects.json'] = 'projects/projects.json'
TEMPLATE_PAGES['projects.css']  = 'projects/projects.css'
TEMPLATE_PAGES['projects_modcontrol.js'] = 'projects/projects_modcontrol.js'
 
# about
EXTRA_TEMPLATES_PATHS.append('about')
TEMPLATE_PAGES['about.html'] = 'about/index.html'
TEMPLATE_PAGES['about.css']  = 'about/about.css'
TEMPLATE_PAGES['about.json'] = 'about/about.json'
TEMPLATE_PAGES['about_modcontrol.js'] = 'about/about_modcontrol.js'

Use Environment Variables

If you need to use environment variables, use the os.environ submodule:

import os

[...]

HOME = os.environ.get('HOME')
PLUGIN_PATHS = [HOME+'/codes/pelican-plugins/']
PLUGINS = ['render_math']

Set Timestamp Style

If you are using a theme that contains pages with date/time stamps, you may want to customize the timestamps without messing with the original template. To do this, you can specify a date and time stamp style in pelicanconf.py:

# time formats for blog
DATE_FORMATS = {'en': '%A %m/%d/%Y',}

# month formatting filter for blog
from datetime import datetime
def int_to_month (m_int):
    """Turns an integer month into a long month."""
    d = datetime(year=2014, day=1, month=m_int)
    return d.strftime("%B")

JINJA_FILTERS = {'month_name':int_to_month}


Flags