aboutsummaryrefslogtreecommitdiff
path: root/build/loop
diff options
context:
space:
mode:
Diffstat (limited to 'build/loop')
-rw-r--r--build/loop/index.html20
1 files changed, 2 insertions, 18 deletions
diff --git a/build/loop/index.html b/build/loop/index.html
index 272d94c..d857c62 100644
--- a/build/loop/index.html
+++ b/build/loop/index.html
@@ -3,11 +3,12 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
+ <meta name="color-scheme" content="dark light">
<link rel="icon" href="data:,">
<title>Looping Through Jekyll Collections</title>
<link href="/atom.xml" type="application/atom+xml" rel="alternate" title="Atom feed for blog posts" />
<link href="/rss.xml" type="application/rss+xml" rel="alternate" title="RSS feed for blog posts" />
-<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style>
+<style>*{box-sizing:border-box;}body{font-family:sans-serif;line-height:1.33;margin:0 auto;max-width:650px;padding:1rem;}blockquote{background:rgba(0,0,0,0.1);border-left:4px solid;padding-left:5px;}img{max-width:100%;}pre{border:1px solid;overflow:auto;padding:5px;}table{text-align:left;width:100%;}.footnotes{font-size:90%;}</style>
</head>
<nav>
@@ -16,38 +17,25 @@
<main>
<h1 id="looping-through-jekyll-collections">Looping Through Jekyll Collections</h1>
-
<p>2022-08-12</p>
-
<p>I recently needed to add a couple new items to my wife&#8217;s personal recipe website (<a href="https://cookingwith.casa">cookingwith.casa</a>) which I hadn&#8217;t touched in quite a while. The Jekyll build still worked fine, but I realized I was statically adding each <code>collection</code> by hand on the main homepage[^1].</p>
-
<p>Not so good.</p>
-
<p>Of course, this wasn&#8217;t difficult at all to fix. Now everything is much more &#8220;hands free&#8221; moving forward. I figured I would share the details here in the hopes that others mind find it useful. Plus, it&#8217;s my blog - so I&#8217;ll do what I want!</p>
-
<h2 id="looping-our-collections">Looping Our Collections</h2>
-
<p>We want Jekyll to make things as streamlined as possible for us. This means that if I decide to add a new collection it will automatically render it along the others on the homepage.</p>
-
<p>Work smart not hard!</p>
-
<p>Let&#8217;s take a look at the bare-bones collections loop:</p>
-
<pre><code>{% for collection in site.collections %}
&#60;!-- Our code goes here --&#62;
{% endfor %}
</code></pre>
-
<p>Then we need to include an <code>if</code> statement to avoid pulling in standard <code>post</code> items (or leave this in if that is desired):</p>
-
<pre><code>{% for collection in site.collections %}
{% if collection.label != &#39;posts&#39; %}
{% endif %}
{% endfor %}
</code></pre>
-
<p>Now for my specific use case, we want to display each collection label and then list its corresponding items below that label (see the <code>site[collection.label]</code> for reference)</p>
-
<pre><code>{% for collection in site.collections %}
{% if collection.label != &#39;posts&#39; %}
&#60;h2&#62;{{ collection.label }}&#60;&#47;h2&#62;
@@ -62,13 +50,9 @@
{% endif %}
{% endfor %}
</code></pre>
-
<p>That&#8217;s it! Now if I plan to add any new collections down the line, I just need to include it in the <code>_config.yml</code> file and I&#8217;m set. The homepage will take care of the rest once rendered.</p>
-
<p>Enjoy looping through your Jekyll collections!</p>
-
<h2 id="refs">Refs</h2>
-
<ol>
<li>Just the sections were statically rendered. All the recipes were pulled in dynamically - I&#8217;m not that insane!</li>
</ol>