Site Migration to Jekyll and AsciiDoc
This post documents some of the quirks involved in setting up a weblog that uses both Markdown and AsciiDoc.
This site used to be built using the Hugo static website generator previously. Although Hugo is very capable at handling content written in Markdown, it needs to invoke an external program to process content in the AsciiDoc format.
The canonical tool for translating AsciiDoc to HTML is a Ruby-based program named AsciiDoctor.[1] However, getting Hugo and Asciidoctor to work well together turned out to be tricky.
I ended up migrating the site to use the Ruby-based Jekyll static site generator instead of Hugo. I could then use the Jekyll AsciiDoc plugin for translating AsciiDoc content.
Migration Steps
The main steps needed for the migration were:
-
Changing the Hugo-isms in existing Markdown content to their Jekyll equivalents.
-
Aligning CSS stylesheets.
Changing Hugo-isms To Jekyll-isms
Custom Shortcodes
Hugo has the notion of a “shortcode”, which is special syntax that expands to HTML when used. Hugo allows users to implement their own shortcodes.
Jekyll does not have shortcodes, but it instead has “includes” that support parameters. This Jekyll feature sufficed to implement equivalents for the custom Hugo shortcodes that I had used for my site.
For example:
Hugo | Jekyll |
---|---|
|
|
Here the Jekyll inclusion of googleslides.html
expands to the same
HTML that the custom Hugo googleslides
shortcode expands to.
Translating Hugo’s {{< figure ... }}
Hugo’s figure
shortcode wraps its content in an HTML <figure>
element.
I used a third-party Ruby gem named “jekyll-figure”
for migrating from Hugo to Jekyll. This Ruby gem implements a Jekyll
“tag”, also named figure
, that works in a fashion similar to
Hugo’s figure
shortcode.
Hugo | Jekyll |
---|---|
|
|
Note
|
The {:style=...} construct in the Jekyll code above centers
the figure. Hugo’s figure shortcode centers figures by default, but
the Jekyll plugin does not.
|
Translating Hugo’s {{< relref ... }}
The uses of Hugo’s builtin relref
shortcode were replaced by
equivalent uses of Jekyll’s relative_url
filter.
Path Differences
Hugo and Jekyll place the HTML files that they generate in differing
locations in the built site. These locations were however easy to
align in configuration (file: _config.yml
for Jekyll), or adjusted for in
the migrated text files using Jekyll’s permalink
feature.
CSS Adjustments
I used the default Minima theme as the ‘base’ theme for the migrated site. This theme comes with its own set of CSS rules.
However, the HTML produced by the Jekyll AsciiDoc plugin expects its
own set of CSS rules to be present (see asciidoctor.css
from the
Jekyll AsciiDoc Quickstart project).
These two CSS rule sets are not compatible. I ended up tweaking the CSS in the two rulesets to make the rendered AsciiDoc and Markdown content look "similar enough".
The styling of this site definitely needs further work.
Future Work
Generate Cleaner HTML
The html5
backend to Jekyll AsciiDoc currently generates ‘noisy’
HTML, with many redundant <div>
elements. For example, every
paragraph in AsciiDoc source is wrapped in a redundant <div>
element:
Asciidoc |
|
HTML output |
|
There appears to be a plugin for Jekyll that generates ‘semantic’
HTML on Github:
asciidoctor-html5s.
However, the HTML code that this plugin generates seems to be
incompatible with the asciidoctor.css
CSS ruleset.
Crafting a suitable set of CSS rules and then using this plugin could perhaps be a future project.
Use A Responsive Jekyll Theme
A ‘responsive’ theme should make this site easier to view on mobile devices.
I may attempt a change of theme after I learn how CSS (‘responsive’ CSS in particular) works. 😎
Conclusion
The site has been migrated. Its content is currently a mix of Markdown and AsciiDoc, with the two blending together reasonably well.
I look forward to getting on with writing documentation in AsciiDoc.