Adding date-based navigation to your site

The following will generate pages of the form:

  • /2020/index.html
  • /2020/01/index.html
  • /2020/02/index.html
  • ...

that contain links to individual source pages.

Add the published date your sources

To add date-based navigation to your site, first ensure that anything you want to show up in the date-based navigation is using the special key published to store the date (it is fine to duplicate the date if you are already using a different key).

Add year and month based index pages

To generate a year and month index pages, add the following to your

from flourish.generators.calendar import (

    # ...
    # your existing paths should be here, don't remove them,
    # ...
        path = '/#year/',
        name = 'year-index',
        path = '/#year/#month/',
        name = 'month-index',

Create a calendar_year.html template:

<h1>Entries for {{year.year}}</h1>

  {% for month in publication_dates %}
    {% with m=month.month %}
      <a href='{{ path("month-index", year=m.year, month=m.month) }}'>
    {% endwith %}
  {% endfor %}

Create a calendar_month.html template:

<h1>Entries for {{month.strftime('%B %Y')}}</h1>

{% for page in pages %}
    <a href='{{page.path}}'>{{page.title}}</a>
{% endfor %}

Add the following to your

def global_context(self):
    return {
        'dates': self.flourish.publication_dates,

GLOBAL_CONTEXT = global_context

This makes a variable global.dates available to all of your templates, which contains a structure that lists all years, months and days that have associated source objects.

Lastly, add something like this to your template(s) to link to the date-based pages:

    {% for year in global.dates %}
        <a href='/{{year.year}}/'>{{year.year}}</a>
    {% endfor %}

Adjusting the content and styling of the generated navigation and index pages is left up to you. There is also a day-based page generator if you would like to have finer-grained archives, see their documentation.