<?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>Hugo on Stefano Chiodino</title>
    <link>https://stefano.chiodino.uk/tags/hugo/</link>
    <description>Recent content in Hugo on Stefano Chiodino</description>
    <generator>Hugo -- 0.147.7</generator>
    <language>en</language>
    <lastBuildDate>Sun, 09 Oct 2016 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://stefano.chiodino.uk/tags/hugo/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Forestry.io</title>
      <link>https://stefano.chiodino.uk/posts/forestry-io/</link>
      <pubDate>Sun, 09 Oct 2016 00:00:00 +0000</pubDate>
      <guid>https://stefano.chiodino.uk/posts/forestry-io/</guid>
      <description>A review of Forestry.io for Hugo websites</description>
      <content:encoded><![CDATA[<p>A reader of <a href="/posts/hugo-host-and-deployment/">my post on how I use Hugo</a> pointed out in the comments that it&rsquo;s now possible to write online Hugo posts from <a href="https://forestry.io">Forestry.io</a>. I&rsquo;ve been playing with it and I&rsquo;m currently using it to write this very post.</p>
<p>As far as writing online goes it&rsquo;s a big improvement over scribe.io. I&rsquo;m just not sure that&rsquo;s enough to make me switch to online writing.</p>
<p>I love the preview. Unfortunately, it&rsquo;s not good enough as it doesn&rsquo;t work with all Hugo&rsquo;s shortcodes and custom ones either. What I would suggest instead is to have a test website. Forestry.io uses the development branch - you simply hook a new website under a test domain! Just make sure it&rsquo;s not going to be indexed by search engines.</p>
<p>Forestry.io is not responsive or mobile friendly either, so keep that in mind if you wish to blog from your mobile.</p>
<p>Something I wish was also implemented is to be able to move files between folders. I organise them by year/month/day and it usually takes me more than a day to write a new blog post.</p>
<p>The lach of spel cheking when writin the post is very anoying. Not sure why but both Chrome standard spell checking and Chrome plugin Grammarly don&rsquo;t work when writing the body of the post!</p>
<p>In general, it feels like yet another application designed for Jekyll, that works for Hugo as well.</p>
<p>By the time I finished writing this post I also noticed that it came out of beta! I&rsquo;m very happy to notice that it still has a free version, with community support and for less than 10 users. I was a bit concerned I was being used as a guinea pig and wasting my time here :)</p>
]]></content:encoded>
    </item>
    <item>
      <title>Hugo: write, deploy, host</title>
      <link>https://stefano.chiodino.uk/posts/hugo-host-and-deployment/</link>
      <pubDate>Sat, 21 May 2016 00:00:00 +0000</pubDate>
      <guid>https://stefano.chiodino.uk/posts/hugo-host-and-deployment/</guid>
      <description>How to write content, deploy automatically and host your website</description>
      <content:encoded><![CDATA[<p>In this post I&rsquo;ll show you how I write my posts, deploy them to the server, process them with <a href="https://gohugo.io">Hugo</a> and host them on my <a href="https://m.do.co/c/875cd23a5c97">DigitalOcean</a> server.</p>
<p>I wanted this process to be as easy and quick as possible, with as few extra softwares and services as possible. There are a lot of solutions out there like Wercker but I didn&rsquo;t want more things in my way.</p>
<h1 id="writing">Writing</h1>
<h2 id="local">Local</h2>
<p>I write the posts from IntelliJ IDEA, which is my IDE of choice. Screw Sublime, Atom and all the rest! It&rsquo;s quite heavier but is worth it. You get spell checking, quite good live previews with the Multimarkdown plugin (shame the embedded HTML doesn&rsquo;t render), git integration, and in general a powerful IDE.</p>
<p>Just to be clear I like Sublime and Atom, but every time I use them there is something wrong. Right now the terminal in Atom doesn&rsquo;t work for me. There is an open issue for this but in the meantime you get a blinking unmovable cursor staring at you.</p>
<p>I feel that, since Hugo is quite new, the tools haven&rsquo;t caught up with its popularity yet. Intellij is flexible enough to allow you to have shortcuts <a href="https://www.jetbrains.com/help/idea/2016.1/live-templates.html">live templates</a> for your shortcodes. E.g.:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-xml" data-lang="xml"><span class="line"><span class="cl">  <span class="nt">&lt;template</span> <span class="na">name=</span><span class="s">&#34;.shortcode&#34;</span> <span class="na">value=</span><span class="s">&#34;{{&amp;lt; $SHORTCODE$ &amp;gt;}}&#34;</span> <span class="na">description=</span><span class="s">&#34;A Hugo shortcode&#34;</span> <span class="na">toReformat=</span><span class="s">&#34;false&#34;</span> <span class="na">toShortenFQNames=</span><span class="s">&#34;true&#34;</span><span class="nt">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;variable</span> <span class="na">name=</span><span class="s">&#34;SHORTCODE&#34;</span> <span class="na">expression=</span><span class="s">&#34;&#34;</span> <span class="na">defaultValue=</span><span class="s">&#34;&#34;</span> <span class="na">alwaysStopAt=</span><span class="s">&#34;true&#34;</span> <span class="nt">/&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;context&gt;</span>
</span></span><span class="line"><span class="cl">      <span class="nt">&lt;option</span> <span class="na">name=</span><span class="s">&#34;OTHER&#34;</span> <span class="na">value=</span><span class="s">&#34;true&#34;</span> <span class="nt">/&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&lt;/context&gt;</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&lt;/template&gt;</span>
</span></span></code></pre></div><p>This allows me to type <code>.s</code>, press enter (if the live template <code>.shortcode</code> is selected), type the name of the shortcode and its parameters and press enter to keep typing without having to type too many symbols or having to move your cursor.</p>
<p>I keep switching between IntelliJ and the localhost page on my browser, where my hugo server is showing how the end result will be (just launch &ldquo;hugo server&rdquo; from the root folder). If you have the page open you don&rsquo;t even need to refresh it thanks to Hugo&rsquo;s live reload feature (and don&rsquo;t even have to save the file since IntelliJ does it when it loses focus). This is very quick to do, which is particularly nice when you want to make final tweaks to make sure your post will display as you want.</p>
<h2 id="online">Online</h2>
<p>If you are using Github and want to write from your browser, or you are not at home, you can use <a href="https://prose.io">prose.io</a>. It&rsquo;s a software developed for Jekyll, but works just fine with Hugo. You get some nice shortcuts to format your text with markdown in case you are not too familiar with it. It also allows you to upload images which are committed to your repo immediately. I don&rsquo;t find it quite as powerful as IntelliJ but it&rsquo;s a nice option.</p>
<p>You can have a look at <a href="https://github.com/Draga/go-web/blob/master/_prose.yml">my prose configuration</a> to get you started. It&rsquo;s important to know that prose.io can only generate content with yaml metadata. You will have to configure Hugo to do the same by adding <code>MetaDataFormat: yaml</code>.</p>
<p>I&rsquo;ve looked at many more free online content editor:</p>
<ul>
<li><a href="http://sofish.github.io/pen/">sofish</a></li>
<li><a href="http://www.webhook.com/">webhook</a></li>
<li><a href="https://www.contentful.com">contentful</a></li>
<li><a href="https://prismic.io/">prismic</a></li>
<li><a href="https://stackedit.io">stackedit</a></li>
<li><a href="http://dillinger.io/">dillinger</a></li>
</ul>
<p>I found them actually extremely good&hellip;just not very compatible with Hugo.</p>
<p>Unfortunately I couldn&rsquo;t find any online resource to write and preview Hugo content, so editing content locally and preview it with Hugo server is still the best option for me. I reckon you could host a test environment to preview your draft, deploying with a different branch, by adding <code>-buildDrafts</code> to your <code>hugo</code> or <code>hugo server</code> commands.</p>
<p>Hopefully some tool that works perfectly with Hugo will come out soon. Spf13, the creator of Hugo, <a href="https://discuss.gohugo.io/t/web-based-editor/155/41">is thinking about creating one</a>.</p>
<h1 id="deployment">Deployment</h1>
<p>I can deploy my website in 2 ways:</p>
<ul>
<li>Push you branch to the repo on the server.</li>
<li>Push the master branch to the main repo. In my case this is on Github but can work with pretty much anything else.</li>
</ul>
<p>These both trigger a small script which I&rsquo;ve adapted from <a href="https://www.digitalocean.com/community/tutorials/how-to-deploy-a-hugo-site-to-production-with-git-hooks-on-ubuntu-14-04">this tutorial on Digitalocean</a>.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="cp">#!/bin/bash
</span></span></span><span class="line"><span class="cl"><span class="cp"></span>
</span></span><span class="line"><span class="cl"><span class="c1"># Better be specific rather than using $HOME because it wouldn&#39;t work with all users.</span>
</span></span><span class="line"><span class="cl"><span class="nv">GIT_REPO</span><span class="o">=</span>/home/draga/go-web
</span></span><span class="line"><span class="cl"><span class="nv">WORKING_DIRECTORY</span><span class="o">=</span><span class="nv">$GIT_REPO</span>/public
</span></span><span class="line"><span class="cl"><span class="nv">PUBLIC_WWW</span><span class="o">=</span>/home/draga/public_html
</span></span><span class="line"><span class="cl"><span class="nv">BACKUP_WWW</span><span class="o">=</span>/home/draga/backup_html
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">set</span> -e
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Clean working dir.</span>
</span></span><span class="line"><span class="cl">rm -rf <span class="nv">$WORKING_DIRECTORY</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Backup current website. Use -z if moving across network to save bandwidth.</span>
</span></span><span class="line"><span class="cl">rsync -aq <span class="nv">$PUBLIC_WWW</span>/ <span class="nv">$BACKUP_WWW</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Restore backup if an error occurs from now on.</span>
</span></span><span class="line"><span class="cl"><span class="nb">trap</span> <span class="s2">&#34;echo &#39;A problem occurred.  Reverting to backup.&#39;; rsync -aq --del </span><span class="nv">$BACKUP_WWW</span><span class="s2">/ </span><span class="nv">$PUBLIC_WWW</span><span class="s2">; rm -rf </span><span class="nv">$WORKING_DIRECTORY</span><span class="s2">&#34;</span> EXIT
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># fetch repo to make sure it&#39;s up to date if working with remote webhook.</span>
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> <span class="nv">$GIT_REPO</span>
</span></span><span class="line"><span class="cl">git fetch
</span></span><span class="line"><span class="cl">git checkout origin/master
</span></span><span class="line"><span class="cl"><span class="c1"># Build the website. GO HUGO!</span>
</span></span><span class="line"><span class="cl">/usr/bin/hugo -s <span class="nv">$GIT_REPO</span> -d <span class="nv">$WORKING_DIRECTORY</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Mirror the output of Hugo to the directory where the website is hosted.</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Use -c to copy only files that have changed to avoid messing with webhost caches.</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Use -z if moving across network to save bandwidth.</span>
</span></span><span class="line"><span class="cl">rsync -aqc --delete <span class="nv">$WORKING_DIRECTORY</span>/ <span class="nv">$PUBLIC_WWW</span>
</span></span><span class="line"><span class="cl"><span class="c1"># Ask Google webmaster tools to parse your sitemap.</span>
</span></span><span class="line"><span class="cl">curl https://google.com/webmasters/sitemaps/ping?sitemap<span class="o">=</span>https://stefano.chiodino.uk/sitemap.xml
</span></span><span class="line"><span class="cl">curl https://www.bing.com/ping?sitemap<span class="o">=</span>https%3A%2F%2Fstefano.chiodino.uk/sitemap.xml
</span></span><span class="line"><span class="cl"><span class="c1"># Disable trap.</span>
</span></span><span class="line"><span class="cl"><span class="nb">trap</span> - EXIT
</span></span></code></pre></div><p>I used the method described in the tutorial above for a while, but it bothered me to push twice since I had to type the password for my ssh key (I&rsquo;ve disabled the password access to the server and can now only be accessed with the key). Also what if I wasn&rsquo;t home or wanted to use prose.io?</p>
<p>Solution: git(hub) webhooks!</p>
<p>Thanks to <a href="https://github.com/adnanh/webhook" target="_blank">github.com/adnanh/webhook</a>, little software written in go, you can have you server listen on a port and execute a script when invoked.</p>
<p>I currently have it connecting in https, with a secret key, and executing the script when the master branch is pushed.</p>
<p>Now I can even use Github itself to edit my posts. Pretty neat!</p>
<h1 id="hosting">Hosting</h1>
<p>Now this was the <del>long</del> fun part. I wanted it all so it took a lot of learning, hence the fun.</p>
<p>I heard of nginx a lot and some research showed that it seems to be the go-to solution. Here are some, more performance related, details of how it performs for me: <a href="/posts/server-load-test/">server load test</a>.</p>
<p>I&rsquo;ve then enabled the pagespeed module which is very complex and heavy, but definitively worth it!
The website now scores <a href="https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fstefano.chiodino.uk%2F" target="_blank">100/100 in Google PageSpeed</a>, both in mobile and desktop!</p>
<p>I score 99/100 in <a href="https://gtmetrix.com/reports/stefano.chiodino.uk/FsGkxV4j" target="_blank">GTmetrix</a> just because there is a bug in the pagespeed module (<a href="https://github.com/pagespeed/ngx_pagespeed/issues/1064">1064</a>) and the very header is added twice, and for some reason GTmetrix seems to think that is not there&hellip;? Or maybe is because pagespeed seems to add it on subsequent reloads. Another small penalty is for the G analytics code being cached for just 2 hours, it&rsquo;s out of my control and don&rsquo;t think is worth self hosting it.</p>
<p>YSlow seems to be mostly concerned of the lack of CDN.</p>
<p>You can find all the scripts that I&rsquo;ve used to set up my server on <a href="https://github.com/Draga/serverScripts">github</a>. They are ordered in the same way they are in the filesystem, so you should get the idea. There is a script to install nginx with the brotli and pagespeed module, directives to use webhook as a service, the entire nginx configuration, etc.</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
