Files
SCDocs/public/posts/migrate-from-jekyll/index.html
JamesFlare1212 5aeea89a31 new subtopic llm
2023-05-11 21:33:10 +08:00

462 lines
17 KiB
HTML

<!DOCTYPE html>
<html lang="zh" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="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&rsquo;ll want any files that should reside at the root (such as CNAME) to be moved to static.">
<meta name="theme-color" content="#FFFFFF">
<meta name="color-scheme" content="light dark"><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&rsquo;ll want any files that should reside at the root (such as CNAME) to be moved to static." />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://academics.jamesflare.com/posts/migrate-from-jekyll/" /><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="2023-01-20T02:32:06+08:00" />
<title>Migrating from Jekyll | Academic Resources</title>
<link rel="manifest" href="/manifest.json">
<link rel="icon" href="/favicon.png" type="image/x-icon">
<link rel="stylesheet" href="/book.min.f8de3645fe00591b41524aee174e19edd98a22255a2930a0cdc82a94835ba387.css" integrity="sha256-&#43;N42Rf4AWRtBUkruF04Z7dmKIiVaKTCgzcgqlINbo4c=" crossorigin="anonymous">
<script defer src="/flexsearch.min.js"></script>
<script defer src="/en.search.min.a96ff1ebe93c483a6fabdb5dfeca9c5064addcd18e5db5d46117139d2e58ff1e.js" integrity="sha256-qW/x6&#43;k8SDpvq9td/sqcUGSt3NGOXbXUYRcTnS5Y/x4=" crossorigin="anonymous"></script>
<!--
Made with Book Theme
https://github.com/alex-shpak/hugo-book
-->
<link rel="stylesheet" href="https://academics.jamesflare.com/css/custom.css">
<script type="text/javascript" src="https://academics.jamesflare.com/js/custom.js"></script>
<script>pangu.spacingPage();</script>
</head>
<body dir="ltr">
<input type="checkbox" class="hidden toggle" id="menu-control" />
<input type="checkbox" class="hidden toggle" id="toc-control" />
<main class="container flex">
<aside class="book-menu">
<div class="book-menu-content">
<nav>
<h2 class="book-brand">
<a class="flex align-center" href="/"><span>Academic Resources</span>
</a>
</h2>
<div class="book-search">
<input type="text" id="book-search-input" placeholder="Search" aria-label="Search" maxlength="64" data-hotkeys="s/" />
<div class="book-search-spinner hidden"></div>
<ul id="book-search-results"></ul>
</div>
<ul class="book-languages">
<li>
<input type="checkbox" id="languages" class="toggle" />
<label for="languages" class="flex justify-between">
<a role="button" class="flex align-center">
<img src="/svg/translate.svg" class="book-icon" alt="Languages" />
English
</a>
</label>
<ul>
<li>
<a href="https://academics.jamesflare.com/zh/">
Chinese
</a>
</li>
</ul>
</li>
</ul>
<ul>
<li>
<a href="/posts/" >
动态
</a>
</li>
</ul>
</nav>
<script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script>
</div>
</aside>
<div class="book-page">
<header class="book-header">
<div class="flex align-center justify-between">
<label for="menu-control">
<img src="/svg/menu.svg" class="book-icon" alt="Menu" />
</label>
<strong>Migrating from Jekyll</strong>
<label for="toc-control">
<img src="/svg/toc.svg" class="book-icon" alt="Table of Contents" />
</label>
</div>
<aside class="hidden clearfix">
<nav id="TableOfContents">
<ul>
<li><a href="#move-static-content-to-static">Move static content to <code>static</code></a></li>
<li><a href="#create-your-hugo-configuration-file">Create your Hugo configuration file</a></li>
<li><a href="#set-your-configuration-publish-folder-to-_site">Set your configuration publish folder to <code>_site</code></a></li>
<li><a href="#convert-jekyll-templates-to-hugo-templates">Convert Jekyll templates to Hugo templates</a></li>
<li><a href="#convert-jekyll-plugins-to-hugo-shortcodes">Convert Jekyll plugins to Hugo shortcodes</a>
<ul>
<li><a href="#implementation">Implementation</a></li>
<li><a href="#usage">Usage</a></li>
</ul>
</li>
<li><a href="#finishing-touches">Finishing touches</a>
<ul>
<li><a href="#fix-content">Fix content</a></li>
<li><a href="#clean-up">Clean up</a></li>
</ul>
</li>
<li><a href="#a-practical-example-in-a-diff">A practical example in a diff</a></li>
</ul>
</nav>
</aside>
</header>
<article class="markdown">
<h1>
<a href="/posts/migrate-from-jekyll/">Migrating from Jekyll</a>
</h1>
<h5>March 10, 2014</h5>
<h2 id="move-static-content-to-static">
Move static content to <code>static</code>
<a class="anchor" href="#move-static-content-to-static">#</a>
</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
<a class="anchor" href="#create-your-hugo-configuration-file">#</a>
</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>
<a class="anchor" href="#set-your-configuration-publish-folder-to-_site">#</a>
</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
<a class="anchor" href="#convert-jekyll-templates-to-hugo-templates">#</a>
</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
<a class="anchor" href="#convert-jekyll-plugins-to-hugo-shortcodes">#</a>
</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
<a class="anchor" href="#implementation">#</a>
</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
<a class="anchor" href="#usage">#</a>
</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
<a class="anchor" href="#finishing-touches">#</a>
</h2>
<h3 id="fix-content">
Fix content
<a class="anchor" href="#fix-content">#</a>
</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
<a class="anchor" href="#clean-up">#</a>
</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
<a class="anchor" href="#a-practical-example-in-a-diff">#</a>
</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>
<footer class="book-footer">
<div class="flex flex-wrap justify-between">
<div><a class="flex align-center" href="https://github.com/JamesFlare1212/SCDocs/commit/d2b7c62a10e2c7f8db801c881ab595830b3f7a7c" title='Last modified by JamesFlare1212 | January 20, 2023' target="_blank" rel="noopener">
<img src="/svg/calendar.svg" class="book-icon" alt="Calendar" />
<span>January 20, 2023</span>
</a>
</div>
<div>
<a class="flex align-center" href="https://github.com/JamesFlare1212/SCDocs/edit/dev/content.en/posts/migrate-from-jekyll.md" target="_blank" rel="noopener">
<img src="/svg/edit.svg" class="book-icon" alt="Edit" />
<span>Edit this page</span>
</a>
</div>
</div>
<script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script>
</footer>
<div class="book-comments">
</div>
<label for="menu-control" class="hidden book-menu-overlay"></label>
</div>
<aside class="book-toc">
<div class="book-toc-content">
<nav id="TableOfContents">
<ul>
<li><a href="#move-static-content-to-static">Move static content to <code>static</code></a></li>
<li><a href="#create-your-hugo-configuration-file">Create your Hugo configuration file</a></li>
<li><a href="#set-your-configuration-publish-folder-to-_site">Set your configuration publish folder to <code>_site</code></a></li>
<li><a href="#convert-jekyll-templates-to-hugo-templates">Convert Jekyll templates to Hugo templates</a></li>
<li><a href="#convert-jekyll-plugins-to-hugo-shortcodes">Convert Jekyll plugins to Hugo shortcodes</a>
<ul>
<li><a href="#implementation">Implementation</a></li>
<li><a href="#usage">Usage</a></li>
</ul>
</li>
<li><a href="#finishing-touches">Finishing touches</a>
<ul>
<li><a href="#fix-content">Fix content</a></li>
<li><a href="#clean-up">Clean up</a></li>
</ul>
</li>
<li><a href="#a-practical-example-in-a-diff">A practical example in a diff</a></li>
</ul>
</nav>
</div>
</aside>
</main>
<script src="/js/pangu.min.js"></script>
<script>pangu.spacingPage();</script>
</body>
</html>