'\" t .\" 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" "Feb 02, 2025" "4" "PELICAN" .SH NAME pelican-theming \- How to create themes for Pelican .sp There is a community\-managed repository of \X'tty: link https://github.com/getpelican/pelican-themes'\fI\%Pelican Themes\fP\X'tty: link' 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 \X'tty: link https://palletsprojects.com/p/jinja/'\fI\%Jinja\fP\X'tty: link' templating engine due to its flexibility and straightforward syntax. If you want to create your own theme, feel free to take inspiration from the \X'tty: link https://github.com/getpelican/pelican/tree/main/pelican/themes/simple/templates'\fI\%\(dqsimple\(dq theme\fP\X'tty: link'\&. .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 .EX pelican content \-s pelicanconf.py \-t /projects/your\-site/themes/your\-theme .EE .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 .EX ├── 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. .EE .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 box 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 .EX {% for tag, articles in tags|sort %} .EE .UNINDENT .UNINDENT .sp If you want to sort based on different criteria, \X'tty: link https://jinja.palletsprojects.com/en/latest/templates/#sort'\fI\%Jinja\(aqs sort command\fP\X'tty: link' 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 \X'tty: link https://docs.python.org/3/library/datetime.html#datetime-objects'\fI\%datetime\fP\X'tty: link' 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 \X'tty: link https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior'\fI\%strftime\fP\X'tty: link' 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 .EX {{ article.date|strftime(\(aq%d %B %Y\(aq) }} .EE .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 .EX {% if \(dqwebassets\(dq is plugin_enabled %} {% assets filters=\(dqcssmin\(dq, output=\(dqcss/style.min.css\(dq, \(dqcss/style.scss\(dq %} {% endassets %} {% else %} {% endif %} .EE .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 box 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 box 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 box 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 box 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 .EX 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 .EE .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 .EX .EE .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 box 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 box 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 box 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 \X'tty: link https://github.com/getpelican/pelican/blob/main/pelican/themes/simple/templates/period_archives.html'\fI\%\(dqsimple\(dq theme period_archives.html template\fP\X'tty: link'\&. .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 box 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 .EX