<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jared Forth</title>
    <description>The latest articles on DEV Community by Jared Forth (@jaredforth).</description>
    <link>https://dev.to/jaredforth</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F235126%2Fb0ceb80d-8755-45f7-8907-9d3fe6b8b0e9.jpg</url>
      <title>DEV Community: Jared Forth</title>
      <link>https://dev.to/jaredforth</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jaredforth"/>
    <language>en</language>
    <item>
      <title>Sharing my "Year in Books" using the Zola static site generator `load_data` method</title>
      <dc:creator>Jared Forth</dc:creator>
      <pubDate>Mon, 19 Aug 2024 21:33:10 +0000</pubDate>
      <link>https://dev.to/jaredforth/sharing-my-year-in-books-using-the-zola-static-site-generator-loaddata-method-3404</link>
      <guid>https://dev.to/jaredforth/sharing-my-year-in-books-using-the-zola-static-site-generator-loaddata-method-3404</guid>
      <description>&lt;p&gt;I recently migrated my personal &lt;a href="https://jaredforth.com/" rel="noopener noreferrer"&gt;website&lt;/a&gt; from HUGO to the &lt;a href="https://www.getzola.org/" rel="noopener noreferrer"&gt;Zola&lt;/a&gt; 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 - &lt;a href="https://www.getzola.org/" rel="noopener noreferrer"&gt;load_data&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Something I started doing a few years back is sharing my "&lt;a href="https://jaredforth.com/words/year-in-books/" rel="noopener noreferrer"&gt;Year in Books&lt;/a&gt;" in the &lt;code&gt;/words&lt;/code&gt; 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. &lt;/p&gt;

&lt;p&gt;I use Goodreads to keep track of what I'm reading, so the first step is to &lt;a href="https://www.goodreads.com/review/import" rel="noopener noreferrer"&gt;export&lt;/a&gt; a CSV file with my data. &lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;templates/shortcodes/books.html&lt;/code&gt; to be used like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{{ books(year="2024")}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in a markdown file. &lt;/p&gt;

&lt;p&gt;The snippet itself is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% set data = load_data(path="/content/books.csv") -%}

&amp;lt;table&amp;gt;
  &amp;lt;thead&amp;gt;
    &amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;
    &amp;lt;th&amp;gt;Author&amp;lt;/th&amp;gt;
    &amp;lt;th&amp;gt;Date Read&amp;lt;/th&amp;gt;
  &amp;lt;/thead&amp;gt;
  &amp;lt;tbody&amp;gt;
    {% for record in data.records %} {% if year in record[14] %}
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;{{ record[1] }}&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;{{ record[2] }}&amp;lt;/td&amp;gt;
      &amp;lt;td&amp;gt;{{ record[14] }}&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    {% endif %} {% endfor %}
  &amp;lt;/tbody&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which creates a table like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gijstu6xz1dct3g02vh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gijstu6xz1dct3g02vh.png" alt="Image description" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;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. &lt;/p&gt;

</description>
      <category>staticsite</category>
      <category>webdev</category>
      <category>data</category>
      <category>books</category>
    </item>
  </channel>
</rss>
