<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Hugo Hints and Tips on Much Ado About IT</title><link>https://it.knightnet.org.uk/kb/hugo/</link><description>
Recent content about Hugo Hints and Tips from Much Ado About IT |
Ramblings and rantings from IT Architect &amp; Designer, Julian Knight</description><generator>Hugo | gohugo.io | Theme twenty-sixteen</generator><language>en-gb</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><lastBuildDate>Mon, 24 Apr 2023 21:27:28 +0000</lastBuildDate><atom:link href="https://it.knightnet.org.uk/kb/hugo/feed.xml" rel="self" type="application/rss+xml"/><item><title>Embed a diagram in a Hugo page</title><link>https://it.knightnet.org.uk/kb/hugo/embed-diagram/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/hugo/embed-diagram/</guid><pubDate>Fri, 14 Dec 2018 12:56:01 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/hugo/embed-diagram/</guid><description><div>It is great to be able to define a diagram in code directly in your web pages. This article shows you one way to achieve that using Gravizo.</div><div>&lt;h2 id="summary">Summary&lt;/h2>
&lt;p>We want to be able to generate neat diagrams for our website. This can, of course, be done offline using Microsoft Visio
or some other diagramming tool. There are online ones too. But sometimes, we want to be able to generate a diagram
using code or we just need something quick and simple. That is where tools such as &lt;a href="http://graphviz.org/">GraphViz&lt;/a> or
&lt;a href="https://www.gravizo.com/#PlantUML">PlantUML&lt;/a> come in handy.&lt;/p>
&lt;p>But currently, there are no direct addin&amp;rsquo;s for Hugo to achieve this.&lt;/p>
&lt;p>We can, however, use an external tool to create the diagram dynamically from code embedded in the page.
There are several tools that we could use, I will update this page as and when I try those tools.&lt;/p>
&lt;h2 id="mermaidjs">MermaidJS&lt;/h2>
&lt;p>&lt;a href="https://mermaidjs.github.io/">MermaidJS&lt;/a> is a JavaScript library that you can easily embed on your page. It is widely used and well supported.&lt;/p>
&lt;p>Mermaid supports several types of diagram including: Sequence, Flowchart, Gantt (timeline), Class (beta), Git graph (beta).&lt;/p>
&lt;p>MermaidJS is available for installation on your own configuration using Node.JS or you can use the UnPkg CDN.&lt;/p>
&lt;h2 id="gravizo">Gravizo&lt;/h2>
&lt;p>We can use &lt;a href="https://www.gravizo.com/">Gravizo&lt;/a> to embed diagrams of various kinds in a web site.&lt;/p>
&lt;p>Gravizo has a number of ways to embed or access the source and supports GraphViz (DOT language), PlantUML and
UMLGraph (though there are some limitations on the latter).&lt;/p>
&lt;p>Graviso will produce the following types of diagram: Graph (DOT), UML Sequence, UML State, UML Class, Activity, SVG custom.&lt;/p>
&lt;p>You can output the diagram as SVG or PNG graphics by changing the URL.&lt;/p>
&lt;p>Note that you are using a 3rd party website if you use these methods. As always, I recommend turning off 3rd-party cookie support
in your browser to help prevent any tracking. The advantage however, is that you don&amp;rsquo;t need any JavaScript on your page.&lt;/p>
&lt;h3 id="using-a-hugo-custom-shortcode">Using a Hugo custom shortcode&lt;/h3>
&lt;p>&lt;code>shortcodes/gravizo.html&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">{{ $title := &amp;#34;Diagram&amp;#34; }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">{{ if .IsNamedParams }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {{ with .Get &amp;#34;title&amp;#34; }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {{ $title = . }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {{ end }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">{{ else }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {{ with .Get 0 }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {{ $title = . }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> {{ end }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">{{ end }}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">figure&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">img&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="na">src&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#39;https://g.gravizo.com/svg?{{ .Inner }}&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="na">alt&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#39;{{ $title }}&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">figcaption&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>{{ $title }}&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">figcaption&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">figure&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>To use:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">{ {&lt;span class="p">&amp;lt;&lt;/span> &lt;span class="nt">gravizo&lt;/span> &lt;span class="err">&amp;#34;&lt;/span>&lt;span class="na">DOT&lt;/span> &lt;span class="na">Language&lt;/span> &lt;span class="err">(&lt;/span>&lt;span class="na">GraphViz&lt;/span>&lt;span class="err">)&lt;/span> &lt;span class="na">Example&lt;/span>&lt;span class="err">&amp;#34;&lt;/span> &lt;span class="p">&amp;gt;&lt;/span>}}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> digraph G {
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> aize =&amp;#34;4,4&amp;#34;;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> main [shape=box];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> main -&amp;gt; parse [weight=8];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> parse -&amp;gt; execute;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> main -&amp;gt; init [style=dotted];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> main -&amp;gt; cleanup;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> execute -&amp;gt; { make_string; printf}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> init -&amp;gt; make_string;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> edge [color=red];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> main -&amp;gt; printf [style=bold,label=&amp;#34;100 times&amp;#34;];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> make_string [label=&amp;#34;make a string&amp;#34;];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> node [shape=box,style=filled,color=&amp;#34;.7 .3 1.0&amp;#34;];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> execute -&amp;gt; compare;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> }
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">{ {&lt;span class="p">&amp;lt;&lt;/span> &lt;span class="p">/&lt;/span>&lt;span class="nt">gravizo&lt;/span> &lt;span class="p">&amp;gt;&lt;/span>}}&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;figure>
&lt;img
src='https://g.gravizo.com/svg?%0a%20%20digraph%20G%20%7b%0a%20%20%20%20aize%20%3d%224%2c4%22%3b%0a%20%20%20%20main%20%5bshape%3dbox%5d%3b%0a%20%20%20%20main%20-%3e%20parse%20%5bweight%3d8%5d%3b%0a%20%20%20%20parse%20-%3e%20execute%3b%0a%20%20%20%20main%20-%3e%20init%20%5bstyle%3ddotted%5d%3b%0a%20%20%20%20main%20-%3e%20cleanup%3b%0a%20%20%20%20execute%20-%3e%20%7b%20make_string%3b%20printf%7d%0a%20%20%20%20init%20-%3e%20make_string%3b%0a%20%20%20%20edge%20%5bcolor%3dred%5d%3b%0a%20%20%20%20main%20-%3e%20printf%20%5bstyle%3dbold%2clabel%3d%22100%20times%22%5d%3b%0a%20%20%20%20make_string%20%5blabel%3d%22make%20a%20string%22%5d%3b%0a%20%20%20%20node%20%5bshape%3dbox%2cstyle%3dfilled%2ccolor%3d%22.7%20.3%201.0%22%5d%3b%0a%20%20%20%20execute%20-%3e%20compare%3b%0a%20%20%7d%0a'
alt='DOT Language (GraphViz) Example'
/>
&lt;figcaption>DOT Language (GraphViz) Example&lt;/figcaption>
&lt;/figure>
&lt;figure>
&lt;img
src='https://g.gravizo.com/svg?%0a%20%20%40startuml%3b%0a%0a%20%20actor%20User%3b%0a%20%20participant%20%22First%20Class%22%20as%20A%3b%0a%20%20participant%20%22Second%20Class%22%20as%20B%3b%0a%20%20participant%20%22Last%20Class%22%20as%20C%3b%0a%0a%20%20User%20-%3e%20A%3a%20DoWork%3b%0a%20%20activate%20A%3b%0a%0a%20%20A%20-%3e%20B%3a%20Create%20Request%3b%0a%20%20activate%20B%3b%0a%0a%20%20B%20-%3e%20C%3a%20DoWork%3b%0a%20%20activate%20C%3b%0a%0a%20%20C%20--%3e%20B%3a%20WorkDone%3b%0a%20%20destroy%20C%3b%0a%0a%20%20B%20--%3e%20A%3a%20Request%20Created%3b%0a%20%20deactivate%20B%3b%0a%0a%20%20A%20--%3e%20User%3a%20Done%3b%0a%20%20deactivate%20A%3b%0a%0a%20%20%40enduml%0a'
alt='PlantUML Example'
/>
&lt;figcaption>PlantUML Example&lt;/figcaption>
&lt;/figure>
&lt;p>Note that the UMLGraph example below from the Gravizo website doesn&amp;rsquo;t
work in this context - it is unclear why but I expect it to be
something to do with an invalid HTML entity.&lt;/p>
&lt;figure>
&lt;img
src='https://g.gravizo.com/svg?%0a%20%20%2f%2a%2a%0a%20%20%20%20%2aStructural%20Things%0a%20%20%20%20%2a%40opt%20commentname%0a%20%20%20%20%2a%40note%20Notes%20can%0a%20%20%20%20%2abe%20extended%20to%0a%20%20%20%20%2aspan%20multiple%20lines%0a%20%20%20%20%2a%2f%0a%20%20%20%20class%20Structural%7b%7d%0a%0a%20%20%20%20%2f%2a%2a%0a%20%20%20%20%2a%40opt%20all%0a%20%20%20%20%2a%40note%20Class%0a%20%20%20%20%2a%2f%0a%20%20%20%20class%20Counter%20extends%20Structural%20%7b%0a%20%20%20%20%20%20%20%20%20%20%20%20static%20public%20int%20counter%3b%0a%20%20%20%20%20%20%20%20%20%20%20%20public%20int%20getCounter%2528%2529%3b%0a%20%20%20%20%7d%0a%0a%20%20%20%20%2f%2a%2a%0a%20%20%20%20%2a%40opt%20shape%20activeclass%0a%20%20%20%20%2a%40opt%20all%0a%20%20%20%20%2a%40note%20Active%20Class%0a%20%20%20%20%2a%2f%0a%20%20%20%20class%20RunningCounter%20extends%20Counter%7b%7d%0a%0a'
alt='UMLGraph Example'
/>
&lt;figcaption>UMLGraph Example&lt;/figcaption>
&lt;/figure>
&lt;h3 id="inline-markdown-code">Inline Markdown code&lt;/h3>
&lt;p>An alternative to needing a shortcode is to embed the source directly into the page.&lt;/p>
&lt;p>Note that this method does not allow blank lines so the source is hard to read. This is because Markdown uses a blank line
as a paragraph separator.&lt;/p>
&lt;p>![Alt text](&lt;a href="https://g.gravizo.com/svg">https://g.gravizo.com/svg&lt;/a>?
@startuml;
actor User;
participant &amp;ldquo;First Class&amp;rdquo; as A;
participant &amp;ldquo;Second Class&amp;rdquo; as B;
participant &amp;ldquo;Last Class&amp;rdquo; as C;
User -&amp;gt; A: DoWork;
activate A;
A -&amp;gt; B: Create Request;
activate B;
B -&amp;gt; C: DoWork;
activate C;
C &amp;ndash;&amp;gt; B: WorkDone;
destroy C;
B &amp;ndash;&amp;gt; A: Request Created;
deactivate B;
A &amp;ndash;&amp;gt; User: Done;
deactivate A;
@enduml
)&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">![&lt;span class="nt">Alt text&lt;/span>](&lt;span class="na">https://g.gravizo.com/svg?
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">@startuml;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">actor User;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">participant &amp;#34;First Class&amp;#34; as A;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">participant &amp;#34;Second Class&amp;#34; as B;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">participant &amp;#34;Last Class&amp;#34; as C;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">User -&amp;gt; A: DoWork;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">activate A;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">A -&amp;gt; B: Create Request;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">activate B;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">B -&amp;gt; C: DoWork;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">activate C;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">C --&amp;gt; B: WorkDone;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">destroy C;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">B --&amp;gt; A: Request Created;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">deactivate B;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">A --&amp;gt; User: Done;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">deactivate A;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">@enduml
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">&lt;/span>)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This method &lt;strong>does&lt;/strong> allow the UMLGraph example to work as long as you remove
the blank lines:&lt;/p>
&lt;p>![Alt text](&lt;a href="https://g.gravizo.com/svg">https://g.gravizo.com/svg&lt;/a>?
/**
*Structural Things
*@opt commentname
*@note Notes can
*be extended to
&lt;em>span multiple lines
&lt;em>/
class Structural{}
/&lt;/em>&lt;/em>
*@opt all
&lt;em>@note Class
&lt;em>/
class Counter extends Structural {
static public int counter;
public int getCounter%28%29;
}
/&lt;/em>&lt;/em>
*@opt shape activeclass
*@opt all
*@note Active Class
*/
class RunningCounter extends Counter{}
)&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">![&lt;span class="nt">Alt text&lt;/span>](&lt;span class="na">https://g.gravizo.com/svg?
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> /**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *Structural Things
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *@opt commentname
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *@note Notes can
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *be extended to
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *span multiple lines
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> */
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> class Structural{}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> /**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *@opt all
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *@note Class
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> */
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> class Counter extends Structural {
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> static public int counter;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> public int getCounter%28%29;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> }
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> /**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *@opt shape activeclass
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *@opt all
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> *@note Active Class
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> */
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na"> class RunningCounter extends Counter{}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="na">&lt;/span>)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/hugo">Hugo</category><category domain="https://it.knightnet.org.uk/tags/hugo">Hugo</category><category domain="https://it.knightnet.org.uk/tags/diagrams">Diagrams</category></item><item><title>Automatically updating Hugo</title><link>https://it.knightnet.org.uk/kb/hugo/get-latest-version/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/hugo/get-latest-version/</guid><pubDate>Tue, 29 May 2018 21:28:30 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/hugo/get-latest-version/</guid><description><div>Hugo is still changing very quickly. So it is helpful to be able to easily download and install the latest version directly from GitHub.</div><div>&lt;h2 id="summary">Summary&lt;/h2>
&lt;p>The tricks are firstly to use GitHub&amp;rsquo;s &lt;code>latest&lt;/code> link for software releases and download the webpage. Secondly, to find the link to the actual software download in
the content of the page. Once you have this, you can download the latest built version file automatically, unpack it over the top of the existing files and then
delete the downloaded file.&lt;/p>
&lt;p>&lt;strong>NOTE&lt;/strong>: For hopefully obvious reasons, the Hugo server cannot be running when you run this.&lt;/p>
&lt;p>Many thanks to &lt;a href="https://discourse.gohugo.io/u/pgr">@pgr&lt;/a> on the &lt;a href="https://discourse.gohugo.io/t/clever-link-to-latest-hugo-version-download/12178">Hugo Discourse for the original idea&lt;/a>.&lt;/p>
&lt;h2 id="using-powershell-on-windows-10">Using PowerShell on Windows 10&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-PowerShell" data-lang="PowerShell">&lt;span class="line">&lt;span class="cl">&lt;span class="c"># get-hugo.ps1&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Get the latest copy of Hugo for Windows (64bit) from GitHub and install it&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># -- CHANGE THESE IF NEEDED -- #&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># The folder containing the Hugo `bin` subfolder&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">$hugoRoot&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;c:\Hugo&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># A regular expression to find the right platform link name&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">$hugoPlatform&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;Windows\-64bit\.zip&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Location of the Hugo executable (relative to $hugoRoot or use absolute path)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">$hugoBin&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;bin&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># ---------------------------- #&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># ================================================== #&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># -- Shouldn&amp;#39;t need to change anything below here -- #&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># ================================================== #&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">Set-LocationEx&lt;/span> &lt;span class="n">-Path&lt;/span> &lt;span class="nv">$hugoRoot&lt;/span> &lt;span class="c"># AKA `cd ...`&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Make TLS 1.2 the primary version otherwise get from most sites will fail&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">[&lt;/span>&lt;span class="no">Net.ServicePointManager&lt;/span>&lt;span class="p">]::&lt;/span>&lt;span class="n">SecurityProtocol&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="s2">&amp;#34;tls12, tls11, tls&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Get the GitHub page containing the latest version of Hugo&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">$latest&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="nb">Invoke-WebRequest&lt;/span> &lt;span class="n">-Uri&lt;/span> &lt;span class="n">https&lt;/span>&lt;span class="err">:&lt;/span>&lt;span class="p">//&lt;/span>&lt;span class="n">github&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">com&lt;/span>&lt;span class="p">/&lt;/span>&lt;span class="n">gohugoio&lt;/span>&lt;span class="p">/&lt;/span>&lt;span class="n">hugo&lt;/span>&lt;span class="p">/&lt;/span>&lt;span class="n">releases&lt;/span>&lt;span class="p">/&lt;/span>&lt;span class="n">latest&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Find the file details for the Windows 64bit version&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">$file&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="nv">$latest&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="py">ParsedHtml&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="py">links&lt;/span> &lt;span class="p">|&lt;/span> &lt;span class="nb">Where-Object&lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="nv">$_&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="py">nameProp&lt;/span> &lt;span class="o">-match&lt;/span> &lt;span class="nv">$hugoPlatform&lt;/span>&lt;span class="p">}&lt;/span> &lt;span class="p">|&lt;/span> &lt;span class="nb">select &lt;/span>&lt;span class="n">pathname&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">nameProp&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Download the actual file&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">Invoke-WebRequest&lt;/span> &lt;span class="n">-Uri&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;https://github.com/&amp;#34;&lt;/span> &lt;span class="p">+&lt;/span> &lt;span class="nv">$file&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">pathname&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="n">-OutFile&lt;/span> &lt;span class="nv">$file&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="py">nameProp&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Unpack the zip file into the `bin` folder - NOTE: This requires PowerShell v5 or above (Windows 10 1709)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">Microsoft&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="py">PowerShell&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">Archive&lt;/span>&lt;span class="p">\&lt;/span>&lt;span class="nb">Expand-Archive&lt;/span> &lt;span class="n">-Path&lt;/span> &lt;span class="nv">$file&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="py">nameProp&lt;/span> &lt;span class="n">-DestinationPath&lt;/span> &lt;span class="nv">$hugoBin&lt;/span> &lt;span class="n">-Force&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Delete the zip file&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">Remove-Item&lt;/span> &lt;span class="nv">$file&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="py">nameProp&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">#EOF&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/hugo">Hugo</category><category domain="https://it.knightnet.org.uk/tags/hugo">Hugo</category><category domain="https://it.knightnet.org.uk/tags/powershell">PowerShell</category><category domain="https://it.knightnet.org.uk/tags/automation">Automation</category><category domain="https://it.knightnet.org.uk/tags/commandline">Commandline</category></item><item><title>Hugo Cloud Deployment with Netlify</title><link>https://it.knightnet.org.uk/kb/hugo/deploy-with-netlify/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/hugo/deploy-with-netlify/</guid><pubDate>Tue, 10 Apr 2018 22:00:00 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/hugo/deploy-with-netlify/</guid><description><div>Netlify is a great cloud-based hosting and CDN service. It has great support for Hugo and other static site builders and is easily integrated into cloud-based GIT services. This makes deployment and updates a snap. \
\
On this page, we list a few snippets of information that help us remember how to do things.</div><div>&lt;p>&lt;a href="https://www.netlify.com">Netlify Website&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://app.netlify.com">Netlify Dashboard&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://gitlab.com/TotallyInformation">GitLab TotallyInformation Dashboard&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://app.forestry.io/dashboard/#/">Forestry.IO Dashboard&lt;/a>&lt;/p>
&lt;h2 id="my-new-site-creation-workflow">My new site creation workflow&lt;/h2>
&lt;ul>
&lt;li>Create a new private repository on &lt;a href="https://gitlab.com/TotallyInformation">GitLab&lt;/a> - this will host the source for the site which we keep private.&lt;/li>
&lt;li>Clone the new repo to your development device.&lt;/li>
&lt;li>Use the clone folder to create a new site.&lt;/li>
&lt;li>Clone a suitable Hugo theme as a GIT submodule to the &lt;code>themes&lt;/code> folder.&lt;/li>
&lt;li>Make any changes or add content as required.&lt;/li>
&lt;li>Commit changes for the site repo and sync back to GitLab.&lt;/li>
&lt;li>&lt;a href="https://app.netlify.com/">Create a new site in Netlify&lt;/a> that uses the GitLab repo.&lt;/li>
&lt;li>Configure Netlify as required.&lt;/li>
&lt;li>Updates to GitLab will now automatically rebuild and deploy the site.&lt;/li>
&lt;/ul>
&lt;p>If I want to have an online editor, I will also &lt;a href="https://app.forestry.io/dashboard/#/">link up Forestry.IO&lt;/a>.&lt;/p>
&lt;h2 id="my-site-update-workflow">My site update workflow&lt;/h2>
&lt;ul>
&lt;li>Make updates to the site.&lt;/li>
&lt;li>Commit changes for the site repo and sync back to GitLab.&lt;/li>
&lt;li>Netlify automatically rebuilds and deploys the site.&lt;/li>
&lt;/ul>
&lt;h2 id="testpreview-and-other-temporary-deploys">Test/Preview and other temporary deploys&lt;/h2>
&lt;p>To test or preview a site change without disturbing live, all that is needed is either:&lt;/p>
&lt;ul>
&lt;li>Create a Pull Request (AKA a Merge Request) in GitLab. Typically, this comes from someone outside
your repo/organisation.&lt;/li>
&lt;li>Create a GIT branch. This can happen on the development device or in GitLab.&lt;/li>
&lt;/ul>
&lt;p>Each PR/branch is given its own URL.&lt;/p>
&lt;p>Configuration of PR/branch versions is done via the &lt;code>netlify.toml&lt;/code> file in your site repo.&lt;/p>
&lt;h2 id="netlify-hints--tips">Netlify Hints &amp;amp; Tips&lt;/h2>
&lt;p>Netlify provides a number of environment variables. They are described &lt;a href="https://www.netlify.com/docs/continuous-deployment/#build-environment-variables">in the docs here&lt;/a>.&lt;/p>
&lt;p>It is easiest to configure Netlify using the &lt;code>netlify.toml&lt;/code> file you include in the root of your site repository.
Details on what goes in there are &lt;a href="https://www.netlify.com/docs/netlify-toml-reference/">in the docs here&lt;/a>.&lt;/p>
&lt;p>Netlify provides a Forms capability. I use this to provide a &lt;a href="https://it.knightnet.org.uk/about/contact/">contact form on this site&lt;/a>.
Data is fed back into the dashboard but you can also use Netlify&amp;rsquo;s webhooks to provide alerting for new
form submissions. I have this wired up to alerts via my Slack org.&lt;/p>
&lt;p>In addition to the &lt;code>netlify.toml&lt;/code> control file that you put in your site root, Netlify provides two additional files &lt;code>_redirects&lt;/code> and &lt;code>_headers&lt;/code>. Their use is pretty obvious but worth noting that you can &lt;strong>test&lt;/strong> those files using Netlify&amp;rsquo;s online test pages: &lt;a href="https://play.netlify.com/redirects">Test &lt;code>_redirects&lt;/code>&lt;/a>, &lt;a href="https://play.netlify.com/headers">Test &lt;code>_headers&lt;/code>&lt;/a>. Simply paste the content of the files into the test pages.&lt;/p>
&lt;h3 id="redirects">Redirects&lt;/h3>
&lt;p>It isn&amp;rsquo;t clear in the documentation but the &lt;code>_redirects&lt;/code> file has to be in your static delivery folder, &lt;code>/static&lt;/code> by default for Hugo. The file is not actually made accessible from the web. However, be careful if you ever move to alternative deployments since the file WILL then be available via the web.&lt;/p>
&lt;p>Alternatively, use the &lt;a href="https://play.netlify.com/redirects">redirects test page&lt;/a> to convert to TOML format and include that in your &lt;code>/netlify.toml&lt;/code> file.&lt;/p></div></description><author>Julian Knight</author></item><item><title>Hugo Snippets and Code Examples</title><link>https://it.knightnet.org.uk/kb/hugo/hugo-snippets/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/hugo/hugo-snippets/</guid><pubDate>Sun, 08 Apr 2018 11:00:00 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/hugo/hugo-snippets/</guid><description><div>A somewhat random collection of code for Hugo so that I don't have to keep looking things up all over the Internet.</div><div>&lt;h4 id="index">Index&lt;/h4>
&lt;!-- raw HTML omitted -->
&lt;ul>
&lt;li>&lt;a href="#markdown-oddities-and-extensions-in-hugo">Markdown oddities and extensions in Hugo&lt;/a>&lt;/li>
&lt;li>&lt;a href="#shortcode-to-render-a-code-example-in-a-pagepost">Shortcode to render a code example in a page/post&lt;/a>&lt;/li>
&lt;li>&lt;a href="#list-the-sub-sections-of-a-section">List the sub-sections of a section&lt;/a>&lt;/li>
&lt;li>&lt;a href="#reset-a-scratch-variable-to-an-empty-array-slice">Reset a Scratch variable to an empty array (slice)&lt;/a>&lt;/li>
&lt;/ul>
&lt;!-- raw HTML omitted -->
&lt;h3 id="markdown-oddities-and-extensions-in-hugo">Markdown oddities and extensions in Hugo&lt;/h3>
&lt;p>Hugo uses the &lt;a href="https://github.com/russross/blackfriday">Blackfriday&lt;/a> markdown engine.&lt;/p>
&lt;p>Some differences that you might want to be aware of:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>GitHub Flavoured&lt;/strong> Most of the GitHub style markdown features are available. The default settings are a little more strict however
(e.g. blank lines between heading and paragraph are required).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Nested Lists&lt;/strong> THere is a subtle &lt;a href="https://github.com/russross/blackfriday/issues/329">bug&lt;/a> in Blackfriday that it uses a logical tab spacing of 4 rather than the more normal (form markdown) 2.
This means that nested content in a list has to be 1 tab or 4 spaces in, not 2 spaces which is the default for most versions of markdown libraries.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Alternative Rendering Engine&lt;/strong> It is possible to use the &lt;a href="https://github.com/miekg/mmark">Mmark&lt;/a> engine instead of Blackfriday.
Put &lt;code>markup: mmark&lt;/code> in a page frontmatter or name files &lt;code>*.mmark&lt;/code>.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Header IDs&lt;/strong> Are enabled by default so each header gets an &lt;code>id&lt;/code>. e.g.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">h3&lt;/span> &lt;span class="na">id&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;shortcode-to-render-a-code-example-in-a-page-post&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>Shortcode to render a code example in a page/post&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">h3&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Dashes&lt;/strong> By default, Latex style smart dashes are used. &lt;code>--&lt;/code> is an &lt;code>&amp;amp;ndash;&lt;/code> &amp;ndash; and &lt;code>---&lt;/code> is an &lt;code>&amp;amp;mdash;&lt;/code> &amp;mdash;.
In addition, a single dash between words is translated to an &lt;code>&amp;amp;ndash;&lt;/code> e.g. &lt;code>12 June - 3 July&lt;/code> becomes &lt;code>12 June &amp;amp;ndash; 3 July&lt;/code>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Syntax Highlighting&lt;/strong> triple backticks are used to wrap code blocks. &lt;a href="https://github.com/alecthomas/chroma">Chroma&lt;/a> is used for the highlighting. &lt;br>
Alternatively, the older &lt;a href="https://gohugo.io/content-management/syntax-highlighting/">Pygments engine can be used&lt;/a>. &lt;br>
Use the &lt;code>{{ &amp;lt; highlight &amp;gt;}}&lt;/code> markup form if you want to use extended controls such as line numbers, line highlights, etc. &lt;br>
Configuration is done in &lt;code>config.toml&lt;/code>, see the &lt;a href="https://gohugo.io/content-management/syntax-highlighting/#configure-syntax-highlighter">content-management/syntax-highlighting&lt;/a>
section of the docs for details.&lt;/p>
&lt;p>The &lt;a href="https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages">list of Highlight languages is given in the docs&lt;/a>.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Definition Lists&lt;/strong> Are easily marked up as:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">Cat
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">: Fluffy animal everyone likes
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Internet
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">: Vector of transmission for pictures of cats \
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Don&amp;#39;t forget the blank line between the terms
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">: You can use multiple definition lines&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Tables&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">Name | Age
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">------|------
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Bob | 27
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Alice | 23
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Footnotes&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">This is a footnote.[^1]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">[^1]: the footnote text.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Strikethrough&lt;/strong> Uses 2 tildes &lt;code>~~&lt;/code>.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Trailing backslash&lt;/strong> Inserts a line break.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>Many of these are optional, see the &lt;a href="https://gohugo.io/content-management/formats/#blackfriday-extensions">content-management/formats&lt;/a> section of the Hugo docs for details.&lt;/p>
&lt;h3 id="shortcode-to-render-a-code-example-in-a-pagepost">Shortcode to render a code example in a page/post&lt;/h3>
&lt;p>&lt;code>layouts/shortcodes/render-code.html&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-go-html-template" data-lang="go-html-template">&lt;span class="line">&lt;span class="cl">&lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">$file&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">:=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="na">.Get&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;file&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">|&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">readFile&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">}}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">$lang&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">:=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="na">.Get&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;language&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">}}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="k">print&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;```&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">$lang&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;\n&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">$file&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;\n```&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">|&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">markdownify&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">}}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>And in a post/page:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-go-html-template" data-lang="go-html-template">&lt;span class="line">&lt;span class="cl">&lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="err">%&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">file&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;/static/some-script.js&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">language&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;js&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="err">%&lt;/span>&lt;span class="cp">}}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="list-the-sub-sections-of-a-section">List the sub-sections of a section&lt;/h3>
&lt;p>I use this on my main blog site to list out the knowledgebase sections.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-go-html-template" data-lang="go-html-template">&lt;span class="line">&lt;span class="cl">&lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">range&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">(&lt;/span>&lt;span class="nx">where&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="na">.Site.Pages&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;Section&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;kb&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">}}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">ul&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">range&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="na">.Sections&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">}}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">li&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;&lt;/span>&lt;span class="nt">a&lt;/span> &lt;span class="na">href&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;&lt;/span>&lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="na">.Permalink&lt;/span>&lt;span class="cp">}}&lt;/span>&lt;span class="s">&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="na">.LinkTitle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">}}&lt;/span> &lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">a&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;/&lt;/span>&lt;span class="nt">li&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="cp">{{&lt;/span>&lt;span class="k">end&lt;/span>&lt;span class="cp">}}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">ul&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">{{&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">end&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">}}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="reset-a-scratch-variable-to-an-empty-array-slice">Reset a Scratch variable to an empty array (slice)&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-go-html-template" data-lang="go-html-template">&lt;span class="line">&lt;span class="cl">&lt;span class="cp">{{-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="na">$.Scratch.Set&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;myvar&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nx">slice&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">-}}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/tags/hugo">Hugo</category></item><item><title>Hugo Benefits and Issues</title><link>https://it.knightnet.org.uk/kb/hugo/benefits-and-issues/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/hugo/benefits-and-issues/</guid><pubDate>Sat, 07 Apr 2018 22:00:00 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/hugo/benefits-and-issues/</guid><description><div>A discussion of Hugo vs Jekyll and WordPress.</div><div>&lt;h2 id="benefits-of-hugo-over-jekyll">Benefits of Hugo over Jekyll&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>Simple binary install for local builds.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Far easier to build a site, even from a blank theme.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://gohugo.io/content-management/shortcodes/">Shortcodes&lt;/a> - &lt;a href="https://gohugo.io/content-management/shortcodes/#example-gist-output">gist&lt;/a>,
ref and relref, speakerdeck, tweet, vimeo, youtube. &lt;strong>Plus&lt;/strong> the ability to &lt;a href="https://gohugo.io/templates/shortcode-templates/">create your own&lt;/a> very easily.&lt;/p>
&lt;p>Examples: &lt;a href="https://github.com/spf13/spf13.com/tree/master/layouts/shortcodes">spf13&lt;/a>, &lt;a href="https://github.com/gohugoio/hugo/tree/master/docs/layouts/shortcodes">Hugo Docs&lt;/a>.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>No need to faff with escaped Liquid tags - makes embedded code examples a LOT simpler.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Seems to have far more logical and useful variables such as the .Parent, etc for shortcodes.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Migration of old sites is made &lt;strong>much&lt;/strong> easier due to &lt;code>aliases&lt;/code> and &lt;code>url&lt;/code> frontmatter fields.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Use &lt;code>archetypes&lt;/code> to template creation of new pages/posts/etc&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Aliases&lt;/strong> - Why don&amp;rsquo;t other site generators use this!! Great for migrating sites. You can supply any number of aliases and Hugo
will generate a redirect page automatically - no more 404 errors when migrating.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Wordpress migration - it actually works. Not only that but it creates sensible url and date metadata. The Jekyll equivalent never worked for me.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h1 id="disbenefits-of-hugo-over-jekyll">Disbenefits of Hugo over Jekyll&lt;/h1>
&lt;ul>
&lt;li>Cannot use variables in page/post content. Have to use a shortcode.&lt;/li>
&lt;/ul>
&lt;h2 id="converting-from-jekyll">Converting from Jekyll&lt;/h2>
&lt;ul>
&lt;li>Change all instances of &lt;code>updated&lt;/code> in frontmatter to &lt;code>lastMod&lt;/code>&lt;/li>
&lt;/ul>
&lt;h2 id="converting-from-wordpress">Converting from Wordpress&lt;/h2>
&lt;ul>
&lt;li>Some posts didn&amp;rsquo;t get a &lt;code>title&lt;/code> frontmatter. They were all draft articles.&lt;/li>
&lt;li>Some posts didn&amp;rsquo;t get a proper date (1970-01-01)&lt;/li>
&lt;li>The &lt;code>excerpt&lt;/code> field used in WordPress was not converted. It still appeared in the frontmatter.
I manually (well vscode file search/replace) converted these to descriptions.&lt;/li>
&lt;li>Link tags came across as HTML rather than markdown. Not too big an issue except many didn&amp;rsquo;t have &lt;code>nofollow&lt;/code> on them. Probably that&amp;rsquo;s carried from the original though.&lt;/li>
&lt;li>Code sections came across wrapped in HTML &lt;code>&amp;lt;code&amp;gt;&amp;lt;/code&amp;gt;&lt;/code> tags instead of GitHub markdown codefenses or Hugo&amp;rsquo;s &lt;code>highlight&lt;/code> tag.&lt;/li>
&lt;li>Pages need tweaking, especially to reproduce the same custom navigation menu.&lt;/li>
&lt;li>No dynamic data (Pods, WP-Pipes, Express Curate, Feedburner redirect, Twitter mentions as comments) -
have to do this some other way or not at all.&lt;/li>
&lt;li>No automation: tag/category lookups/suggestions, no auto-dates, no auto-SEO, no auto-share&lt;/li>
&lt;li>No search&lt;/li>
&lt;li>No PODs (Custom data &amp;amp; forms) - have to export to JSON, add the json to the data folder, create a shortcode to display.&lt;/li>
&lt;li>Export from WP created a frontmatter var of dsq_thread_id as a list, this needs changing to &lt;code>disqus_identifier&lt;/code> and making text
in order for it to be used by the internal Disqus template.&lt;/li>
&lt;li>My export had some leftover frontmatter URL&amp;rsquo;s in the form &lt;code>blogger_permalink&lt;/code> from when I merged to Blogger blogs. I renamed
these as aliases.&lt;/li>
&lt;li>Draft posts came across with 1970 dates and URLs in the format ``, I removed all of the URL&amp;rsquo;s for these.&lt;/li>
&lt;/ul>
&lt;h2 id="general-gotchas">General &amp;ldquo;Gotcha&amp;rsquo;s&amp;rdquo;&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>When using a partial, make sure to pass &amp;ldquo;.&amp;rdquo; as a parameter othwise the partial does not get any context variables.&lt;/p>
&lt;p>e.g. &lt;code>{{ partial &amp;quot;partialname.html&amp;quot; . }}&lt;/code>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>When using &lt;code>hugo server&lt;/code>, pages and other resources that are moved or deleted &lt;strong>MAY&lt;/strong> not be released by
the live reloader. May need to stop/restart the server for them to actually disappear.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Site and page variables are defined without leading caps. But they are used with leading caps.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>lastMod&lt;/code> in a page frontmatter is actually used as &lt;code>.Page.Lastmod&lt;/code> - note the change of case!&lt;/p>
&lt;p>Honestly, this kind of thing really puts people off.&lt;/p>
&lt;/li>
&lt;/ul></div></description><author>Julian Knight</author></item></channel></rss>