mirror of
https://github.com/foo-dogsquared/hugo-theme-contentful.git
synced 2025-01-31 04:58:03 +00:00
180 lines
11 KiB
XML
180 lines
11 KiB
XML
<?xml version="1.0" encoding="utf-8" ?>
|
||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||
<title>Contentful</title>
|
||
|
||
<link rel="self" type="application/atom+xml" href="https://foo-dogsquared.github.io/hugo-theme-contentful/recipes/feed.atom"/><link rel="canonical" type="text/html" href="https://foo-dogsquared.github.io/hugo-theme-contentful/recipes/"/><link rel="alternate" type="application/feed+json" href="https://foo-dogsquared.github.io/hugo-theme-contentful/recipes/feed.json"/><link rel="alternate" type="application/rss+xml" href="https://foo-dogsquared.github.io/hugo-theme-contentful/recipes/feed.rss"/><rights>© 2022 </rights>
|
||
<generator uri="https://gohugo.io/" version="0.98.0">Hugo</generator>
|
||
<updated>2020-05-12T17:25:55+08:00</updated>
|
||
<id>https://foo-dogsquared.github.io/hugo-theme-contentful/</id><icon>https://foo-dogsquared.github.io/hugo-theme-contentful/icon.png</icon>
|
||
<author>
|
||
<name>John Doe</name>
|
||
<email>johndoe@example.com</email>
|
||
</author><entry>
|
||
<id>https://foo-dogsquared.github.io/hugo-theme-contentful/recipes/simple-icons-integration/</id>
|
||
<title type="text">Simple Icons integration with Hugo modules</title>
|
||
<link rel="alternate" href="https://foo-dogsquared.github.io/hugo-theme-contentful/recipes/simple-icons-integration/" hreflang="en" title="Simple Icons integration with Hugo modules"/><category term="tag1"/><category term="tag2"/>
|
||
<published>2020-10-20T21:36:34+08:00</published>
|
||
<updated>2022-05-13T18:08:06+08:00</updated><content type="html"><div class="paragraph">
|
||
<p><a href="https://github.com/simple-icons/simple-icons">Simple Icons</a> is a free and open source icon set for popular brands including social media sites such as Twitter, YouTube, Twitch, GitHub, and so on.
|
||
This is a perfect component for getting social media icons.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Usually to make use of this icon set in Hugo, you would have to download each icon you need.
|
||
Luckily, there’s an easier way to make use of the set with <a href="https://gohugo.io/hugo-modules/">Hugo modules</a>.
|
||
In the future, Hugo will have an easier way to <a href="https://discourse.gohugo.io/t/esbuild-looks-like-we-can-finally-get-solid-hugo-modules-support/28757">integrate</a> <a href="https://gohugo.io/commands/hugo_mod_npm/#readout">with JavaScript modules</a>.
|
||
<sup class="footnote">[<a id="_footnoteref_1" class="footnote" href="#_footnotedef_1" title="View footnote.">1</a>]</sup></p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>To get started, simply initialize your Hugo site as a Hugo module with <code>hugo mod init $HUGO_MOD_NAME</code> where <code>$HUGO_MOD_NAME</code> is simply the name of the Hugo module which could be anything.
|
||
For example, if you host your Hugo site on GitHub pages, you might want to name your module like <code>github.com/$USER/$HUGO_SITE_REPO</code>.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Then, add the Simple Icons repo as a dependency module in your site configuration.
|
||
The following configuration gets the icon set and the metadata and places them at <code>assets/icons</code> and <code>data/simple-icons.json</code> respectively.</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre class="highlight"><code class="language-toml" data-lang="toml">[[module.imports]]
|
||
path = &#34;github.com/simple-icons/simple-icons&#34;
|
||
[[module.imports.mounts]]
|
||
source = &#34;icons&#34;
|
||
target = &#34;assets/icons&#34;
|
||
[[module.imports.mounts]]
|
||
source = &#34;_data/simple-icons.json&#34;
|
||
target = &#34;data/simple-icons.json&#34;</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Onto the interesting point which is using the icons itself.
|
||
Since the icon set is stored in the assets folder, we can then use it in our templates.</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre class="highlight"><code class="language-go" data-lang="go">{{ $github_icon := resources.Get &#34;icons/github.svg&#34; }}
|
||
{{ $github_icon.Content | safeHTML }}</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>And the SVG source will be applied inline to the resulting page.
|
||
This opens up a lot of uses with the icon set.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Let’s reimplement the <a href="../configurable-list-of-contacts.html">configurable list of contacts</a> with added feature of adding an icon from the set with each key serves as the icon to be displayed.</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre class="highlight"><code class="language-go" data-lang="go">&lt;address&gt;
|
||
{{- range (sort $.Site.Data.contacts &#34;weight&#34; &#34;asc&#34;) -}}
|
||
&lt;a rel=&#34;me&#34; href=&#34;{{ .url }}&#34; aria-contact=&#34;{{ .name }}&#34;&gt;
|
||
{{ $location := printf &#34;icons/%s.svg&#34; .id }}
|
||
{{ with resources.Get $location }}{{ .Content | safeHTML }}{{ end }}&lt;/a&gt; |
|
||
{{- end -}}
|
||
&lt;/address&gt;</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Unfortunately, this doesn’t take account for missing icons so a fallback would be handy.
|
||
For now, we’ll use text as our fallback even though it’s not going to be pretty.</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre class="highlight"><code class="language-go" data-lang="go">&lt;address&gt;
|
||
{{- range (sort $.Site.Data.contacts &#34;weight&#34; &#34;asc&#34;) -}}
|
||
&lt;a rel=&#34;me&#34; href=&#34;{{ .url }}&#34; aria-contact=&#34;{{ .name }}&#34;&gt;
|
||
{{ $location := printf &#34;icons/%s.svg&#34; .id }}
|
||
{{ $icon := resources.Get $location }}
|
||
{{ if (countrunes $icon.Content) }}
|
||
{{ .Content | safeHTML }}
|
||
{{ else }}
|
||
{{ .name }}
|
||
{{ end }}
|
||
&lt;/a&gt; |
|
||
{{- end -}}
|
||
&lt;/address&gt;</code></pre>
|
||
</div>
|
||
</div>
|
||
<div id="footnotes">
|
||
<hr/>
|
||
<div class="footnote" id="_footnotedef_1">
|
||
<a href="#_footnoteref_1">1</a>. Or integrating with NPM which <a href="https://gohugo.io/news/0.75.0-relnotes/">Hugo</a> certain has more support in the upcoming version.
|
||
</div>
|
||
</div>
|
||
</content>
|
||
</entry><entry>
|
||
<id>https://foo-dogsquared.github.io/hugo-theme-contentful/recipes/configurable-list-of-contacts/</id>
|
||
<title type="text">Configurable list of contacts</title>
|
||
<link rel="alternate" href="https://foo-dogsquared.github.io/hugo-theme-contentful/recipes/configurable-list-of-contacts/" hreflang="en" title="Configurable list of contacts"/>
|
||
<published>2020-10-20T20:38:24+08:00</published>
|
||
<updated>2022-05-13T18:08:06+08:00</updated><content type="html"><div class="paragraph">
|
||
<p>Most themes offer quick social media links with site configuration.
|
||
However, it is only limited to popular media sites such as Facebook, Twitter, Instagram, GitHub, etc.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>To get around this, we’ll make use of <a href="https://gohugo.io/templates/data-templates/">data templates</a>.
|
||
Let’s create a quick game plan how does it work.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>The data is a top-level dictionary/object with each key contains an object with the following fields.</p>
|
||
</div>
|
||
<div class="ulist">
|
||
<ul>
|
||
<li>
|
||
<p><code>url</code> is the… contact link itself and it is required to have it.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>name</code> is the text to appear in the output.
|
||
Also required to have.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>weight</code> is an integer similar to how Hugo sorts the pages with the lower weight having high precedence;
|
||
if this key is absent, it will be interpreted as 0.</p>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>And here’s the data example in TOML which is placed in <code>data/contact.toml</code>.</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre class="highlight"><code class="language-toml" data-lang="toml">[github]
|
||
name = &#34;GitHub&#34;
|
||
url = &#34;https://github.com/foo-dogsquared&#34;
|
||
|
||
[gitlab]
|
||
name = &#34;Gitlab&#34;
|
||
url = &#34;https://gitlab.com/foo-dogsquared&#34;
|
||
|
||
[keybase]
|
||
name = &#34;Keybase&#34;
|
||
url = &#34;https://keybase.io/foo_dogsquared&#34;
|
||
weight = -1
|
||
|
||
[twitter]
|
||
name = &#34;Twitter&#34;
|
||
url = &#34;https://twitter.com/foo_dogsquared&#34;</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>I want my Keybase profile to appear first than anything else for whatever reason so the <code>weight</code> key is set to -1.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>With this data, we can then create a template out of it.
|
||
I’ve put the following template in a partial named <code>contacts</code> (i.e., <code>layouts/partials/contacts</code>).</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre class="highlight"><code class="language-go" data-lang="go">&lt;address&gt;
|
||
{{- range (sort $.Site.Data.contacts &#34;weight&#34; &#34;asc&#34;) -}}
|
||
| &lt;a rel=&#34;me&#34; href=&#34;{{ .url }}&#34;&gt;{{- .name -}}&lt;/a&gt; |
|
||
{{- end -}}
|
||
&lt;/address&gt;</code></pre>
|
||
</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>A suggestion (and an exercise) for extending this is to create image links.
|
||
Maybe add another key named <code>image</code> that accepts either URL.
|
||
The <code>name</code> would now be the image alternative text.</p>
|
||
</div>
|
||
</content>
|
||
</entry></feed>
|