Custom nested iterations in Pelican with Jinja

19 views Asked by At

I would like to use Pelican+Jinja to generate a static webpage that is generated from structured data. In particular, I have article objects (each is represented by a Markdown file), and author objects (same). An article metadata includes authors: [author_a, author_b] list. From here, it would be easier to explain what I want to achieve by giving a simple example.

Suppose I have two authors, Sophie and Oliver, and two articles, Foo and Bar. Foo has an author list [Sophie] and Bar has an author list [Sophie, Oliver]. Sophie has url: sophie.com and Oliver has url: oliver.com in their metadata. I want the output to be

<ul>
  <li>Foo, by <a href='sophie.com'>Sophie</a></li>
  <li>Bar, by <a href='sophie.com'>Sophie</a> and <a href='ollie.com'>Ollie</a></li>
</ul>

What I know how to do:

<ul>
    {% for p in articles %}
    <li class='paper'>
        {{ p.title }},
        by {{ p.authors }}
    </li>
    {% endfor %}
</ul>

This outputs a list of "articles" taken from my "contents" folder (not sure about the order). But I am not sure how to let it read author data from other files (and I am also not sure where to put these files).

Can Pelican handle this scenario, or am I stretching it too much?

0

There are 0 answers