Sharing my “Year in Books” using the Zola static site generator `load_data` method

I recently migrated my personal website from HUGO to the Zola static site generator. It’s been incredible to use, and I wanted to share a real life use case of one of the more obscure features – load_data

Something I started doing a few years back is …


This content originally appeared on DEV Community and was authored by Jared Forth

I recently migrated my personal website from HUGO to the Zola static site generator. It's been incredible to use, and I wanted to share a real life use case of one of the more obscure features - load_data

Something I started doing a few years back is sharing my "Year in Books" in the /words section of my site. This was trivial with HUGO, but it took a bit of digging through the Zola docs to figure out how to accomplish it in the new system. It was also simple to do in Zola, but thought I'd share my approach.

I use Goodreads to keep track of what I'm reading, so the first step is to export a CSV file with my data.

The next step is to simply load that data and render what is desired. I want to be able to use a shortcode, so I created templates/shortcodes/books.html to be used like:

{{ books(year="2024")}}

in a markdown file.

The snippet itself is:

{% set data = load_data(path="/content/books.csv") -%}

<table>
  <thead>
    <th>Title</th>
    <th>Author</th>
    <th>Date Read</th>
  </thead>
  <tbody>
    {% for record in data.records %} {% if year in record[14] %}
    <tr>
      <td>{{ record[1] }}</td>
      <td>{{ record[2] }}</td>
      <td>{{ record[14] }}</td>
    </tr>
    {% endif %} {% endfor %}
  </tbody>
</table>

which creates a table like:

Image description

It ended up taking me only about 15 minutes to implement this feature, which speaks to how user-friendly the Zola static site generator is. Hope this is helpful for someone looking to import data into their static site.


This content originally appeared on DEV Community and was authored by Jared Forth


Print Share Comment Cite Upload Translate Updates
APA

Jared Forth | Sciencx (2024-08-19T21:33:10+00:00) Sharing my “Year in Books” using the Zola static site generator `load_data` method. Retrieved from https://www.scien.cx/2024/08/19/sharing-my-year-in-books-using-the-zola-static-site-generator-load_data-method/

MLA
" » Sharing my “Year in Books” using the Zola static site generator `load_data` method." Jared Forth | Sciencx - Monday August 19, 2024, https://www.scien.cx/2024/08/19/sharing-my-year-in-books-using-the-zola-static-site-generator-load_data-method/
HARVARD
Jared Forth | Sciencx Monday August 19, 2024 » Sharing my “Year in Books” using the Zola static site generator `load_data` method., viewed ,<https://www.scien.cx/2024/08/19/sharing-my-year-in-books-using-the-zola-static-site-generator-load_data-method/>
VANCOUVER
Jared Forth | Sciencx - » Sharing my “Year in Books” using the Zola static site generator `load_data` method. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/19/sharing-my-year-in-books-using-the-zola-static-site-generator-load_data-method/
CHICAGO
" » Sharing my “Year in Books” using the Zola static site generator `load_data` method." Jared Forth | Sciencx - Accessed . https://www.scien.cx/2024/08/19/sharing-my-year-in-books-using-the-zola-static-site-generator-load_data-method/
IEEE
" » Sharing my “Year in Books” using the Zola static site generator `load_data` method." Jared Forth | Sciencx [Online]. Available: https://www.scien.cx/2024/08/19/sharing-my-year-in-books-using-the-zola-static-site-generator-load_data-method/. [Accessed: ]
rf:citation
» Sharing my “Year in Books” using the Zola static site generator `load_data` method | Jared Forth | Sciencx | https://www.scien.cx/2024/08/19/sharing-my-year-in-books-using-the-zola-static-site-generator-load_data-method/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.