mirror of
https://github.com/Noettore/cocoa-eh-hugo-theme.git
synced 2025-10-15 11:46:41 +02:00
290 lines
12 KiB
HTML
290 lines
12 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en-US">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
|
<meta name="HandheldFriendly" content="True">
|
|
<meta name="MobileOptimized" content="320">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
|
|
|
|
|
|
<base href="http://localhost:1313/">
|
|
<title>
|
|
|
|
|
|
Migrate to Hugo from Jekyll · Hugo Themes
|
|
|
|
</title>
|
|
<link rel="canonical" href="http://localhost:1313/post/migrate-from-jekyll/">
|
|
|
|
<link rel="stylesheet" href="http://localhost:1313/css/reset.css">
|
|
<link rel="stylesheet" href="http://localhost:1313/css/pygments.css">
|
|
<link rel="stylesheet" href="http://localhost:1313/css/main.css">
|
|
|
|
|
|
|
|
<link rel="shortcut icon"
|
|
|
|
href="http://localhost:1313/img/myicon.ico"
|
|
|
|
>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
<body lang="en">
|
|
|
|
<div class="section header">
|
|
<div class="container">
|
|
<div class="content">
|
|
<nav>
|
|
<ul>
|
|
<a href="http://localhost:1313/posts"><li>posts</li></a>
|
|
<a href="http://localhost:1313/about"><li>about</li></a>
|
|
<a href="http://localhost:1313/code"><li>code</li></a>
|
|
</ul>
|
|
</nav>
|
|
<a href="http://localhost:1313/"><div class="name">map[]</div></a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section icons">
|
|
<div class="container">
|
|
<div class="content">
|
|
|
|
|
|
<a href="//github.com/username" target="_blank">
|
|
<i class="icon ion-social-github"></i>
|
|
</a>
|
|
|
|
|
|
|
|
<a href="//twitter.com/username" target="_blank">
|
|
<i class="icon ion-social-twitter"></i>
|
|
</a>
|
|
|
|
|
|
|
|
<a href="//linkedin.com/in/username" target="_blank">
|
|
<i class="icon ion-social-linkedin"></i>
|
|
</a>
|
|
|
|
|
|
|
|
<a href="//facebook.com/username" target="_blank">
|
|
<i class="icon ion-social-facebook larger"></i>
|
|
</a>
|
|
|
|
|
|
|
|
|
|
|
|
<a href="mailto:username@hogwarts.edu">
|
|
<i class="icon ion-ios-email larger"></i>
|
|
</a>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="section main">
|
|
<div class="container">
|
|
<div class="content">
|
|
|
|
|
|
<h2 id="move-static-content-to-static:964c172ef5e837f03573891408d8d631">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>▾ <root>/
|
|
▾ images/
|
|
logo.png
|
|
</code></pre>
|
|
|
|
<p>should become</p>
|
|
|
|
<pre><code>▾ <root>/
|
|
▾ static/
|
|
▾ images/
|
|
logo.png
|
|
</code></pre>
|
|
|
|
<p>Additionally, you’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:964c172ef5e837f03573891408d8d631">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="http://localhost:1313/overview/configuration/">Hugo configuration documentation</a> for details.</p>
|
|
|
|
<h2 id="set-your-configuration-publish-folder-to-site:964c172ef5e837f03573891408d8d631">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’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>{
|
|
..
|
|
"publishdir": "_site",
|
|
..
|
|
}
|
|
</code></pre></li>
|
|
</ol>
|
|
|
|
<h2 id="convert-jekyll-templates-to-hugo-templates:964c172ef5e837f03573891408d8d631">Convert Jekyll templates to Hugo templates</h2>
|
|
|
|
<p>That’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’s template documentation</a> if you need to refresh your memory on how you built your blog and <a href="http://localhost:1313/layout/templates/">Hugo’s template</a> to learn Hugo’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:964c172ef5e837f03573891408d8d631">Convert Jekyll plugins to Hugo shortcodes</h2>
|
|
|
|
<p>Jekyll has <a href="http://jekyllrb.com/docs/plugins/">plugins</a>; Hugo has <a href="http://localhost:1313/doc/shortcodes/">shortcodes</a>. It’s fairly trivial to do a port.</p>
|
|
|
|
<h3 id="implementation:964c172ef5e837f03573891408d8d631">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’s plugin:</p>
|
|
|
|
<pre><code>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)
|
|
</code></pre>
|
|
|
|
<p>is written as this Hugo shortcode:</p>
|
|
|
|
<pre><code><!-- 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 -->
|
|
</code></pre>
|
|
|
|
<h3 id="usage:964c172ef5e837f03573891408d8d631">Usage</h3>
|
|
|
|
<p>I simply changed:</p>
|
|
|
|
<pre><code>{% 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/ %}
|
|
</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="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/" %}}
|
|
</code></pre>
|
|
|
|
<p>As a bonus, the shortcode named parameters are, arguably, more readable.</p>
|
|
|
|
<h2 id="finishing-touches:964c172ef5e837f03573891408d8d631">Finishing touches</h2>
|
|
|
|
<h3 id="fix-content:964c172ef5e837f03573891408d8d631">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:964c172ef5e837f03573891408d8d631">Clean up</h3>
|
|
|
|
<p>You’ll want to remove the Jekyll configuration at this point. If you have anything else that isn’t used, delete it.</p>
|
|
|
|
<h2 id="a-practical-example-in-a-diff:964c172ef5e837f03573891408d8d631">A practical example in a diff</h2>
|
|
|
|
<p><a href="http://heyitsalex.net/">Hey, it’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>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
|
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
|
</script>
|
|
<script type="text/javascript">
|
|
try {
|
|
var pageTracker = _gat._getTracker("\x3cGoogle-Analytics-ID\x3e");
|
|
pageTracker._trackPageview();
|
|
} catch(err) {}
|
|
</script>
|
|
|
|
|
|
|
|
<script>document.write('<script src="http://'
|
|
+ (location.host || 'localhost').split(':')[0]
|
|
+ ':1313/livereload.js?mindelay=10"></'
|
|
+ 'script>')</script></body>
|
|
</html>
|
|
|