Files
ivi/public/posts/migrate-from-jekyll/index.html
T
2026-10-17 08:45:08 +02:00

310 lines
18 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head><script src="/livereload.js?mindelay=10&amp;v=2&amp;port=1313&amp;path=livereload" data-no-instant defer></script>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Migrate to Hugo from Jekyll &middot; Hugo Themes - noesis</title>
<meta name="description" content="noesis Hugo theme for blogs" />
<meta name="author" content="Joe Hutchinson" />
<link rel="canonical" href="http://localhost:1313/posts/migrate-from-jekyll/">
<meta property="og:url" content="http://localhost:1313/posts/migrate-from-jekyll/">
<meta property="og:site_name" content="Hugo Themes - noesis">
<meta property="og:title" content="Migrate to Hugo from Jekyll">
<meta property="og: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
▾ &lt;root&gt;/ ▾ images/ logo.png should become
▾ &lt;root&gt;/ ▾ static/ ▾ images/ logo.png Additionally, you’ll want any files that should reside at the root (such as CNAME) to be moved to static.">
<meta property="og:locale" content="en_US">
<meta property="og:type" content="article">
<meta property="article:section" content="posts">
<meta property="article:published_time" content="2014-03-10T00:00:00+00:00">
<meta property="article:modified_time" content="2014-03-10T00:00:00+00:00">
<meta property="og:image" content="http://localhost:1313/posts/migrate-from-jekyll/yan-ots-257617-unsplash.jpg">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://localhost:1313/posts/migrate-from-jekyll/yan-ots-257617-unsplash.jpg">
<meta name="twitter:title" content="Migrate to Hugo from Jekyll">
<meta name="twitter: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
▾ &lt;root&gt;/ ▾ images/ logo.png should become
▾ &lt;root&gt;/ ▾ static/ ▾ images/ logo.png Additionally, you’ll want any files that should reside at the root (such as CNAME) to be moved to static.">
<script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@id":"http://localhost:1313/#person","@type":"Person","homeLocation":{"@type":"Place","name":"San Francisco, CA"},"image":"http://localhost:1313/headshot.jpg","jobTitle":"Job Title","name":"Joe Hutchinson","sameAs":["https://github.com/","https://instagram.com/","https://linkedin.com/","https://patreon.com/","https://youtube.com/"],"url":"http://localhost:1313/"},{"@id":"http://localhost:1313/posts/migrate-from-jekyll/","@type":"BlogPosting","author":{"@id":"http://localhost:1313/#person"},"dateModified":"2014-03-10T00:00:00Z","datePublished":"2014-03-10T00:00:00Z","description":"noesis Hugo theme for blogs","headline":"Migrate to Hugo from Jekyll","image":"http://localhost:1313/posts/migrate-from-jekyll/yan-ots-257617-unsplash.jpg","inLanguage":"en-US","isPartOf":{"@id":"http://localhost:1313/#website"},"mainEntityOfPage":"http://localhost:1313/posts/migrate-from-jekyll/","name":"Migrate to Hugo from Jekyll","publisher":{"@id":"http://localhost:1313/#person"},"url":"http://localhost:1313/posts/migrate-from-jekyll/"}]}</script>
<link href="/css/katex.min.9e0577d7101023e29eacd62ce616012cadc4d9f4f9c5ea0543ca5f32c2e00da8.css" rel="stylesheet" integrity="sha256-ngV31xAQI&#43;KerNYs5hYBLK3E2fT5xeoFQ8pfMsLgDag=" crossorigin="anonymous">
<meta name="theme-color" content="#f7f3eb" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#20201d" media="(prefers-color-scheme: dark)">
<meta name="color-scheme" content="light dark">
<link href="/css/noesis.min.38d798e1fe17d82ca96fb225efb02b30fff54c360db27974e5dce8dc3b20c987.css" rel="stylesheet" integrity="sha256-ONeY4f4X2Cypb7Il77ArMP/1TDYNsnl05dzo3DsgyYc=" crossorigin="anonymous">
</head>
<body class="single-body">
<a class="skip-link" href="#main-content">Skip to content</a>
<nav class="nav-bar side-padding" aria-label="Primary navigation">
<p class="nav-header"><a href="/" class="nav-text">noesis</a></p>
<ul class="nav-links">
<li><a href="/">Home</a></li>
<li><a href="/about/">About Hugo</a></li>
<li><a href="/categories/development/">Development</a></li>
<li><a href="/categories/features/">Features</a></li>
<li><a href="/categories/golang/">Golang</a></li>
<li><a href="/categories/web/">Web</a></li>
</ul>
<div class="hamburger-menu">
<input class="hamburger-menu-button" type="checkbox"
onclick="hamburgerMenuPressed.call(this)"
aria-label="Open navigation menu"
aria-expanded="false"
aria-controls="menu"
>
<div class="hamburger-menu-icon" aria-hidden="true">
<span></span>
<span></span>
</div>
<ul id="menu" class="hamburger-menu-overlay">
<li><a href="/" class="hamburger-menu-overlay-link">Home</a></li>
<li><a href="/about/" class="hamburger-menu-overlay-link">About Hugo</a></li>
<li><a href="/categories/development/" class="hamburger-menu-overlay-link">Development</a></li>
<li><a href="/categories/features/" class="hamburger-menu-overlay-link">Features</a></li>
<li><a href="/categories/golang/" class="hamburger-menu-overlay-link">Golang</a></li>
<li><a href="/categories/web/" class="hamburger-menu-overlay-link">Web</a></li>
</ul>
</div>
</nav>
<main id="main-content" class="content side-text-padding" tabindex="-1">
<article class="post">
<header class="post-header">
<div class="post-meta">
<p><time datetime="2014-03-10">Mar 10, 2014</time></p>
</div>
<h1 class="post-title">Migrate to Hugo from Jekyll</h1>
</header>
<figure class="post-figure">
<picture>
<source type="image/webp" srcset="/posts/migrate-from-jekyll/yan-ots-257617-unsplash_hu_c6c6215e1bf6bfe9.webp 711w" sizes="(min-width: 711px) 711px, 100vw">
<source srcset="/posts/migrate-from-jekyll/yan-ots-257617-unsplash_hu_c0823afd5df0a195.jpg 711w" sizes="(min-width: 711px) 711px, 100vw">
<img src="/posts/migrate-from-jekyll/yan-ots-257617-unsplash_hu_c0823afd5df0a195.jpg" width="711" height="533" alt="Colorful buildings alongside a body of water" loading="eager" decoding="async">
</picture>
</figure>
<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="https://gohugo.io/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="https://gohugo.io/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="https://gohugo.io/content-management/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>
</article>
</main>
<footer class="site-footer side-padding">
<p class="footer-brand">noesis</p>
<nav class="footer-links" aria-label="Footer navigation">
<a href="/">Home</a>
<a href="/about/">About Hugo</a>
<a href="/categories/development/">Development</a>
<a href="/categories/features/">Features</a>
<a href="/categories/golang/">Golang</a>
<a href="/categories/web/">Web</a>
</nav>
<div class="social-links footer-social-links"><a href="mailto:author@example.com" aria-label="Email" title="Email" style="--social-icon: url(&#39;/icons/email.svg&#39;); --social-icon-dark: url(&#39;/icons/email.svg&#39;);">
<span class="social-icon" aria-hidden="true"></span>
<span class="sr-only">Email</span>
</a><a href="https://github.com/" target="_blank" rel="noopener noreferrer" aria-label="GitHub" title="GitHub" style="--social-icon: url(&#39;/icons/github.svg&#39;); --social-icon-dark: url(&#39;/icons/github.svg&#39;);">
<span class="social-icon" aria-hidden="true"></span>
<span class="sr-only">GitHub</span>
</a><a href="https://instagram.com/" target="_blank" rel="noopener noreferrer" aria-label="Instagram" title="Instagram" style="--social-icon: url(&#39;/icons/instagram.svg&#39;); --social-icon-dark: url(&#39;/icons/instagram.svg&#39;);">
<span class="social-icon" aria-hidden="true"></span>
<span class="sr-only">Instagram</span>
</a><a href="https://linkedin.com/" target="_blank" rel="noopener noreferrer" aria-label="LinkedIn" title="LinkedIn" style="--social-icon: url(&#39;/icons/linkedin.svg&#39;); --social-icon-dark: url(&#39;/icons/linkedin.svg&#39;);">
<span class="social-icon" aria-hidden="true"></span>
<span class="sr-only">LinkedIn</span>
</a><a href="https://patreon.com/" target="_blank" rel="noopener noreferrer" aria-label="Patreon" title="Patreon" style="--social-icon: url(&#39;/icons/patreon.svg&#39;); --social-icon-dark: url(&#39;/icons/patreon.svg&#39;);">
<span class="social-icon" aria-hidden="true"></span>
<span class="sr-only">Patreon</span>
</a><a href="https://youtube.com/" target="_blank" rel="noopener noreferrer" aria-label="YouTube" title="YouTube" style="--social-icon: url(&#39;/icons/youtube.svg&#39;); --social-icon-dark: url(&#39;/icons/youtube.svg&#39;);">
<span class="social-icon" aria-hidden="true"></span>
<span class="sr-only">YouTube</span>
</a></div>
</footer>
<script defer src="/js/katex.min.e9822c57638322efdd9ede0164169216682eb5f5c90fb0d04d1d6014bab3a8ea.js" integrity="sha256-6YIsV2ODIu/dnt4BZBaSFmgutfXJD7DQTR1gFLqzqOo=" crossorigin="anonymous"></script>
<script defer src="/js/contrib/auto-render.min.e5372d199bcdae8b4de71d0f7ceba72a4ba12774a27c60a6f1f77d03b3228ee4.js" integrity="sha256-5TctGZvNrotN5x0PfOunKkuhJ3SifGCm8fd9A7MijuQ=" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
<script defer src="/js/core.min.f2db9fdefe6b9087ea561d6ef6b78b1e4e58c03586d262b1b17de4753f301471.js" integrity="sha256-8tuf3v5rkIfqVh1u9reLHk5YwDWG0mKxsX3kdT8wFHE=" crossorigin="anonymous"></script>
</body>
</html>