.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "PELICAN-THEMING" "1" "Jan 07, 2024" "4" "PELICAN" .SH NAME pelican-theming \- How to create themes for Pelican .sp There is a community\-managed repository of \fI\%Pelican Themes\fP for people to share and use. .sp Please note that while we do our best to review and merge theme contributions, they are submitted by the Pelican community and thus may have varying levels of support and interoperability. .SH CREATING THEMES .sp To generate its HTML output, Pelican uses the \fI\%Jinja\fP templating engine due to its flexibility and straightforward syntax. If you want to create your own theme, feel free to take inspiration from the \fI\%\(dqsimple\(dq theme\fP\&. .sp To generate your site using a theme you have created (or downloaded manually and then modified), you can specify that theme via the \fB\-t\fP flag: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C pelican content \-s pelicanconf.py \-t /projects/your\-site/themes/your\-theme .ft P .fi .UNINDENT .UNINDENT .sp If you\(aqd rather not specify the theme on every invocation, you can define \fBTHEME\fP in your settings to point to the location of your preferred theme. .SS Structure .sp To make your own theme, you must follow the following structure: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C ├── static │ ├── css │ └── images └── templates ├── archives.html // to display archives ├── article.html // processed for each article ├── author.html // processed for each author ├── authors.html // must list all the authors ├── 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 ├── period_archives.html // to display time\-period archives ├── tag.html // processed for each tag └── tags.html // must list all the tags. Can be a tag cloud. .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .IP \(bu 2 \fIstatic\fP contains all the static assets, which will be copied to the output \fItheme\fP folder. The above filesystem layout includes CSS and image folders, but those are just examples. Put what you need here. .IP \(bu 2 \fItemplates\fP contains all the templates that will be used to generate the content. The template files listed above are mandatory; you can add your own templates if it helps you keep things organized while creating your theme. .UNINDENT .SS Templates and Variables .sp The idea is to use a simple syntax that you can embed into your HTML pages. This document describes which templates should exist in a theme, and which variables will be passed to each template at generation time. .sp All templates will receive the variables defined in your settings file, as long as they are in all\-caps. You can access them directly. .SS Common Variables .sp All of these settings will be available to all templates. .TS center; |l|l|. _ T{ Variable T} T{ Description T} _ T{ output_file T} T{ The name of the file currently being generated. For instance, when Pelican is rendering the home page, output_file will be \(dqindex.html\(dq. T} _ T{ articles T} T{ The list of articles, ordered descending by date. All the elements are \fIArticle\fP objects, so you can access their attributes (e.g. title, summary, author etc.). Sometimes this is shadowed (for instance, in the tags page). You will then find info about it in the \fIall_articles\fP variable. T} _ T{ dates T} T{ The same list of articles, but ordered by date, ascending. T} _ T{ hidden_articles T} T{ The list of hidden articles T} _ T{ drafts T} T{ The list of draft articles T} _ T{ period_archives T} T{ A dictionary containing elements related to time\-period archives (if enabled). See the section \fI\%Listing and Linking to Period Archives\fP for details. T} _ T{ authors T} T{ A list of (author, articles) tuples, containing all the authors and corresponding articles (values) T} _ T{ categories T} T{ A list of (category, articles) tuples, containing all the categories and corresponding articles (values) T} _ T{ tags T} T{ A list of (tag, articles) tuples, containing all the tags and corresponding articles (values) T} _ T{ pages T} T{ The list of pages T} _ T{ hidden_pages T} T{ The list of hidden pages T} _ T{ draft_pages T} T{ The list of draft pages T} _ .TE .SS Sorting .sp URL wrappers (currently categories, tags, and authors), have comparison methods that allow them to be easily sorted by name: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C {% for tag, articles in tags|sort %} .ft P .fi .UNINDENT .UNINDENT .sp If you want to sort based on different criteria, \fI\%Jinja\(aqs sort command\fP has a number of options. .SS Date Formatting .sp Pelican formats the date according to your settings and locale (\fBDATE_FORMATS\fP/\fBDEFAULT_DATE_FORMAT\fP) and provides a \fBlocale_date\fP attribute. On the other hand, the \fBdate\fP attribute will be a \fI\%datetime\fP object. If you need custom formatting for a date different than your settings, use the Jinja filter \fBstrftime\fP that comes with Pelican. Usage is same as Python \fI\%strftime\fP format, but the filter will do the right thing and format your date according to the locale given in your settings: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C {{ article.date|strftime(\(aq%d %B %Y\(aq) }} .ft P .fi .UNINDENT .UNINDENT .SS Checking Loaded Plugins .sp Pelican provides a \fBplugin_enabled\fP Jinja test for checking if a certain plugin is enabled. This test accepts a plugin name as a string and will return a Boolean. Namespace plugins can be specified by full name (\fBpelican.plugins.plugin_name\fP) or short name (\fBplugin_name\fP). The following example uses the \fBwebassets\fP plugin to minify CSS if the plugin is enabled and otherwise falls back to regular CSS: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C {% if \(dqwebassets\(dq is plugin_enabled %} {% assets filters=\(dqcssmin\(dq, output=\(dqcss/style.min.css\(dq, \(dqcss/style.scss\(dq %} {% endassets %} {% else %} {% endif %} .ft P .fi .UNINDENT .UNINDENT .SS index.html .sp This is the home page or index of your blog, generated at \fBindex.html\fP\&. .sp If pagination is active, subsequent pages will reside in \fBindex{number}.html\fP\&. .TS center; |l|l|. _ T{ Variable T} T{ Description T} _ T{ articles_paginator T} T{ A paginator object for the list of articles T} _ T{ articles_page T} T{ The current page of articles T} _ T{ articles_previous_page T} T{ The previous page of articles (\fBNone\fP if page does not exist) T} _ T{ articles_next_page T} T{ The next page of articles (\fBNone\fP if page does not exist) T} _ T{ dates_paginator T} T{ A paginator object for the article list, ordered by date, ascending. T} _ T{ dates_page T} T{ The current page of articles, ordered by date, ascending. T} _ T{ dates_previous_page T} T{ The previous page of articles, ordered by date, ascending (\fBNone\fP if page does not exist) T} _ T{ dates_next_page T} T{ The next page of articles, ordered by date, ascending (\fBNone\fP if page does not exist) T} _ T{ page_name T} T{ \(aqindex\(aq \-\- useful for pagination links T} _ .TE .SS author.html .sp This template will be processed for each of the existing authors, with output generated according to the \fBAUTHOR_SAVE_AS\fP setting (\fIDefault:\fP \fBauthor/{slug}.html\fP). If pagination is active, subsequent pages will by default reside at \fBauthor/{slug}{number}.html\fP\&. .TS center; |l|l|. _ T{ Variable T} T{ Description T} _ T{ author T} T{ The name of the author being processed T} _ T{ articles T} T{ Articles by this author T} _ T{ dates T} T{ Articles by this author, but ordered by date, ascending T} _ T{ articles_paginator T} T{ A paginator object for the list of articles T} _ T{ articles_page T} T{ The current page of articles T} _ T{ articles_previous_page T} T{ The previous page of articles (\fBNone\fP if page does not exist) T} _ T{ articles_next_page T} T{ The next page of articles (\fBNone\fP if page does not exist) T} _ T{ dates_paginator T} T{ A paginator object for the article list, ordered by date, ascending. T} _ T{ dates_page T} T{ The current page of articles, ordered by date, ascending. T} _ T{ dates_previous_page T} T{ The previous page of articles, ordered by date, ascending (\fBNone\fP if page does not exist) T} _ T{ dates_next_page T} T{ The next page of articles, ordered by date, ascending (\fBNone\fP if page does not exist) T} _ T{ page_name T} T{ AUTHOR_URL where everything after \fI{slug}\fP is removed \-\- useful for pagination links T} _ .TE .SS category.html .sp This template will be processed for each of the existing categories, with output generated according to the \fBCATEGORY_SAVE_AS\fP setting (\fIDefault:\fP \fBcategory/{slug}.html\fP). If pagination is active, subsequent pages will by default reside at \fBcategory/{slug}{number}.html\fP\&. .TS center; |l|l|. _ T{ Variable T} T{ Description T} _ T{ category T} T{ The name of the category being processed T} _ T{ articles T} T{ Articles for this category T} _ T{ dates T} T{ Articles for this category, but ordered by date, ascending T} _ T{ articles_paginator T} T{ A paginator object for the list of articles T} _ T{ articles_page T} T{ The current page of articles T} _ T{ articles_previous_page T} T{ The previous page of articles (\fBNone\fP if page does not exist) T} _ T{ articles_next_page T} T{ The next page of articles (\fBNone\fP if page does not exist) T} _ T{ dates_paginator T} T{ A paginator object for the list of articles, ordered by date, ascending T} _ T{ dates_page T} T{ The current page of articles, ordered by date, ascending T} _ T{ dates_previous_page T} T{ The previous page of articles, ordered by date, ascending (\fBNone\fP if page does not exist) T} _ T{ dates_next_page T} T{ The next page of articles, ordered by date, ascending (\fBNone\fP if page does not exist) T} _ T{ page_name T} T{ CATEGORY_URL where everything after \fI{slug}\fP is removed \-\- useful for pagination links T} _ .TE .SS article.html .sp This template will be processed for each article, with output generated according to the \fBARTICLE_SAVE_AS\fP setting (\fIDefault:\fP \fB{slug}.html\fP). The following variables are available when rendering. .TS center; |l|l|. _ T{ Variable T} T{ Description T} _ T{ article T} T{ The article object to be displayed T} _ T{ category T} T{ The name of the category for the current article T} _ .TE .sp Any metadata that you put in the header of the article source file will be available as fields on the \fBarticle\fP object. The field name will be the same as the name of the metadata field, except in all\-lowercase characters. .sp For example, you could add a field called \fIFacebookImage\fP to your article metadata, as shown below: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C Title: I love Python more than music Date: 2013\-11\-06 10:06 Tags: personal, python Category: Tech Slug: python\-je\-l\-aime\-a\-mourir Author: Francis Cabrel FacebookImage: http://franciscabrel.com/images/pythonlove.png .ft P .fi .UNINDENT .UNINDENT .sp This new metadata will be made available as \fIarticle.facebookimage\fP in your \fIarticle.html\fP template. This would allow you, for example, to specify an image for the Facebook open graph tags that will change for each article: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C .ft P .fi .UNINDENT .UNINDENT .SS page.html .sp This template will be processed for each page, with output generated according to the \fBPAGE_SAVE_AS\fP setting (\fIDefault:\fP \fBpages/{slug}.html\fP). The following variables are available when rendering. .TS center; |l|l|. _ T{ Variable T} T{ Description T} _ T{ page T} T{ The page object to be displayed. You can access its title, slug, and content. T} _ .TE .SS tag.html .sp This template will be processed for each tag, with output generated according to the \fBTAG_SAVE_AS\fP setting (\fIDefault:\fP \fBtag/{slug}.html\fP). If pagination is active, subsequent pages will by default reside at \fBtag/{slug}{number}.html\fP\&. .TS center; |l|l|. _ T{ Variable T} T{ Description T} _ T{ tag T} T{ The name of the tag being processed T} _ T{ articles T} T{ Articles related to this tag T} _ T{ dates T} T{ Articles related to this tag, but ordered by date, ascending T} _ T{ articles_paginator T} T{ A paginator object for the list of articles T} _ T{ articles_page T} T{ The current page of articles T} _ T{ articles_previous_page T} T{ The previous page of articles (\fBNone\fP if page does not exist) T} _ T{ articles_next_page T} T{ The next page of articles (\fBNone\fP if page does not exist) T} _ T{ dates_paginator T} T{ A paginator object for the list of articles, ordered by date, ascending T} _ T{ dates_page T} T{ The current page of articles, ordered by date, ascending T} _ T{ dates_previous_page T} T{ The previous page of articles, ordered by date, ascending (\fBNone\fP if page does not exist) T} _ T{ dates_next_page T} T{ The next page of articles, ordered by date, ascending (\fBNone\fP if page does not exist) T} _ T{ page_name T} T{ TAG_URL where everything after \fI{slug}\fP is removed \-\- useful for pagination links T} _ .TE .SS period_archives.html .sp This template will be processed for each year of your posts if a path for \fBYEAR_ARCHIVE_SAVE_AS\fP is defined, each month if \fBMONTH_ARCHIVE_SAVE_AS\fP is defined, and each day if \fBDAY_ARCHIVE_SAVE_AS\fP is defined. .TS center; |l|l|. _ T{ Variable T} T{ Description T} _ T{ period T} T{ A tuple of the form (\fIyear\fP, \fImonth\fP, \fIday\fP) that indicates the current time period. \fIyear\fP and \fIday\fP are numbers while \fImonth\fP is a string. This tuple only contains \fIyear\fP if the time period is a given year. It contains both \fIyear\fP and \fImonth\fP if the time period is over years and months and so on. T} _ T{ period_num T} T{ A tuple of the form (\fByear\fP, \fBmonth\fP, \fBday\fP), as in \fBperiod\fP, except all values are numbers. T} _ .TE .sp You can see an example of how to use \fIperiod\fP in the \fI\%\(dqsimple\(dq theme period_archives.html template\fP\&. .SS Listing and Linking to Period Archives .sp The \fBperiod_archives\fP variable can be used to generate a list of links to the set of period archives that Pelican generates. As a \fI\%common variable\fP, it is available for use in any template, so you can implement such an index in a custom direct template, or in a sidebar visible across different site pages. .sp \fBperiod_archives\fP is a dict that may contain \fByear\fP, \fBmonth\fP, and/or \fBday\fP keys, depending on which \fB*_ARCHIVE_SAVE_AS\fP settings are enabled. The corresponding value is a list of dicts, where each dict in turn represents a time period (ordered according to the \fBNEWEST_FIRST_ARCHIVES\fP setting) with the following keys and values: .TS center; |l|l|. _ T{ Key T} T{ Value T} _ T{ period T} T{ The same tuple as described in \fBperiod_archives.html\fP, e.g. \fB(2023, \(aqJune\(aq, 18)\fP\&. T} _ T{ period_num T} T{ The same tuple as described in \fBperiod_archives.html\fP, e.g. \fB(2023, 6, 18)\fP\&. T} _ T{ url T} T{ The URL to the period archive page, e.g. \fBposts/2023/06/18/\fP\&. This is controlled by the corresponding \fB*_ARCHIVE_URL\fP setting. T} _ T{ save_as T} T{ The path to the save location of the period archive page file, e.g. \fBposts/2023/06/18/index.html\fP\&. This is used internally by Pelican and is usually not relevant to themes. T} _ T{ articles T} T{ A list of \fI\%Article\fP objects that fall under the time period. T} _ T{ dates T} T{ Same list as \fBarticles\fP, but ordered according to the \fBNEWEST_FIRST_ARCHIVES\fP setting. T} _ .TE .sp Here is an example of how \fBperiod_archives\fP can be used in a template: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C .ft P .fi .UNINDENT .UNINDENT .sp You can change \fBperiod_archives.month\fP in the \fBfor\fP statement to \fBperiod_archives.year\fP or \fBperiod_archives.day\fP as appropriate, depending on the time period granularity desired. .SS Objects .sp Detail objects attributes that are available and useful in templates. Not all attributes are listed here, this is a selection of attributes considered useful in a template. .SS Article .sp The string representation of an Article is the \fIsource_path\fP attribute. .TS center; |l|l|. _ T{ Attribute T} T{ Description T} _ T{ author T} T{ The \fI\%Author\fP of this article. T} _ T{ authors T} T{ A list of \fI\%Authors\fP of this article. T} _ T{ category T} T{ The \fI\%Category\fP of this article. T} _ T{ content T} T{ The rendered content of the article. T} _ T{ date T} T{ Datetime object representing the article date. T} _ T{ date_format T} T{ Either default date format or locale date format. T} _ T{ default_template T} T{ Default template name. T} _ T{ in_default_lang T} T{ Boolean representing if the article is written in the default language. T} _ T{ lang T} T{ Language of the article. T} _ T{ locale_date T} T{ Date formatted by the \fIdate_format\fP\&. T} _ T{ metadata T} T{ Article header metadata \fIdict\fP\&. T} _ T{ save_as T} T{ Location to save the article page. T} _ T{ slug T} T{ Page slug. T} _ T{ source_path T} T{ Full system path of the article source file. T} _ T{ relative_source_path T} T{ Relative path from \fI\%PATH\fP to the article source file. T} _ T{ status T} T{ The article status, can be any of \(aqpublished\(aq or \(aqdraft\(aq. T} _ T{ summary T} T{ Rendered summary content. T} _ T{ tags T} T{ List of \fI\%Tag\fP objects. T} _ T{ template T} T{ Template name to use for rendering. T} _ T{ title T} T{ Title of the article. T} _ T{ translations T} T{ List of translations \fI\%Article\fP objects. T} _ T{ url T} T{ URL to the article page. T} _ .TE .SS Author / Category / Tag .sp The string representation of those objects is the \fIname\fP attribute. .TS center; |l|l|. _ T{ Attribute T} T{ Description T} _ T{ name T} T{ Name of this object [1]\&. T} _ T{ page_name T} T{ Author page name. T} _ T{ save_as T} T{ Location to save the author page. T} _ T{ slug T} T{ Page slug. T} _ T{ url T} T{ URL to the author page. T} _ .TE .IP [1] 5 for Author object, coming from \fI:authors:\fP or \fIAUTHOR\fP\&. .SS Page .sp The string representation of a Page is the \fIsource_path\fP attribute. .TS center; |l|l|. _ T{ Attribute T} T{ Description T} _ T{ author T} T{ The \fI\%Author\fP of this page. T} _ T{ content T} T{ The rendered content of the page. T} _ T{ date T} T{ Datetime object representing the page date. T} _ T{ date_format T} T{ Either default date format or locale date format. T} _ T{ default_template T} T{ Default template name. T} _ T{ in_default_lang T} T{ Boolean representing if the article is written in the default language. T} _ T{ lang T} T{ Language of the article. T} _ T{ locale_date T} T{ Date formatted by the \fIdate_format\fP\&. T} _ T{ metadata T} T{ Page header metadata \fIdict\fP\&. T} _ T{ save_as T} T{ Location to save the page. T} _ T{ slug T} T{ Page slug. T} _ T{ source_path T} T{ Full system path of the page source file. T} _ T{ relative_source_path T} T{ Relative path from \fI\%PATH\fP to the page source file. T} _ T{ status T} T{ The page status, can be any of \(aqpublished\(aq, \(aqhidden\(aq or \(aqdraft\(aq. T} _ T{ summary T} T{ Rendered summary content. T} _ T{ tags T} T{ List of \fI\%Tag\fP objects. T} _ T{ template T} T{ Template name to use for rendering. T} _ T{ title T} T{ Title of the page. T} _ T{ translations T} T{ List of translations \fI\%Article\fP objects. T} _ T{ url T} T{ URL to the page. T} _ .TE .SS Feeds .sp The feed variables changed in 3.0. Each variable now explicitly lists ATOM or RSS in the name. ATOM is still the default. Old themes will need to be updated. Here is a complete list of the feed variables: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C AUTHOR_FEED_ATOM AUTHOR_FEED_RSS CATEGORY_FEED_ATOM CATEGORY_FEED_RSS FEED_ALL_ATOM FEED_ALL_RSS FEED_ATOM FEED_RSS TAG_FEED_ATOM TAG_FEED_RSS TRANSLATION_FEED_ATOM TRANSLATION_FEED_RSS .ft P .fi .UNINDENT .UNINDENT .SS Inheritance .sp Since version 3.0, Pelican supports inheritance from the \fBsimple\fP theme, so you can re\-use the \fBsimple\fP theme templates in your own themes. .sp If one of the mandatory files in the \fBtemplates/\fP directory of your theme is missing, it will be replaced by the matching template from the \fBsimple\fP theme. So if the HTML structure of a template in the \fBsimple\fP theme is right for you, you don\(aqt have to write a new template from scratch. .sp You can also extend templates from the \fBsimple\fP theme in your own themes by using the \fB{% extends %}\fP directive as in the following example: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C {% extends \(dq!simple/index.html\(dq %} {% extends \(dqindex.html\(dq %} .ft P .fi .UNINDENT .UNINDENT .SS Example .sp With this system, it is possible to create a theme with just two files. .SS base.html .sp The first file is the \fBtemplates/base.html\fP template: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C {% extends \(dq!simple/base.html\(dq %} {% block head %} {{ super() }} {% endblock %} .ft P .fi .UNINDENT .UNINDENT .INDENT 0.0 .IP 1. 3 On the first line, we extend the \fBbase.html\fP template from the \fBsimple\fP theme, so we don\(aqt have to rewrite the entire file. .IP 2. 3 On the third line, we open the \fBhead\fP block which has already been defined in the \fBsimple\fP theme. .IP 3. 3 On the fourth line, the function \fBsuper()\fP keeps the content previously inserted in the \fBhead\fP block. .IP 4. 3 On the fifth line, we append a stylesheet to the page. .IP 5. 3 On the last line, we close the \fBhead\fP block. .UNINDENT .sp This file will be extended by all the other templates, so the stylesheet will be linked from all pages. .SS style.css .sp The second file is the \fBstatic/css/style.css\fP CSS stylesheet: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C body { font\-family : monospace ; font\-size : 100% ; background\-color : white ; color : #111 ; width : 80% ; min\-width : 400px ; min\-height : 200px ; padding : 1em ; margin : 5% 10% ; border : thin solid gray ; border\-radius : 5px ; display : block ; } a:link { color : blue ; text\-decoration : none ; } a:hover { color : blue ; text\-decoration : underline ; } a:visited { color : blue ; } h1 a { color : inherit !important } h2 a { color : inherit !important } h3 a { color : inherit !important } h4 a { color : inherit !important } h5 a { color : inherit !important } h6 a { color : inherit !important } pre { margin : 2em 1em 2em 4em ; } #menu li { display : inline ; } #post\-list { margin\-bottom : 1em ; margin\-top : 1em ; } .ft P .fi .UNINDENT .UNINDENT .SS Download .sp You can download this example theme \fBhere\fP\&. .SH AUTHOR The Pelican contributors .SH COPYRIGHT 2010–2024 .\" Generated by docutils manpage writer. .