6.8 KiB
title | date | groups | groups_weight | |
---|---|---|---|---|
Migrate to Hugo from Jekyll | 2014-03-10 |
|
10 |
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:
-
Change your submodule to point to map
gh-pages
to public instead of_site
(recommended). {{% highlight sh %}} git submodule deinit _site git rm _site git submodule add -b gh-pages git@github.com:your-username/your-repo.git public {{% /highlight %}} -
Or, change the Hugo configuration to use
_site
instead ofpublic
. {{% highlight json %}} { .. "publishdir": "_site", .. } {{% /highlight %}}
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:
{{% highlight ruby %}}
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 = "