2011-01-20 01:04:54 +01:00
|
|
|
.. _theming-pelican:
|
|
|
|
|
|
2010-12-05 19:15:02 +00:00
|
|
|
How to create themes for pelican
|
|
|
|
|
################################
|
|
|
|
|
|
|
|
|
|
Pelican uses the great `jinja2 <http://jinjna.pocoo.org>`_ templating engine to
|
2011-01-05 14:04:11 +01:00
|
|
|
generate it's HTML output. The jinja2 syntax is really simple. If you want to
|
|
|
|
|
create your own theme, feel free to take inspiration from the "simple" theme,
|
|
|
|
|
which is available `here
|
|
|
|
|
<https://github.com/ametaireau/pelican/tree/master/pelican/themes/simple/templates>`_
|
2010-12-05 19:15:02 +00:00
|
|
|
|
|
|
|
|
Structure
|
|
|
|
|
=========
|
|
|
|
|
|
|
|
|
|
To make your own theme, you must follow the following structure::
|
|
|
|
|
|
|
|
|
|
├── static
|
|
|
|
|
│ ├── css
|
|
|
|
|
│ └── images
|
|
|
|
|
└── templates
|
2010-12-15 18:13:59 +00:00
|
|
|
├── archives.html // to display archives
|
|
|
|
|
├── article.html // processed for each article
|
|
|
|
|
├── categories.html // must list all the categories
|
|
|
|
|
├── category.html // processed for each category
|
|
|
|
|
├── index.html // the index. List all the articles
|
|
|
|
|
├── page.html // processed for each page
|
|
|
|
|
├── tag.html // processed for each tag
|
|
|
|
|
└── tags.html // must list all the tags. Can be a tag cloud.
|
2010-12-05 19:15:02 +00:00
|
|
|
|
|
|
|
|
* `static` contains all the static content. It will be copied on the output
|
|
|
|
|
`theme/static` folder then. I've put the css and image folders, but they are
|
|
|
|
|
just examples. Put what you need here.
|
|
|
|
|
|
|
|
|
|
* `templates` contains all the templates that will be used to generate the content.
|
|
|
|
|
I've just put the mandatory templates here, you can define your own if it helps
|
|
|
|
|
you to organize yourself while doing the theme.
|
|
|
|
|
|
|
|
|
|
Templates and variables
|
|
|
|
|
=======================
|
|
|
|
|
|
|
|
|
|
It's using a simple syntax, that you can embbed into your html pages.
|
|
|
|
|
This document describes which templates should exists on a theme, and which
|
|
|
|
|
variables will be passed to each template, while generating it.
|
|
|
|
|
|
|
|
|
|
All templates will receive the variables defined in your settings file, if they
|
|
|
|
|
are in caps. You can access them directly.
|
|
|
|
|
|
|
|
|
|
Common variables
|
|
|
|
|
----------------
|
|
|
|
|
|
2010-12-15 18:08:25 +00:00
|
|
|
All of those settings will be given to all templates.
|
|
|
|
|
|
2010-12-05 19:15:02 +00:00
|
|
|
============= ===================================================
|
|
|
|
|
Variable Description
|
|
|
|
|
============= ===================================================
|
|
|
|
|
articles That's the list of articles, ordsered desc. by date
|
|
|
|
|
all the elements are `Article` objects, so you can
|
|
|
|
|
access their properties (e.g. title, summary, author
|
|
|
|
|
etc.
|
|
|
|
|
dates The same list of article, but ordered by date,
|
|
|
|
|
ascending
|
|
|
|
|
tags A dict containing each tags (keys), and the list of
|
|
|
|
|
relative articles.
|
|
|
|
|
categories A dict containing each category (keys), and the
|
|
|
|
|
list of relative articles.
|
|
|
|
|
pages The list of pages
|
|
|
|
|
============= ===================================================
|
|
|
|
|
|
2011-02-18 11:21:33 +01:00
|
|
|
index.html
|
|
|
|
|
----------
|
|
|
|
|
|
|
|
|
|
Home page of your blog, will finally remain at output/index.html.
|
|
|
|
|
|
|
|
|
|
If pagination is active, next pages will remain at output/index`n`.html.
|
|
|
|
|
|
|
|
|
|
=================== ===================================================
|
|
|
|
|
Variable Description
|
|
|
|
|
=================== ===================================================
|
|
|
|
|
articles_paginator A paginator object of article list
|
|
|
|
|
articles_page The current page of articles
|
|
|
|
|
dates_paginator A paginator object of article list, ordered by date,
|
|
|
|
|
ascending
|
|
|
|
|
dates_page The current page of articles, ordered by date,
|
|
|
|
|
ascending
|
2011-02-18 12:33:11 +00:00
|
|
|
page_name 'index'. Useful for pagination links.
|
2011-02-18 11:21:33 +01:00
|
|
|
=================== ===================================================
|
|
|
|
|
|
2010-12-05 19:15:02 +00:00
|
|
|
category.html
|
|
|
|
|
-------------
|
|
|
|
|
|
2010-12-15 18:08:25 +00:00
|
|
|
This template will be processed for each of the existing categories, and will
|
|
|
|
|
finally remain at output/category/`category_name`.html.
|
|
|
|
|
|
2011-02-18 11:21:33 +01:00
|
|
|
If pagination is active, next pages will remain at
|
|
|
|
|
output/category/`category_name``n`.html.
|
|
|
|
|
|
|
|
|
|
=================== ===================================================
|
|
|
|
|
Variable Description
|
|
|
|
|
=================== ===================================================
|
|
|
|
|
category The name of the category being processed
|
|
|
|
|
articles Articles of this category
|
|
|
|
|
dates Articles of this category, but ordered by date,
|
|
|
|
|
ascending
|
|
|
|
|
articles_paginator A paginator object of article list
|
|
|
|
|
articles_page The current page of articles
|
|
|
|
|
dates_paginator A paginator object of article list, ordered by date,
|
|
|
|
|
ascending
|
|
|
|
|
dates_page The current page of articles, ordered by date,
|
|
|
|
|
ascending
|
2011-02-18 12:33:11 +00:00
|
|
|
page_name 'category/`category_name`'. Useful for pagination
|
2011-02-18 11:21:33 +01:00
|
|
|
links.
|
|
|
|
|
=================== ===================================================
|
2010-12-05 19:15:02 +00:00
|
|
|
|
|
|
|
|
article.html
|
|
|
|
|
-------------
|
|
|
|
|
|
2010-12-15 18:08:25 +00:00
|
|
|
This template will be processed for each article. .html files will be outputed
|
|
|
|
|
in output/`article_name`.html. Here are the specific variables it gets.
|
|
|
|
|
|
2010-12-05 19:15:02 +00:00
|
|
|
============= ===================================================
|
|
|
|
|
Variable Description
|
|
|
|
|
============= ===================================================
|
|
|
|
|
article The article object to be displayed
|
|
|
|
|
category The name of the category of the current article
|
|
|
|
|
============= ===================================================
|
|
|
|
|
|
|
|
|
|
tag.html
|
|
|
|
|
--------
|
|
|
|
|
|
2010-12-15 18:08:25 +00:00
|
|
|
For each tag, this template will be processed. It will create .html files in
|
2011-02-18 11:21:33 +01:00
|
|
|
/output/tag/`tag_name`.html.
|
|
|
|
|
|
|
|
|
|
If pagination is active, next pages will remain at
|
|
|
|
|
output/tag/`tag_name``n`.html.
|
|
|
|
|
|
|
|
|
|
=================== ===================================================
|
|
|
|
|
Variable Description
|
|
|
|
|
=================== ===================================================
|
|
|
|
|
tag The name of the tag being processed
|
|
|
|
|
articles Articles related to this tag
|
|
|
|
|
dates Articles related to this tag, but ordered by date,
|
|
|
|
|
ascending
|
|
|
|
|
articles_paginator A paginator object of article list
|
|
|
|
|
articles_page The current page of articles
|
|
|
|
|
dates_paginator A paginator object of article list, ordered by date,
|
|
|
|
|
ascending
|
|
|
|
|
dates_page The current page of articles, ordered by date,
|
|
|
|
|
ascending
|
2011-02-18 12:33:11 +00:00
|
|
|
page_name 'tag/`tag_name`'. Useful for pagination links.
|
2011-02-18 11:21:33 +01:00
|
|
|
=================== ===================================================
|