Never change your Pelican footer again

One of the less glamorous tasks of hosting a blog is keeping all the small details up to date. One of those details is the copyright date on the site. Here's an easy way to never have to worry about this again. Pelican themes have a core set of files to generate a website. One of them is the base.html theme file. Check your Pelican theme and see if the base.html file includes a reference to a footer theme file, like footer.html. If it does, skip the next step and move on.

Add Footer.html reference

Because your base.html file does not reference a footer theme file, or have any details related to a copyright date at the bottom, you'll need to add some code between the last </div tag and just before the </body tag to get your footer to show up. You'll need to add the following snippet:

<footer role="contentinfo">{% include 'footer.html' %}</footer>

The end of the base.html theme file should now look similar to this:1

    <div id="main">
        <div id="content">
        {% block content %}{% endblock %}
        {% include '_includes/sidebar.html' %}
<footer role="contentinfo">{% include 'footer.html' %}</footer>

So now the next time your regenerate the content on your site, the base.html theme file will call on the footer.html theme file we'll create in the next step.

Create/Edit Footer.html

The next step is also dependent on the Pelican theme you have installed. Some themes have the footer.html file in the main theme folder, others have it one level down in another folder, like _includes. Locate the footer.html file and open it with your favorite text editor - e.g. nano.

Most Pelican themes that use a footer.html theme file use the date of the most recent post to set up the copyright date range. My theme originally used the following:

    {% if LICENSE %}
        {{ LICENSE }} 
    {% else %}
    {% set years = dates|groupby('date.year')|sort(reverse=False) %}
    {% set sinceYear = years|first|first|default('2014') %}
    {% set toYear = years|last|first|default('2014') %}
    Copyright &copy; {% if sinceYear == toYear %} {{ sinceYear }} 
        {% else %} 
        {{ sinceYear }}-{{ toYear }} {% endif%} - {{ AUTHOR }} -
    {% endif %}
    <span class="credit">Powered by <a href="">Pelican

Using a little Javascript we can have the footer be up to date at the stroke of midnight on Jan 1. Change the footer.htmltemplate to something like this:

<p class = "credit">Copyright &copy 1999 - <script type="text/javascript">
document.write(new Date().getFullYear()); </script>
 John Smith | Powered by <a href="">Pelican</a></span>

If your theme doesn't have a footer.html file, create one on the root of your theme folder by copying and pasting the snippet from above into the new file. Save the file and refresh the content on your site - pelican content.

Now when someone views your site the footer will show the correct copyright year.

  1. YMMV based on your theme, so may need to experiment with the syntax based on your Pelican theme.