Pelican Quick Reference

Installing Pelican and dependencies

(venv) $ pip install pelican[Markdown]
(venv) $ pip install beautifulsoup4 # use by some plugins
(venv) $ pip install ghp-import # publish to github pages

Installing plugin

List of pelican plugins and how to use: https://github.com/getpelican/pelican-plugins

$ git clone --recursive https://github.com/getpelican/pelican-plugins

Local Test

Accessible at: http://localhost:8000/

$ pelican /path/to/your/content/ [-s path/to/your/settings.py]
$ source venv/bin/activate
$ pelican content -t PATH/TO/CUSTOM/THEME
$ pelican content --autoreload --listen -t PATH/TO/CUSTOM/THEME 

Publishing to Github Pages

$ source venv/bin/activate
$ pelican content -t PATH/TO/CUSTOM/THEME
$ ghp-import output -b gh-pages
$ git push origin gh-pages

Pelican Config Example

#!/usr/bin/env python
from __future__ import unicode_literals
import time

AUTHOR = 'YOUR NAME'
SITENAME = 'SITE NAME'
SITEURL = 'SITE_URL'
SITEURL = 'http://localhost:8000' # enable for local test

# custom variable
YEAR = time.strftime('%Y')


THEME = 'PATH/TO/YOUR/THEME'
GOOGLE_ANALYTICS = 'UA-YOUR-GA'
PATH = 'content'

# your source folder relative to PATH
ARTICLE_PATHS = ['blog'] # source
PAGE_PATHS = ['pages']
STATIC_PATHS = ['images', 'static/CNAME', 'static/favicon.ico']

ARTICLE_URL = SITEURL + '/blog/{slug}/'
ARTICLE_SAVE_AS = 'blog/{slug}/index.html'
PAGE_URL = SITEURL + '/{slug}/'
PAGE_SAVE_AS = '{slug}/index.html'

TIMEZONE = '<YOUR_TIMEZONE>' # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

DEFAULT_LANG = 'en'

# Feed generation is usually not desired when developing (default)
FEED_ALL_ATOM = None
CATEGORY_FEED_ATOM = None
TRANSLATION_FEED_ATOM = None
AUTHOR_FEED_ATOM = None
AUTHOR_FEED_RSS = None

FEED_ALL_ATOM = 'feeds/all.atom.xml'
# CATEGORY_FEED_ATOM = 'feeds/{slug}.atom.xml'

DISPLAY_PAGES_ON_MENU = True

# map static source to main output folder
EXTRA_PATH_METADATA = {
    'static/CNAME': {'path': 'CNAME'},
    'static/favicon.ico': {'path': 'favicon.ico'},
}

# Social widget or url list
SOCIAL = (
          ('Instagram', 'https://instagram.com/YOUR_USERNAME'),
          ('Twitter', 'javascript:void(0)'),
          ('Github', 'https://github.com/YOUR_USERNAME'),
        )

# secondary memu if you need
MENUITEMS = (
    ("ITEMS", "URL"),
)

# code block parent class
MARKDOWN = {
    'extension_configs': {
        'markdown.extensions.codehilite': {
            'css_class': 'hljs'
            'use_pygments': False
        }, # output <pre class="hljs"><code> YOUR CODE <code></pre>
        'markdown.extensions.extra': {},
        'markdown.extensions.meta': {},
    },
    'output_format': 'html5',
}


DEFAULT_PAGINATION = 5

# Custom template pages
TEMPLATE_PAGES = {'custom/recent.json': 'api/recent.json', }

PAGINATION_PATTERNS = (
    (1, '/blog', 'blog/{save_as}'),
    (2, '{base_name}/blog/page/{number}/', '{base_name}/blog/page/{number}/index.html'),
)

LINKS = (
    ("home", SITEURL),
    ("about", f"{SITEURL}/about"),
    ("works", "javascript:void(0)"),
    ("blog", f"{SITEURL}/blog"),
)

# disable unneeded output file
CATEGORY_SAVE_AS = ''
TAG_SAVE_AS = ''
AUTHOR_SAVE_AS = ''
AUTHORS_SAVE_AS = ''
CATEGORIES_SAVE_AS = ''
TAGS_SAVE_AS = ''
ARCHIVES_SAVE_AS = ''

# Uncomment following line if you want document-relative URLs when developing
#RELATIVE_URLS = True

# Plugins
PLUGIN_PATHS = ['pelican-plugins/']
PLUGINS = ['sitemap', 'pelican-open_graph', 'readtime', 'pelican-toc']

TOC = {
    'TOC_HEADERS'       : '^h[1-6]',
    'TOC_RUN'           : 'true',
    'TOC_INCLUDE_TITLE': 'false',
}

SITEMAP = {'exclude': ['api/']}

Language name as class name

There are no codihilite official workaround for this. But i just need to change one line, specifically line 83 inside codihilite.py to get the result that i wanted.

# self.css_class = css_class
self.css_class = f"{css_class} {lang}" # line 83 change this line
 # output eg: <pre class="hljs python"><code> YOUR CODE <code></pre>