<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>hugo on Arunrocks</title>
    <link>https://arunrocks.com/tags/hugo/</link>
    <description>Recent articles in hugo on Arunrocks</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 10 Jul 2017 10:51:31 +0530</lastBuildDate><atom:link href="https://arunrocks.com/tags/hugo/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>A Gentle Introduction to Creating a Minimal Hugo Site</title>
      <link>https://arunrocks.com/minimal-hugo-site-tutorial/</link>
      <pubDate>Mon, 10 Jul 2017 10:51:31 +0530</pubDate>
      
      <guid>https://arunrocks.com/minimal-hugo-site-tutorial/</guid>
      <description>&lt;p&gt;When I started using Hugo, I was very impressed by its speed. But I was daunted by the directory structure it creates for a new project. With directory names like &lt;code&gt;archetypes&lt;/code&gt; and &lt;code&gt;static&lt;/code&gt;, a Hugo site felt unfamiliar and confusing. Fortunately, not every site needs them.&lt;/p&gt;
&lt;p&gt;This post tells you how to start small with just the bare minimum files and directories to build a Hugo site without errors. Being minimal, this site will have only one page (essentially, the home page).&lt;/p&gt;
&lt;p&gt;You can see the finished project on &lt;a href=&#34;https://github.com/arocks/minimal-hugo&#34;&gt;Github&lt;/a&gt;. Let&amp;rsquo;s start looking at only the top-level files of the project:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;.
├── config.toml
├── content/
├── .git/
├── .gitignore
└── themes/
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There are only two directories: &lt;code&gt;content&lt;/code&gt; which contains your site&amp;rsquo;s content like posts or articles and &lt;code&gt;themes&lt;/code&gt; which are contain various themes - the non-content part of your site like its design and page layouts.&lt;/p&gt;
&lt;p&gt;For Hugo, &lt;code&gt;config.toml&lt;/code&gt; contains all the configuration settings of your site like the name of the site, author name, theme etc. For this minimal site, we will only mention two lines:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;baseURL = &amp;quot;http://example.org/&amp;quot;
theme = &amp;quot;bare&amp;quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is a &lt;a href=&#34;https://en.wikipedia.org/wiki/TOML&#34;&gt;TOML file&lt;/a&gt;. It has a very simple syntax. Each line is written like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;key = &amp;quot;value&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;baseURL&lt;/code&gt; value mentions the URL where the site will be published. Strictly speaking, we don&amp;rsquo;t need it for a minimal site. But Hugo throws an error if &lt;code&gt;baseURL&lt;/code&gt; is not specified.&lt;/p&gt;
&lt;p&gt;Next, we mention that we are using the &amp;ldquo;bare&amp;rdquo; theme. Essentially, &amp;ldquo;bare&amp;rdquo; is a directory inside &amp;ldquo;themes&amp;rdquo; directory. We will look at it closely soon.&lt;/p&gt;
&lt;p&gt;The Git files are worth mentioning. I prefer to exclude the generated site (having rendered HTML pages) from Git. Assuming that the generated files will go into a directory named &amp;ldquo;public&amp;rdquo;, my &lt;code&gt;.gitignore&lt;/code&gt; file is simply this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;content-files&#34;&gt;Content files&lt;/h2&gt;
&lt;p&gt;A content file is usually a text file containing your blog post or article. Typically content files are written in Markdown syntax. But Hugo supports other text formats like Asciidoc, reStructuredText or Org-Mode, which gets converted to HTML. This is easier than directly editing HTML files.&lt;/p&gt;
&lt;p&gt;The only content file in this minimal site is &lt;code&gt;_index.md&lt;/code&gt;. This filename is special to Hugo and used to specify a page leading to a list of pages. Typically, an index file is used for a home page, a section, a taxonomy or a taxonomy terms listing.&lt;/p&gt;
&lt;p&gt;Our &lt;code&gt;_index.md&lt;/code&gt; looks like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-markdown&#34; data-lang=&#34;markdown&#34;&gt;+++
title = &amp;#34;Home sweet home&amp;#34;
+++

This page has &lt;span class=&#34;gs&#34;&gt;**bold**&lt;/span&gt; and &lt;span class=&#34;ge&#34;&gt;*italics*&lt;/span&gt; formatting.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The two &lt;code&gt;+++&lt;/code&gt; separators divides the document into two parts - the &lt;em&gt;front matter&lt;/em&gt; (first three lines) in TOML format and the rest of the document in Markdown format. Front matter specifies the metadata of the file like its title, date or category. Most text editors will treat this file as a Markdown file (due to the .md extension) and ignore the front matter.&lt;/p&gt;
&lt;p&gt;Since the &lt;code&gt;_index.md&lt;/code&gt; is located inside &lt;code&gt;content&lt;/code&gt; directory at the top-level, it will be the first page seen when the user opens the baseURL location i.e. the home page. However, for this page to be rendered, there must be a corresponding template within the theme.&lt;/p&gt;
&lt;h2 id=&#34;theme-files&#34;&gt;Theme files&lt;/h2&gt;
&lt;p&gt;So far, we have not specified the look and feel of the site. This is typically mentioned in a separate theme directory (it can also be mentioned inside a &lt;code&gt;layouts&lt;/code&gt; directory within the site but its more cleaner this way).&lt;/p&gt;
&lt;p&gt;Unlike say Wordpress themes, you might not be able to download an arbitrary Hugo theme and apply it to your site. This is because a theme makes certain assumptions like that your site is a blog and the posts are one-level deep etc, which might not be true in your case. So, I prefer making my own theme while creating new kind of sites. Besides you would eventually want to customize your theme anyway.&lt;/p&gt;
&lt;p&gt;The bare theme is located inside the themes directory. Here is directory structure of that theme:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;themes/
└── bare/
    ├── layouts/
    │   └── index.html
    └── theme.toml
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note that this is literally a &amp;ldquo;bare&amp;rdquo; theme in that it has no stylesheets or images. It can just render a single home page in plain HTML.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;theme.toml&lt;/code&gt; like &lt;code&gt;config.toml&lt;/code&gt; contains some metadata about this theme. As seen below, it is fairly self-explanatory:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;name = &amp;quot;Bare&amp;quot;
license = &amp;quot;MIT&amp;quot;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The layouts directory contains templates which specify how your content files should be rendered into HTML. As you might have guessed, &lt;code&gt;index.html&lt;/code&gt; at the top-level is used for rendering a top-level &lt;code&gt;_index.md&lt;/code&gt;. This file contains:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;html&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Welcome!&amp;lt;/h1&amp;gt;

    &amp;lt;h2&amp;gt;{{ .Title }}&amp;lt;/h2&amp;gt;
    {{ .Content }}

  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This looks like an HTML page except for parts enclosed in double curly braces ( &lt;code&gt;{{ something }}&lt;/code&gt; ). These parts are in &lt;a href=&#34;https://gohugo.io/templates/go-templates/&#34;&gt;Go Template language&lt;/a&gt; and will be replaced by their values.&lt;/p&gt;
&lt;p&gt;To understand what &lt;code&gt;.Title&lt;/code&gt; means you have to understand that the dot in the beginning refers to the current context, which is the current page. In other programming languages this might be written as &lt;code&gt;ThisPage.Title&lt;/code&gt;, but here &lt;code&gt;ThisPage&lt;/code&gt; is implied and hence omitted.&lt;/p&gt;
&lt;p&gt;The value for &lt;code&gt;.Title&lt;/code&gt; comes from the front matter. While rendering &amp;ldquo;_index.md&amp;rdquo;, it will be replaced by &amp;ldquo;Home sweet home&amp;rdquo; (refer &lt;code&gt;_index.md&lt;/code&gt; mentioned earlier). The value for &lt;code&gt;.Content&lt;/code&gt; will be the rendered HTML from the Markdown file.&lt;/p&gt;
&lt;p&gt;Most themes will have certain common elements across a site like a header and footer. Just because we only need a template for one page, the &amp;ldquo;bare&amp;rdquo; theme omits all those flourishes.&lt;/p&gt;
&lt;p&gt;You can checkout the finished project at &lt;a href=&#34;https://github.com/arocks/minimal-hugo&#34;&gt;Github&lt;/a&gt;. You can use this as a landing page or could be a starting point to a larger Hugo project.&lt;/p&gt;
&lt;h2 id=&#34;rendering-and-publishing&#34;&gt;Rendering and Publishing&lt;/h2&gt;
&lt;p&gt;While developing a Hugo site or previewing a post that is being composed, you might want to use the built-in test server. The files are not generated (in the project folder) but you can browse your site locally in your browser&lt;/p&gt;
&lt;p&gt;For local development, execute the following command (in the project directory):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ hugo server -w
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is what you should see in your browser:&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/minimal-site.png&#34; alt=&#34;Minimal site in hugo&#34;   width=475 height=&#34;370&#34;  /&gt;
    
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Once you are ready to publish the site, you&amp;rsquo;ll need the generate the files into an output directory. The following command will create generate your site into the &amp;ldquo;public&amp;rdquo; directory:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ hugo --destination public
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now you can copy the files from public directory into the web root of &amp;ldquo;example.com&amp;rdquo; or whichever domain that you mentioned as your baseURL. You can use GitHub Pages to host this site for free. I would recommend reading up instructions in their &lt;a href=&#34;https://pages.github.com/&#34;&gt;GitHub Pages documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Next, I would recommend looking at other Hugo sites to understand how various features of Hugo have been used. Personally, I wrote this post so that I have a minimal starting point when I start a new project. Enjoy exploring Hugo!&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Migrating Blogs (Again) from Pelican to Hugo</title>
      <link>https://arunrocks.com/moving-blogs-pelican-to-hugo/</link>
      <pubDate>Tue, 02 May 2017 10:51:31 +0530</pubDate>
      
      <guid>https://arunrocks.com/moving-blogs-pelican-to-hugo/</guid>
      <description>&lt;p&gt;Our universe is in a continuous cycle of creation and destruction. How can this humble site escape that cosmic dance? It is time to change the blogging platform of arunrocks.com again.&lt;/p&gt;
&lt;p&gt;You might remember my &lt;a href=&#34;https://arunrocks.com/moving-blogs-to-pelican/&#34;&gt;earlier lengthy justification of using Pelican&lt;/a&gt;. I have done numerous hacks and plugins to twist and bend it to my liking. While it has served me well for the past four years, it is time to move on.&lt;/p&gt;
&lt;p&gt;The reason, of course, is a much better static site generator - &lt;a href=&#34;http://gohugo.io/&#34;&gt;Hugo&lt;/a&gt;. A fairly young but very actively developed project, Hugo has some extremely compelling set of qualities, which made the choice to migrate my site fairly obvious. Some of them are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Content Organization&lt;/strong&gt;: Hugo believes in the philosophy that your content should be arranged in the same way they are intended for the rendered website. This brings tremendous clarity in identifying file locations and reduces the need for hacks.&lt;/p&gt;
&lt;p&gt;By default, some blogging engines (including Pelican) assume that all your &amp;ldquo;pages&amp;rdquo; will be finally rendered into the &lt;code&gt;pages&lt;/code&gt; folder. A configuration setting can change it to use any URL scheme. But why doesn&amp;rsquo;t it leave it where it was? The source structure is nested and organized. Why flatten it and lose that information?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Extremely Fast&lt;/strong&gt;: Even if your site contains hundreds of files, the build time is usually under a second, without cached compilation,&amp;hellip; inside a virtual machine, &amp;hellip; without an SSD. Yes, it is unbelievable.&lt;/p&gt;
&lt;p&gt;This makes the edit-preview development cycle a pleasure to use. Tweak an SCSS variable and the browser will live reload almost instantaneously. I make a hundred tweaks after a page gets rendered, so a short feedback loop is ideal for my workflow.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;No Stack&lt;/strong&gt;: This is usually marketed as the &amp;ldquo;single executable&amp;rdquo; advantage of Go applications. But it matters much more profoundly in the case of Hugo.&lt;/p&gt;
&lt;p&gt;Many new languages like Javascript and Python need a pile of third party libraries to make their tools run (even if they are &amp;ldquo;batteries included&amp;rdquo;). While it might be easy to setup initially with a single command like &lt;code&gt;pip install Foo&lt;/code&gt;, future invocations might need you to update everything to their latest versions first and then fixing whatever breaks.&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/slacking-off-t-shirt-min.png&#34; alt=&#34;Slacking Off T shirt&#34;   width=618 height=&#34;505&#34;  /&gt;
    
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Even though dynamic languages do not require a lengthy compilation step, a constant stream of updates can get tiring. &amp;ldquo;Updating my packages&amp;rdquo;&amp;quot; has become the new &amp;ldquo;I am compiling&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Ok, end of my rant. Hugo is a single self contained executable (in all platforms). This not only reduces the number of moving pieces that you need to keep track of (my &lt;code&gt;requirements.txt&lt;/code&gt; for the site listed 20 packages), it simplifies the ongoing maintenance of your site.&lt;/p&gt;
&lt;p&gt;I would rather not have the headache of managing code environments just for writing a blog. In Arch Linux, where I develop my site, it is even easier considering it is a rolling distribution. Hugo automatically updates along with the rest of the system. The updates are usually backward compatible and nothing breaks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Actively Developed&lt;/strong&gt;: Many static blog generator projects have this problem. The early days would have the community engaged and actively involved. Then the interest dwindles, code gets stale and the backlog of issues grows. Hugo is still in its early days and has a energetic community. Hopefully the interest will continue to grow.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Not too Blog-oriented&lt;/strong&gt;: My site, like most personal sites, is predominantly a blog. But it is not just a blog, it is a full-fledged site. Hugo has very minimal assumptions about what kind of site you have. For instance, I can convert a JSON file with all my talks into a Talks page. I just need to define a template for a new type of page in my layouts.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;it-is-not-all-peaches-and-cream&#34;&gt;It is not all Peaches and Cream&lt;/h3&gt;
&lt;p&gt;Hugo does have some rough edges. But considering the rate of its development, you might find that all these problems have been solved by the time you read it. But, for the record, I did come across these issues:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Lack of Static Assets Pipeline&lt;/strong&gt;: I use SCSS to create my CSS files. In general, Hugo is unaware of any static assets pipeline which may involve compiling SCSS, minification or compression. I use a Makefile which invokes the compiler as a dependency for build. Sometimes I need to stop live reloading and explicitly call &lt;code&gt;Make&lt;/code&gt;. Since everything is fast, it doesn&amp;rsquo;t matter much.&lt;/p&gt;
&lt;p&gt;&lt;figure&gt;
    &lt;img loading=&#34;lazy&#34; src=&#34;https://arunrocks.com/static/images/blog/wasabi-conveyor-belt.jpg&#34; alt=&#34;Wasabi restaurant at Tysons Corner Center in McLean, Virginia taken by Ben Schumin&#34;   width=700 height=&#34;525&#34;  /&gt;
    
  &lt;/figure&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Menu Generation Flaky&lt;/strong&gt;: I found the &lt;a href=&#34;https://webdesignerhut.com/active-class-navigation-menu/&#34;&gt;&amp;ldquo;active section in menu&amp;rdquo; pattern&lt;/a&gt; used in most website menus a bit hard to implement. There are &lt;a href=&#34;https://discuss.gohugo.io/t/is-hasmenucurrent-for-list-of-content-templates/2609/6&#34;&gt;others&lt;/a&gt; &lt;a href=&#34;https://discuss.gohugo.io/t/questions-about-ismenucurrent-function-tag-names-keys-and-theme-contribution/945/8&#34;&gt;who&lt;/a&gt; &lt;a href=&#34;https://discuss.gohugo.io/t/normal-page-not-selectable-in-menu/5431&#34;&gt;have&lt;/a&gt; faced similar issues. I resorted to not using this pattern for now.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Outdated Blog posts&lt;/strong&gt; Hugo documentation is extensive and covers a lot of material. But good documentation is very hard to get right. Some sections are confusing and I often look for better explanations say from blogs.&lt;/p&gt;
&lt;p&gt;But one needs to watch out for outdated content. For instance, I needed to change my RSS feed location and one blog recommended changing &lt;code&gt;RSSUri&lt;/code&gt; in the config file. This is deprecated. Now, you need to use output formats say like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;outputFormats.RSS:
  BaseName: &amp;quot;index&amp;quot;
  Path: &amp;quot;feed/index.xml&amp;quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Python Tooling&lt;/strong&gt;: While using Pelican, I was happy that if I needed any additional functionality, I could always write a plugin in Python. This doesn&amp;rsquo;t worry me for two reasons. First, Hugo&amp;rsquo;s template system is very expressive and handles many of such needs. Second, &lt;a href=&#34;https://gohugo.io/extras/shortcodes/&#34;&gt;ShortCodes&lt;/a&gt; offer a much cleaner alternative to plugins.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Inconsistent Casing&lt;/strong&gt; Sometimes a variable is mentioned in title case in one place and lower case in another. I would end up wondering whether it is copyright or Copyright or CopyRight. Probably, there is a naming convention. But I haven&amp;rsquo;t found it yet.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;As you can see, most of these issues are solvable. Hugo is a long way from version 1.0 (currently we have v20.7). So this might all be fixed by then.&lt;/p&gt;
&lt;h3 id=&#34;changing-a-jet-engine-mid-flight&#34;&gt;Changing a Jet Engine Mid-flight&lt;/h3&gt;
&lt;p&gt;Once your site achieves a certain amount of traffic, then making any change is fraught with risk. Every time I change this site&amp;rsquo;s underlying platform I make a short TODO list. It looks something like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Setup Redirects&lt;/strong&gt;: Map the old link structure to the new ones&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fix Renders&lt;/strong&gt;: Markdown is not quite a standard. Each Markdown engine has its own quirk. I manually check the rendered HTML is some cases.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check Missing Images&lt;/strong&gt;: Things have to move around to adjust for various source layouts. So images, scripts or download links can return 404s.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even after all these checks, I still need to watch the error log for omissions. As this happens in my spare time, the whole migration &amp;ldquo;project&amp;rdquo; takes months. It is pretty much like changing a jet&amp;rsquo;s engine mid-flight.&lt;/p&gt;
&lt;h3 id=&#34;some-takeaways&#34;&gt;Some Takeaways&lt;/h3&gt;
&lt;p&gt;In short, I would say you can never underestimate the sheer amount of work involved in migrating a site. There is a very &lt;a href=&#34;https://moz.com/blog/web-site-migration-guide-tips-for-seos&#34;&gt;good post on site migration&lt;/a&gt; by folks at Mozilla that covers many aspects that people tend to miss. Unless you have very good reasons to move, I would suggest that you stick with your blogging platform of choice.&lt;/p&gt;
&lt;p&gt;As for me, time to start thinking about migration to HTTPS 😉&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
