.Kind (page): .Type (post) / .Layout ()
Bundle: n/a (regular page)
[ categories | tags | search ]
Hugo Bare Min Theme

This is an Example Site for the hugo-bare-min-theme.

It is updated automatically after each commit to the hugo-bare-min-theme repo. It was last updated on Feb 10, 2020 17:48 UTC.


This page was created/modified in commit 162544b "Use .RegularPages instead of .Pages where appropriate" on 2019-09-11.
Markdown source of this page

Migrating to Hugo from Jekyll


Description/Summary

Move static content to static Jekyll has a rule that any directory not starting with _ will be copied as-is to the _site output. Hugo keeps all static content under static. You should therefore move it all there. With Jekyll, something that looked like ▾ <root>/ ▾ images/ logo.png should become ▾ <root>/ ▾ static/ ▾ images/ logo.png Additionally, you’ll want any files that should reside at the root (such as CNAME) to be moved to static.


Content

Move static content to static

Jekyll has a rule that any directory not starting with _ will be copied as-is to the _site output. Hugo keeps all static content under static. You should therefore move it all there. With Jekyll, something that looked like

▾ <root>/
    ▾ images/
        logo.png

should become

▾ <root>/
    ▾ static/
        ▾ images/
            logo.png

Additionally, you’ll want any files that should reside at the root (such as CNAME) to be moved to static.

Create your Hugo configuration file

Hugo can read your configuration as JSON, YAML or TOML. Hugo supports parameters custom configuration too. Refer to the Hugo configuration documentation for details.

Set your configuration publish folder to _site

The default is for Jekyll to publish to _site and for Hugo to publish to public. If, like me, you have _site mapped to a git submodule on the gh-pages branch, you’ll want to do one of two alternatives:

  1. Change your submodule to point to map gh-pages to public instead of _site (recommended).

    git submodule deinit _site
    git rm _site
    git submodule add -b gh-pages git@github.com:your-username/your-repo.git public
  2. Or, change the Hugo configuration to use _site instead of public.

    {
        ..
        "publishdir": "_site",
        ..
    }

Convert Jekyll templates to Hugo templates

That’s the bulk of the work right here. The documentation is your friend. You should refer to Jekyll’s template documentation if you need to refresh your memory on how you built your blog and Hugo’s template to learn Hugo’s way.

As a single reference data point, converting my templates for heyitsalex.net took me no more than a few hours.

Convert Jekyll plugins to Hugo shortcodes

Jekyll has plugins; Hugo has shortcodes. It’s fairly trivial to do a port.

Implementation

As an example, I was using a custom image_tag plugin to generate figures with caption when running Jekyll. As I read about shortcodes, I found Hugo had a nice built-in shortcode that does exactly the same thing.

Jekyll’s plugin:

module Jekyll
  class ImageTag < Liquid::Tag
    @url = nil
    @caption = nil
    @class = nil
    @link = nil
    // Patterns
    IMAGE_URL_WITH_CLASS_AND_CAPTION =
    IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK = /(\w+)(\s+)((https?:\/\/|\/)(\S+))(\s+)"(.*?)"(\s+)->((https?:\/\/|\/)(\S+))(\s*)/i
    IMAGE_URL_WITH_CAPTION = /((https?:\/\/|\/)(\S+))(\s+)"(.*?)"/i
    IMAGE_URL_WITH_CLASS = /(\w+)(\s+)((https?:\/\/|\/)(\S+))/i
    IMAGE_URL = /((https?:\/\/|\/)(\S+))/i
    def initialize(tag_name, markup, tokens)
      super
      if markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION_AND_LINK
        @class   = $1
        @url     = $3
        @caption = $7
        @link = $9
      elsif markup =~ IMAGE_URL_WITH_CLASS_AND_CAPTION
        @class   = $1
        @url     = $3
        @caption = $7
      elsif markup =~ IMAGE_URL_WITH_CAPTION
        @url     = $1
        @caption = $5
      elsif markup =~ IMAGE_URL_WITH_CLASS
        @class = $1
        @url   = $3
      elsif markup =~ IMAGE_URL
        @url = $1
      end
    end
    def render(context)
      if @class
        source = "<figure class='#{@class}'>"
      else
        source = "<figure>"
      end
      if @link
        source += "<a href=\"#{@link}\">"
      end
      source += "<img src=\"#{@url}\">"
      if @link
        source += "</a>"
      end
      source += "<figcaption>#{@caption}</figcaption>" if @caption
      source += "</figure>"
      source
    end
  end
end
Liquid::Template.register_tag('image', Jekyll::ImageTag)

is written as this Hugo shortcode:

<!-- image -->
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
    {{ with .Get "link"}}<a href="{{.}}">{{ end }}
        <img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}"{{ end }} />
    {{ if .Get "link"}}</a>{{ end }}
    {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
    <figcaption>{{ if isset .Params "title" }}
        {{ .Get "title" }}{{ end }}
        {{ if or (.Get "caption") (.Get "attr")}}<p>
        {{ .Get "caption" }}
        {{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
            {{ .Get "attr" }}
        {{ if .Get "attrlink"}}</a> {{ end }}
        </p> {{ end }}
    </figcaption>
    {{ end }}
</figure>
<!-- image -->

Usage

I simply changed:

{% image full http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg "One of my favorite touristy-type photos. I secretly waited for the good light while we were "having fun" and took this. Only regret: a stupid pole in the top-left corner of the frame I had to clumsily get rid of at post-processing." ->http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/ %}

to this (this example uses a slightly extended version named fig, different than the built-in figure):

{{% fig class="full" src="http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg" title="One of my favorite touristy-type photos. I secretly waited for the good light while we were having fun and took this. Only regret: a stupid pole in the top-left corner of the frame I had to clumsily get rid of at post-processing." link="http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/" %}}

As a bonus, the shortcode named parameters are, arguably, more readable.

Finishing touches

Fix content

Depending on the amount of customization that was done with each post with Jekyll, this step will require more or less effort. There are no hard and fast rules here except that hugo server --watch is your friend. Test your changes and fix errors as needed.

Clean up

You’ll want to remove the Jekyll configuration at this point. If you have anything else that isn’t used, delete it.

A practical example in a diff

Hey, it’s Alex was migrated in less than a father-with-kids day from Jekyll to Hugo. You can see all the changes (and screw-ups) by looking at this diff.


Page (Debug)

Page VariableValue
Name "Migrating to Hugo from Jekyll"
Title "Migrating to Hugo from Jekyll"
ResourceType "page"
Kind "page"
Section "post"
Draft false
Type "post"
Layout ""
Permalink "https://hugo-bare-min.netlify.com/post/migrate-from-jekyll/"
RelPermalink "/post/migrate-from-jekyll/"
Data
page.Data{} (type:page.Data)
NextPageGetting Started with Hugo
PrevPageSearch
NextInSectionGetting Started with Hugo
PrevInSectionNone

Page Params (Debug)

KeyTypeValue
datetime.Time 2014-03-10 00:00:00 +0000 UTC
draftbool false
iscjklanguagebool false
lastmodtime.Time 2019-09-11 08:39:43 -0400 -0400
linktitlestring "Migrating from Jekyll"
menumap[string]interface {}
KeyTypeValue
mainmap[string]interface {}
KeyTypeValue
identifierstring "migrating-to-hugo-from-jekyll"
weightint64 2004
publishdatetime.Time 2014-03-10 00:00:00 +0000 UTC
titlestring "Migrating to Hugo from Jekyll"

File Object (Debug)

FileInfo VariableValue
UniqueID "7267aa86d808e09dc6676112f87f5e53"
BaseFileName "migrate-from-jekyll"
TranslationBaseName "migrate-from-jekyll"
Lang "en"
Section "post"
LogicalName "migrate-from-jekyll.md"
Dir "post/"
Ext "md"
Path "post/migrate-from-jekyll.md"

This site is generated using the hugo-bare-min-theme + Hugo 0.59.0 (commit 1dd0c69c) . [Test Site home]