Pelican Generate index.html by reStructuredText or Markdown
Use Pelican static site generator to generate index.html by writing reStructuredText or Markdown.
In Pelican, you can create your own theme. In this post, we will show you how to wrtie rst or md to generate index.html in your customized theme.
Jinja2 filter in pelicanconf.py
We create a custom Jinja2 filter to select the hidden pages with slug is index.
# custom Jinja2 filter
def hidden_pages_get_page_with_slug_index(hidden_pages):
for page in hidden_pages:
if page.slug == "index":
return page
JINJA_FILTERS = {
"hidden_pages_get_page_with_slug_index": hidden_pages_get_page_with_slug_index,
}
index.html in theme
Then we modify the index.html in theme to do something like following:
{% extends "layout/layout.html" %}
{% set index = (hidden_pages|hidden_pages_get_page_with_slug_index) %}
<div class="title">{{ index.title }}</div>
<div class="summary">{{ index.summary }}</div>
<div class="main-content">{{ index.content }}</div>
Just the same as you are writing page.html or article.html in the customized theme.
Tested on: Ubuntu Linux 15.10, Python 2.7.10, Pelican 3.6.3.
References:
[1] | pelican custom Jinja2 filter to let you write index.html in rst · siongui/pelican-template@e70b7ca · GitHub |
[2] | JINJA_FILTERS in Settings — Pelican documentation |
[3] | GitHub - siongui/pelican-template |
[4] | python - Querying for specific articles (via tag/category) in Pelican themes - Stack Overflow |