arcusiridis/isableFastRender/post/migrate-from-jekyll/index.html
2019-07-25 12:46:57 +05:30

505 lines
24 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Migrate to Hugo from Jekyll</title><meta name="description" itemprop="description" 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 ▾ &amp;lt;root&amp;gt;/ ▾ images/ logo.png should become ▾ &amp;lt;root&amp;gt;/ ▾ static/ ▾ images/ logo.png Additionally, you&amp;rsquo;ll want any files that should reside at the root (such as CNAME) to be moved to static." id="desc"><meta name="generator" content="Hugo 0.55.6" /><link rel="canonical" href="http://localhost:1313/post/migrate-from-jekyll/">
<link rel="dns-prefetch" href="https://use.fontawesome.com/" />
<link rel="preconnect" href="https://use.fontawesome.com/" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/foundation.min.js"></script>
<script type="text/javascript" src="/js/lunr.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/foundation.css">
<link rel="stylesheet" href="http://localhost:1313/css/dark.min.a2e0a27b84f040c06c153f1811086f6c2703f82371f3533c5ebb5617ad55f808.css" integrity="sha256-ouCie4TwQMBsFT8YEQhvbCcD+CNx81M8XrtWF61V+Ag="><link rel="stylesheet" href="/styles.css" >
<link rel="stylesheet" href="http://localhost:1313/css/reset.min.58d4832e34c59f168248179e8f6a0495f3f1ed2cb432fa09597f17f8d2916f62.css" integrity="sha256-WNSDLjTFnxaCSBeej2oElfPx7Sy0MvoJWX8X+NKRb2I="><link rel="stylesheet" href="http://localhost:1313/css/fonts.min.4ffd55649e797a49b8a6d3f70cdd1c97f25a942848a291346dd055c59bd4f010.css" integrity="sha256-T/1VZJ55ekm4ptP3DN0cl/JalChIopE0bdBVxZvU8BA="><link rel="stylesheet" href="http://localhost:1313/css/classes.min.717d03fc567fccb77be4ab35d1ac133e64e2cc160d72af4bf64a7ec26281238d.css" integrity="sha256-cX0D/FZ/zLd75Ks10awTPmTizBYNcq9L9kp+wmKBI40="><link rel="stylesheet" href="http://localhost:1313/css/pagination.min.1c019354f2098f0d34a80aa4c70a37ff5f5eb84a744f30e8af601fd877b142be.css" integrity="sha256-HAGTVPIJjw00qAqkxwo3/19euEp0TzDor2Af2HexQr4="><link rel="stylesheet" href="http://localhost:1313/css/page.min.16c3a4532fcc8cffaa9edb031826dbcfb1008775b0e8b08ada4c7d60aaaa2714.css" integrity="sha256-FsOkUy/MjP+qntsDGCbbz7EAh3Ww6LCK2kx9YKqqJxQ="><link rel="stylesheet" href="http://localhost:1313/css/widgets.min.f86a3fac609b70f8c8746e1a9bf0ee6d7030716a21281e29e0010bd19b4f22d0.css" integrity="sha256-+Go/rGCbcPjIdG4am/DubXAwcWohKB4p4AEL0ZtPItA=">
<link rel="stylesheet" href="http://localhost:1313/css/single.min.f8c42b40c9487fb9a57081e37af57fd067d349a6442c35c8b511a9d52a3bf502.css" integrity="sha256-+MQrQMlIf7mlcIHjevV/0GfTSaZELDXItRGp1So79QI=">
<link rel="preload" media="print" type="text/css" href="http://localhost:1313/css/print.min.2e0961e511885e38a09cc9a9ff3de5ce7d7d2186bb9ed98a61f176688d4ef61a.css" integrity="sha256-Lglh5RGIXjignMmp/z3lzn19IYa7ntmKYfF2aI1O9ho=" as="style"><link rel="dns-prefetch" href="https://cdnjs.cloudflare.com/" />
<link rel="preconnect" href="https://cdnjs.cloudflare.com/" />
<link rel="preload" href="http://localhost:1313/index.json" as="fetch" />
<link rel="stylesheet" href="http://localhost:1313/css/widgets/search.min.5561d0b8fcf8e2a7d3d0fcbe830ba8a5743255be7f849e564d3849a7cc1ba725.css" integrity="sha256-VWHQuPz44qfT0Py+gwuopXQyVb5/hJ5WTThJp8wbpyU=">
<link rel="stylesheet" href="http://localhost:1313/css/widgets/taglist.min.59f177c0ac5a5ae6b88ede8a87029d4012b1bdf53e37d2ccf5873832626a77f3.css" integrity="sha256-WfF3wKxaWua4jt6KhwKdQBKxvfU+N9LM9Yc4MmJqd/M=">
<meta name="theme-color" content="#2073c9">
<meta name="apple-mobile-web-app-title" content="Example Site">
<meta name="application-name" content="Example Site">
</head>
<body itemscope itemtype="http://schema.org/WebPage">
<div class="off-canvas-wrapper">
<button id="off-canvas-toggle" type="button" class="button hide-for-medium" aria-label="Open Menu" data-toggle="main-nav-off-canvas">
<span class="fas fa-bars"></span>
</button>
<div class="off-canvas position-left" id="main-nav-off-canvas" data-off-canvas>
<nav>
<ul class="vertical menu drilldown" data-drilldown><li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button" tabindex="0" href="http://localhost:1313/post/" >
POSTS
</a></li><li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button" tabindex="0" href="http://localhost:1313/about/" >
ABOUT HUGO
</a></li><li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button active" tabindex="0" href="http://localhost:1313/" >
TUTORIALS
</a><ul class="vertical menu">
<li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button" tabindex="0" href="http://localhost:1313/post/creating-a-new-theme/" >
CREATING A NEW THEME
</a></li><li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button active" tabindex="0" href="http://localhost:1313/post/migrate-from-jekyll/" >
MIGRATING FROM JEKYLL
</a></li>
</ul></li></ul>
</nav>
</div>
<div id="site-container" class="grid-container full off-canvas-content">
<div class="grid-x full grid-container data-off-canvas-content">
<div id="site-header" class="cell">
<a href="http://localhost:1313/">
<header class="small-text-center medium-text-left grid-x">
<div id="site-title-container" class="cell shrink grid-y">
<div id="site-title" class="cell shrink" itemprop="name">Example Site</div>
<div class="cell shrink" id="site-tagline">Using the Midnight theme</div>
</div>
</header>
</a>
<nav id="main-nav" class="small-hide">
<ul class="dropdown menu" data-dropdown-menu><li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button" tabindex="0" href="http://localhost:1313/post/" >
POSTS
</a></li><li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button" tabindex="0" href="http://localhost:1313/about/" >
ABOUT HUGO
</a></li><li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button active" tabindex="0" href="http://localhost:1313/" >
TUTORIALS
</a><ul class="vertical menu">
<li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button" tabindex="0" href="http://localhost:1313/post/creating-a-new-theme/" >
CREATING A NEW THEME
</a></li><li itemscope itemtype="http://schema.org/SiteNavigationElement">
<a class="main-nav button active" tabindex="0" href="http://localhost:1313/post/migrate-from-jekyll/" >
MIGRATING FROM JEKYLL
</a></li>
</ul></li></ul>
</nav>
</div>
<div id="main-container" class="cell grid-x grid-padding-x grid-container" role="main" itemprop="mainContentOfPage">
<div class="callout cell text-center">
Interested in using Midnight? Check out the <a href="https://bluestnight.com/guides/midnight/getting-started/">getting started</a>
guide and the <a href="https://bluestnight.com/docs/midnight/users/">user documentation</a> for more information.
</div>
<main class="cell medium-8" >
<article id="post-article" itemscope itemtype="http://schema.org/Article" itemref="desc">
<header id="page-header">
<h1 itemprop="headline">Migrate to Hugo from Jekyll</h1><p id="post-metadata" class="grid-x grid-padding-x"><span class="cell shrink">
<span class="far fa-clock fa-sm fa-fw" aria-hidden></span>
<strong>Published:</strong>
<time datetime="2014-03-10" content="2014-03-10" itemprop="datePublished">March 10, 2014</time>
</span><span class="cell shrink">
<span class="fas fa-book fa-sm fa-fw" aria-hidden></span>
<strong>Estimated Reading Time:</strong>
~<span itemprop="timeRequired">4 minutes</span>
</span></p>
</header>
<div id="post-content"><span itemprop="articleBody">
<h2 id="move-static-content-to-static">Move static content to <code>static</code></h2>
<p>Jekyll has a rule that any directory not starting with <code>_</code> will be copied as-is to the <code>_site</code> output. Hugo keeps all static content under <code>static</code>. You should therefore move it all there.
With Jekyll, something that looked like</p>
<pre><code>&lt;root&gt;/
▾ images/
logo.png
</code></pre>
<p>should become</p>
<pre><code>&lt;root&gt;/
▾ static/
▾ images/
logo.png
</code></pre>
<p>Additionally, you&rsquo;ll want any files that should reside at the root (such as <code>CNAME</code>) to be moved to <code>static</code>.</p>
<h2 id="create-your-hugo-configuration-file">Create your Hugo configuration file</h2>
<p>Hugo can read your configuration as JSON, YAML or TOML. Hugo supports parameters custom configuration too. Refer to the <a href="/overview/configuration/">Hugo configuration documentation</a> for details.</p>
<h2 id="set-your-configuration-publish-folder-to-site">Set your configuration publish folder to <code>_site</code></h2>
<p>The default is for Jekyll to publish to <code>_site</code> and for Hugo to publish to <code>public</code>. If, like me, you have <a href="http://blog.blindgaenger.net/generate_github_pages_in_a_submodule.html"><code>_site</code> mapped to a git submodule on the <code>gh-pages</code> branch</a>, you&rsquo;ll want to do one of two alternatives:</p>
<ol>
<li><p>Change your submodule to point to map <code>gh-pages</code> to public instead of <code>_site</code> (recommended).</p>
<pre><code>git submodule deinit _site
git rm _site
git submodule add -b gh-pages git@github.com:your-username/your-repo.git public
</code></pre></li>
<li><p>Or, change the Hugo configuration to use <code>_site</code> instead of <code>public</code>.</p>
<pre><code>{
..
&quot;publishdir&quot;: &quot;_site&quot;,
..
}
</code></pre></li>
</ol>
<h2 id="convert-jekyll-templates-to-hugo-templates">Convert Jekyll templates to Hugo templates</h2>
<p>That&rsquo;s the bulk of the work right here. The documentation is your friend. You should refer to <a href="http://jekyllrb.com/docs/templates/">Jekyll&rsquo;s template documentation</a> if you need to refresh your memory on how you built your blog and <a href="/layout/templates/">Hugo&rsquo;s template</a> to learn Hugo&rsquo;s way.</p>
<p>As a single reference data point, converting my templates for <a href="http://heyitsalex.net/">heyitsalex.net</a> took me no more than a few hours.</p>
<h2 id="convert-jekyll-plugins-to-hugo-shortcodes">Convert Jekyll plugins to Hugo shortcodes</h2>
<p>Jekyll has <a href="http://jekyllrb.com/docs/plugins/">plugins</a>; Hugo has <a href="/doc/shortcodes/">shortcodes</a>. It&rsquo;s fairly trivial to do a port.</p>
<h3 id="implementation">Implementation</h3>
<p>As an example, I was using a custom <a href="https://github.com/alexandre-normand/alexandre-normand/blob/74bb12036a71334fdb7dba84e073382fc06908ec/_plugins/image_tag.rb"><code>image_tag</code></a> 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.</p>
<p>Jekyll&rsquo;s plugin:</p>
<pre><code>module Jekyll
class ImageTag &lt; 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+)&quot;(.*?)&quot;(\s+)-&gt;((https?:\/\/|\/)(\S+))(\s*)/i
IMAGE_URL_WITH_CAPTION = /((https?:\/\/|\/)(\S+))(\s+)&quot;(.*?)&quot;/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 = &quot;&lt;figure class='#{@class}'&gt;&quot;
else
source = &quot;&lt;figure&gt;&quot;
end
if @link
source += &quot;&lt;a href=\&quot;#{@link}\&quot;&gt;&quot;
end
source += &quot;&lt;img src=\&quot;#{@url}\&quot;&gt;&quot;
if @link
source += &quot;&lt;/a&gt;&quot;
end
source += &quot;&lt;figcaption&gt;#{@caption}&lt;/figcaption&gt;&quot; if @caption
source += &quot;&lt;/figure&gt;&quot;
source
end
end
end
Liquid::Template.register_tag('image', Jekyll::ImageTag)
</code></pre>
<p>is written as this Hugo shortcode:</p>
<pre><code>&lt;!-- image --&gt;
&lt;figure {{ with .Get &quot;class&quot; }}class=&quot;{{.}}&quot;{{ end }}&gt;
{{ with .Get &quot;link&quot;}}&lt;a href=&quot;{{.}}&quot;&gt;{{ end }}
&lt;img src=&quot;{{ .Get &quot;src&quot; }}&quot; {{ if or (.Get &quot;alt&quot;) (.Get &quot;caption&quot;) }}alt=&quot;{{ with .Get &quot;alt&quot;}}{{.}}{{else}}{{ .Get &quot;caption&quot; }}{{ end }}&quot;{{ end }} /&gt;
{{ if .Get &quot;link&quot;}}&lt;/a&gt;{{ end }}
{{ if or (or (.Get &quot;title&quot;) (.Get &quot;caption&quot;)) (.Get &quot;attr&quot;)}}
&lt;figcaption&gt;{{ if isset .Params &quot;title&quot; }}
{{ .Get &quot;title&quot; }}{{ end }}
{{ if or (.Get &quot;caption&quot;) (.Get &quot;attr&quot;)}}&lt;p&gt;
{{ .Get &quot;caption&quot; }}
{{ with .Get &quot;attrlink&quot;}}&lt;a href=&quot;{{.}}&quot;&gt; {{ end }}
{{ .Get &quot;attr&quot; }}
{{ if .Get &quot;attrlink&quot;}}&lt;/a&gt; {{ end }}
&lt;/p&gt; {{ end }}
&lt;/figcaption&gt;
{{ end }}
&lt;/figure&gt;
&lt;!-- image --&gt;
</code></pre>
<h3 id="usage">Usage</h3>
<p>I simply changed:</p>
<pre><code>{% image full http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg &quot;One of my favorite touristy-type photos. I secretly waited for the good light while we were &quot;having fun&quot; 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.&quot; -&gt;http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/ %}
</code></pre>
<p>to this (this example uses a slightly extended version named <code>fig</code>, different than the built-in <code>figure</code>):</p>
<pre><code>{{% fig class=&quot;full&quot; src=&quot;http://farm5.staticflickr.com/4136/4829260124_57712e570a_o_d.jpg&quot; title=&quot;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.&quot; link=&quot;http://www.flickr.com/photos/alexnormand/4829260124/in/set-72157624547713078/&quot; %}}
</code></pre>
<p>As a bonus, the shortcode named parameters are, arguably, more readable.</p>
<h2 id="finishing-touches">Finishing touches</h2>
<h3 id="fix-content">Fix content</h3>
<p>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 <code>hugo server --watch</code> is your friend. Test your changes and fix errors as needed.</p>
<h3 id="clean-up">Clean up</h3>
<p>You&rsquo;ll want to remove the Jekyll configuration at this point. If you have anything else that isn&rsquo;t used, delete it.</p>
<h2 id="a-practical-example-in-a-diff">A practical example in a diff</h2>
<p><a href="http://heyitsalex.net/">Hey, it&rsquo;s Alex</a> was migrated in less than a <em>father-with-kids day</em> from Jekyll to Hugo. You can see all the changes (and screw-ups) by looking at this <a href="https://github.com/alexandre-normand/alexandre-normand/compare/869d69435bd2665c3fbf5b5c78d4c22759d7613a...b7f6605b1265e83b4b81495423294208cc74d610">diff</a>.</p>
</span>
</div></article>
<nav id="post-nav" aria-label="Pagination">
<ul class="pagination grid-x grid-x-padding full">
<li class="pagination-previous cell small-order-2 medium-5 medium-order-1">
<a class="button" href="http://localhost:1313/post/goisforlovers/" rel="prev">
<span class="sr-text">Previous:</span>
(Hu)go Template Primer</a>
</li>
<li class="pagination-next cell small-order-1 medium-5 medium-order-2 medium-offset-2">
<a class="button" href="http://localhost:1313/post/creating-a-new-theme/" rel="next">
<span class="sr-text">Next:</span>Creating a New Theme
</a>
</li>
</ul>
</nav>
</main>
<aside class="cell small-12 small-order-2 medium-4" itemscope itemtype="http://schema.org/WPSideBar"><div class="widget" id="search-container">
<header>
<span class="widget-header"><span class="fas fa-search fa-xs" aria-hidden></span> Search</span>
</header>
<input type="search" name="search" id="searchbox" placeholder="Search..." autocomplete="off"/>
<div id="search-results" class="grid-y hide"></div>
</div>
<div class="widget">
<header>
<span class="widget-header"><span class="fas fa-pencil-alt fa-xs" aria-hidden></span> <a href="http://localhost:1313/post/">Recent Posts</a></span>
</header>
<a class="widget-header-small button" href="http://localhost:1313/index.xml"><span class="fas fa-rss fa-xs" aria-hidden></span> Subscribe to the Site</a>
<a class="widget-header-small button" href="http://localhost:1313/post/index.xml"><span class="fas fa-rss fa-xs" aria-hidden></span> Subscribe to Posts</a><ul><li><a href="http://localhost:1313/post/creating-a-new-theme/">Creating a New Theme</a></li><li><a href="http://localhost:1313/post/migrate-from-jekyll/">Migrate to Hugo from Jekyll</a></li><li><a href="http://localhost:1313/post/goisforlovers/">(Hu)go Template Primer</a></li><li><a href="http://localhost:1313/post/hugoisforlovers/">Getting Started with Hugo</a></li></ul>
</div>
<div class="widget">
<header>
<span class="widget-header">
<span class="fas fa-folder fa-xs" aria-hidden></span>
<a href="http://localhost:1313/categories/">Categories</a>
</span>
</header>
<ul><li>
<a href="http://localhost:1313/categories/development/">
Development
</a>
</li>
<li>
<a href="http://localhost:1313/categories/golang/">
Golang
</a>
</li>
</ul>
</div>
<div class="widget">
<header>
<span class="widget-header"><span class="fas fa-tags fa-xs" aria-hidden></span> <a href="http://localhost:1313/tags/">Tags</a></span>
</header>
<div class="grid-x grid-padding-x" id="sidebar-tags"><a class="cell shrink" href="http://localhost:1313/tags/development/" title="development">
development
</a><a class="cell shrink" href="http://localhost:1313/tags/go/" title="go">
go
</a><a class="cell shrink" href="http://localhost:1313/tags/golang/" title="golang">
golang
</a><a class="cell shrink" href="http://localhost:1313/tags/hugo/" title="hugo">
hugo
</a><a class="cell shrink" href="http://localhost:1313/tags/templates/" title="templates">
templates
</a><a class="cell shrink" href="http://localhost:1313/tags/themes/" title="themes">
themes
</a></div>
</div>
</aside>
</div>
<footer class="cell grid-x full align-middle">
<div class="cell medium-4 small-text-center medium-text-left medium-left small-order-1 grid-x">
<div class="cell">
<small>
&copy; 2019
<span itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<span itemprop="name">
Example Site.
</span>
</span>
</small>
</div>
<div class="cell">
<small>
Built with <a href="https://gohugo.io">Hugo</a> and <a href="https://bluestnight.com/products/midnight/">Midnight</a>.
</small>
</div>
</div>
<div class="cell medium-4 small-text-center medium-text-center small-order-2 grid-x">
<div class="cell small-full small-text-center grid-x">
</div>
</div>
<div id="social-icons" class="grid-x cell medium-4 small-text-center small-order-3 medium-text-right">
<a href="https://gitlab.com/BluestNight/Midnight" class="cell shrink" rel="me nofollow" title="GitLab" aria-title="Fork me on GitLab!">
<span class="fa-stack fa-xs">
<span class="fas fa-square fa-stack-2x"></span>
<span class="fab fa-gitlab fa-stack-1x fa-inverse"></span>
</span>
</a>
</div>
</footer>
</div>
</div>
<script type="text/javascript" src="http://localhost:1313/js/iubenda.min.e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.js" integrity="sha256-47DEQpj8HBSa&#43;/TImW&#43;5JCeuQeRkm5NMpJWZG3hSuFU="></script>
<script type="text/javascript" src="http://localhost:1313/js/widgets/search.min.572f332ce215f4f16d9adc8643ebc2c193fcb351d506d92d1769efaf95230773.js" integrity="sha256-Vy8zLOIV9PFtmtyGQ&#43;vCwZP8s1HVBtktF2nvr5UjB3M=" defer></script><script type="text/javascript" src="http://localhost:1313/js/index.min.e22883a04526785bb35feb658da4974c160999432286921d7df30235cc21e4f3.js" integrity="sha256-4iiDoEUmeFuzX&#43;tljaSXTBYJmUMihpIdffMCNcwh5PM=" defer></script>
</div>
<script>
$(document).foundation();
</script>
<script data-no-instant>document.write('<script src="/livereload.js?port=1313&mindelay=10"></' + 'script>')</script></body>
</html>