<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>jsonfeed on foosel.net</title><link>https://foosel.net/tags/jsonfeed/</link><description>Recent content in jsonfeed on foosel.net</description><generator>Hugo</generator><language>en-us</language><copyright>Gina Häußge (foosel)</copyright><lastBuildDate>Thu, 02 Feb 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://foosel.net/tags/jsonfeed/feed.xml" rel="self" type="application/rss+xml"/><item><title>TIL: How to use jq to extract new posts from a JSON Feed</title><link>https://foosel.net/til/2023-02-02-how-to-use-jq-to-extract-new-posts-from-a-json-feed/</link><pubDate>Thu, 02 Feb 2023 00:00:00 +0000</pubDate><guid>https://foosel.net/til/2023-02-02-how-to-use-jq-to-extract-new-posts-from-a-json-feed/</guid><description>&lt;p&gt;I&amp;rsquo;m currently looking into ways to automate some stuff around new posts on this page (be it blog or TIL post) directly during the page build on GitHub Actions. For this, I first need to be able to reliably &lt;em&gt;detect&lt;/em&gt; new posts, from a bash run step. So here&amp;rsquo;s how to do that with &lt;a href="https://stedolan.github.io/jq/"&gt;&lt;code&gt;jq&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The idea is to get the current &lt;a href="https://foosel.net/til/how-to-add-json-feed-support-to-hugo/"&gt;&lt;code&gt;feed.json&lt;/code&gt;&lt;/a&gt; prior to publishing the page, and then compare it to the one that was just generated during the build. If there are any differences, we know that there are new posts and can trigger further actions from there.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I&rsquo;m currently looking into ways to automate some stuff around new posts on this page (be it blog or TIL post) directly during the page build on GitHub Actions. For this, I first need to be able to reliably <em>detect</em> new posts, from a bash run step. So here&rsquo;s how to do that with <a href="https://stedolan.github.io/jq/"><code>jq</code></a>.</p>
<p>The idea is to get the current <a href="https://foosel.net/til/how-to-add-json-feed-support-to-hugo/"><code>feed.json</code></a> prior to publishing the page, and then compare it to the one that was just generated during the build. If there are any differences, we know that there are new posts and can trigger further actions from there.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Get current feed.json</span>
</span></span><span style="display:flex;"><span>curl -s https://foosel.net/til/feed.json &gt; feed.current.json
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Get new feed.json</span>
</span></span><span style="display:flex;"><span>cp public/til/feed.json feed.next.json
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Compare the two, this is where the magic happens</span>
</span></span><span style="display:flex;"><span>jq --slurpfile current til.current.json --slurpfile next til.next.json -n <span style="color:#e6db74">&#39;$next[0].items - $current[0].items&#39;</span> &gt; til.json
</span></span></code></pre></div><p>Let&rsquo;s go through this <code>jq</code> command there:</p>
<ul>
<li><code>--slurpfile &lt;variable&gt; &lt;file&gt;</code> reads in the given files and makes it accessible as an array contained in the given variable. In this case we read in <code>til.current.json</code> and make it accessible as <code>$current</code>, and also read in <code>til.next.json</code> and make it accessible as <code>$next</code>.</li>
<li><code>-n</code> doesn&rsquo;t wait for input on stdin.</li>
<li><code>'$next[0].items - $current[0].items'</code> subtracts the items from the new feed from the items in the current feed<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup>.</li>
<li><code>&gt; til.json</code> writes the output to <code>til.json</code>.</li>
</ul>
<p><code>til.json</code> will then contain all new items (as long as there weren&rsquo;t more than the feed&rsquo;s item size), can be uploaded as an artifact and then used in further jobs<sup id="fnref:2"><a href="#fn:2" class="footnote-ref" role="doc-noteref">2</a></sup>.</p>
<div class="footnotes" role="doc-endnotes">
<hr>
<ol>
<li id="fn:1">
<p>The indexing (e.g. <code>$new[0]</code>) here is needed due to <code>--slurpfile</code> creating an array from the read file. I admittedly need to experiment more with this option to fully understand it, but for the purpose here it works.&#160;<a href="#fnref:1" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
<li id="fn:2">
<p>My current goal is to move my announcements on Mastodon for new posts from my NodeRED install got the page build, and also send any webmentions for links contained in new posts as well.&#160;<a href="#fnref:2" class="footnote-backref" role="doc-backlink">&#x21a9;&#xfe0e;</a></p>
</li>
</ol>
</div>
]]></content:encoded></item><item><title>TIL: How to add JSON Feed support to Hugo</title><link>https://foosel.net/til/2023-01-29-how-to-add-json-feed-support-to-hugo/</link><pubDate>Sun, 29 Jan 2023 00:00:00 +0000</pubDate><guid>https://foosel.net/til/2023-01-29-how-to-add-json-feed-support-to-hugo/</guid><description>&lt;p&gt;In order to add &lt;a href="https://www.jsonfeed.org/"&gt;JSON Feed 1.1 support&lt;/a&gt; to &lt;a href="https://gohugo.io"&gt;Hugo&lt;/a&gt; you need to first add a new &lt;code&gt;jsonfeed&lt;/code&gt; output format in &lt;code&gt;config.yaml&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-yaml" data-lang="yaml"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;mediaTypes&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;application/feed+json&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;suffixes&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; - &lt;span style="color:#ae81ff"&gt;json&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;outputFormats&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;jsonfeed&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;mediaType&lt;/span&gt;: &lt;span style="color:#ae81ff"&gt;application/feed+json&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;baseName&lt;/span&gt;: &lt;span style="color:#ae81ff"&gt;feed&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;rel&lt;/span&gt;: &lt;span style="color:#ae81ff"&gt;alternate&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;isPlainText&lt;/span&gt;: &lt;span style="color:#66d9ef"&gt;true&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This adds a new media type &lt;code&gt;application/feed+json&lt;/code&gt; with the extension &lt;code&gt;json&lt;/code&gt; and creates a new output format &lt;code&gt;jsonfeed&lt;/code&gt; rendering into that media type with a base name of &lt;code&gt;feed&lt;/code&gt; (so &lt;code&gt;feed.json&lt;/code&gt; as &lt;a href="https://www.jsonfeed.org/version/1.1/#discovery"&gt;recommended by the JSON Feed spec&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;This then needs to be added to the outputs it should be generated for - on this page I&amp;rsquo;ve only added it to &lt;code&gt;section&lt;/code&gt;s. Again, in &lt;code&gt;config.yaml&lt;/code&gt;:&lt;/p&gt;</description><content:encoded><![CDATA[<p>In order to add <a href="https://www.jsonfeed.org/">JSON Feed 1.1 support</a> to <a href="https://gohugo.io">Hugo</a> you need to first add a new <code>jsonfeed</code> output format in <code>config.yaml</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">mediaTypes</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">application/feed+json</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">suffixes</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#ae81ff">json</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">outputFormats</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">jsonfeed</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">mediaType</span>: <span style="color:#ae81ff">application/feed+json</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">baseName</span>: <span style="color:#ae81ff">feed</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">rel</span>: <span style="color:#ae81ff">alternate</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">isPlainText</span>: <span style="color:#66d9ef">true</span>
</span></span></code></pre></div><p>This adds a new media type <code>application/feed+json</code> with the extension <code>json</code> and creates a new output format <code>jsonfeed</code> rendering into that media type with a base name of <code>feed</code> (so <code>feed.json</code> as <a href="https://www.jsonfeed.org/version/1.1/#discovery">recommended by the JSON Feed spec</a>).</p>
<p>This then needs to be added to the outputs it should be generated for - on this page I&rsquo;ve only added it to <code>section</code>s. Again, in <code>config.yaml</code>:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">outputs</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">home</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">HTML</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">JSON</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">section</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">HTML</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">RSS</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">jsonfeed</span>
</span></span></code></pre></div><p>Finally, a template needs to be created so that Hugo can actually render something. I&rsquo;ve put this into <code>layouts/_default/list.jsonfeed.json</code> (following the expected naming scheme of <code>list.&lt;outputFormat&gt;.&lt;extension&gt;</code>):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-go-text-template" data-lang="go-text-template"><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$pctx</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">.</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">.IsHome</span> <span style="color:#75715e">-}}{{</span> <span style="color:#a6e22e">$pctx</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">site</span> <span style="color:#75715e">}}{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$pages</span> <span style="color:#f92672">:=</span> <span style="color:#66d9ef">slice</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#66d9ef">or</span> <span style="color:#a6e22e">$.IsHome</span> <span style="color:#a6e22e">$.IsSection</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$pages</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">$pctx</span><span style="color:#a6e22e">.RegularPages</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">else</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$pages</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">$pctx</span><span style="color:#a6e22e">.Pages</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$limit</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">site</span><span style="color:#a6e22e">.Config.Services.RSS.Limit</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#66d9ef">ge</span> <span style="color:#a6e22e">$limit</span> <span style="color:#a6e22e">1</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$pages</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">$pages</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">first</span> <span style="color:#a6e22e">$limit</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">-}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$title</span> <span style="color:#f92672">:=</span> <span style="color:#e6db74">&#34;&#34;</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#66d9ef">eq</span> <span style="color:#a6e22e">.Title</span> <span style="color:#a6e22e">.Site.Title</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$title</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">.Site.Title</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">else</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">with</span> <span style="color:#a6e22e">.Title</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$title</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">print</span> <span style="color:#a6e22e">.</span> <span style="color:#e6db74">&#34; on &#34;</span><span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$title</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">print</span> <span style="color:#a6e22e">$title</span> <span style="color:#a6e22e">.Site.Title</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>    &#34;version&#34;: &#34;https://jsonfeed.org/version/1.1&#34;,
</span></span><span style="display:flex;"><span>    &#34;title&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">$title</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>    &#34;home_page_url&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Permalink</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">with</span>  <span style="color:#a6e22e">.OutputFormats.Get</span> <span style="color:#e6db74">&#34;jsonfeed&#34;</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>    &#34;feed_url&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Permalink</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span>  <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#f92672">(</span><span style="color:#66d9ef">or</span> <span style="color:#a6e22e">.Site.Params.author</span> <span style="color:#a6e22e">.Site.Params.author_url</span><span style="color:#f92672">)</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>    &#34;authors&#34;: [{
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">.Site.Params.author</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>        &#34;name&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Site.Params.author</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">.Site.Params.author_url</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>        &#34;url&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Site.Params.author_url</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>    }],
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">$pages</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>    &#34;items&#34;: [
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">range</span> <span style="color:#a6e22e">$index</span><span style="color:#f92672">,</span> <span style="color:#a6e22e">$element</span> <span style="color:#f92672">:=</span> <span style="color:#a6e22e">$pages</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">with</span> <span style="color:#a6e22e">$element</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">$index</span> <span style="color:#75715e">}}</span>,<span style="color:#75715e">{{</span><span style="color:#66d9ef">end</span><span style="color:#75715e">}}</span> {
</span></span><span style="display:flex;"><span>            &#34;title&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Title</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>            &#34;id&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Permalink</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>            &#34;url&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Permalink</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">.Site.Params.showFullTextinJSONFeed</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>            &#34;summary&#34;: <span style="color:#75715e">{{</span> <span style="color:#66d9ef">with</span> <span style="color:#a6e22e">.Description</span> <span style="color:#75715e">}}{{</span> <span style="color:#a6e22e">.</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}{{</span> <span style="color:#66d9ef">else</span> <span style="color:#75715e">}}{{</span> <span style="color:#a6e22e">.Summary</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}{{</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">-}}</span>,
</span></span><span style="display:flex;"><span>            &#34;content_html&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Content</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">else</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>            &#34;content_text&#34;: <span style="color:#75715e">{{</span> <span style="color:#66d9ef">with</span> <span style="color:#a6e22e">.Description</span> <span style="color:#75715e">}}{{</span> <span style="color:#a6e22e">.</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}{{</span> <span style="color:#66d9ef">else</span> <span style="color:#75715e">}}{{</span> <span style="color:#a6e22e">.Summary</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}{{</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">-}}</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">.Params.cover.image</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">{{-</span> <span style="color:#a6e22e">$cover</span> <span style="color:#f92672">:=</span> <span style="color:#f92672">(</span><span style="color:#a6e22e">.Resources.ByType</span> <span style="color:#e6db74">&#34;image&#34;</span><span style="color:#f92672">)</span><span style="color:#a6e22e">.GetMatch</span> <span style="color:#f92672">(</span><span style="color:#66d9ef">printf</span> <span style="color:#e6db74">&#34;*%s*&#34;</span> <span style="color:#f92672">(</span><span style="color:#a6e22e">.Params.cover.image</span><span style="color:#f92672">))</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">$cover</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>            &#34;image&#34;: <span style="color:#75715e">{{</span> <span style="color:#f92672">(</span><span style="color:#a6e22e">path</span><span style="color:#a6e22e">.Join</span> <span style="color:#a6e22e">.RelPermalink</span> <span style="color:#a6e22e">$cover</span><span style="color:#f92672">)</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">absURL</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>,
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>            &#34;date_published&#34;: <span style="color:#75715e">{{</span> <span style="color:#a6e22e">.Date.Format</span> <span style="color:#e6db74">&#34;2006-01-02T15:04:05Z07:00&#34;</span> <span style="color:#f92672">|</span> <span style="color:#a6e22e">jsonify</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">{{-</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>    ]
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">{{</span> <span style="color:#66d9ef">end</span> <span style="color:#75715e">}}</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>By default, this generates a feed with summaries only. If you want a full content feed, set <code>params.showFullTextinJSONFeed</code> to <code>true</code> in <code>config.yaml</code>.</p>
<p>The relevant docs for custom media types, output formats and template locations can be found <a href="https://gohugo.io/templates/output-formats/">here</a>.</p>
<p>On <a href="https://github.com/adityatelange/hugo-PaperMod">the Papermod theme</a> the above will automatically cause something like</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#f92672">link</span> <span style="color:#a6e22e">rel</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;alternate&#34;</span> <span style="color:#a6e22e">type</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;application/feed+json&#34;</span> <span style="color:#a6e22e">href</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;https://foosel.net/til/feed.json&#34;</span>&gt;
</span></span></code></pre></div><p>to be added to the <code>head</code> of the page, as needed for <a href="https://www.jsonfeed.org/version/1.1/#discovery">discovery</a>. In other themes you might have to do it yourself.</p>
<p>The result of all of this is something like <a href="https://foosel.net/til/feed.json">this</a>.</p>
]]></content:encoded></item></channel></rss>