ox-hugo
is an Org exporter backend that exports Org to Hugo-compatible Markdown (Blackfriday) and also generates the front-matter (in TOML or YAML format).
The ox-hugo
backend extends from a parent backend ox-blackfriday.el
. The latter is the one that primarily does the Blackfriday-friendly Markdown content generation. The main job of ox-hugo
is to generate the front-matter for each exported content file, and then append that generated Markdown to it.
There are, though, few functions that ox-hugo.el
overrides over those by ox-blackfriday.el
.
See the Real World Examples section to quickly jump to sites generated using ox-hugo
and their Org sources.
Before you read further, you can see below how ox-hugo
translates Org to Markdown (Org on the left; exported Markdown with Hugo front-matter on the right).
The preferred way to organize the posts is as Org subtrees (also the main reason to write this package, as nothing like that was out there) as it makes the meta-data management for Hugo front-matter pretty effortless.
If you are a one Org-file per post type of a person, that flow works too! Just note that in this flow many of those #+hugo_
properties need to be managed manually.. just as one would manage the front-matter in Markdown files — See the Org versions in the above screenshots for comparison.
ox-hugo
uses itself to generate its documentation!
You can generate the same too! Simply clone this repo and do make doc_md
.
Make sure you visit the above link to read more on:
ox-hugo
?The documentation site is published by first using ox-hugo
to export from Org to Markdown, and then finally hugo
. So no Markdown files are committed in the =doc/content/= directory.
Org source → =ox-hugo= Exported Markdown → https://ox-hugo.scripter.co/test
The test site uses a minimal theme written just for debug purposes (not extra aesthetics). The test site is designed to verify if all the content translates from Org to Markdown as expected.
See Hugo Themes for examples of really good site prettification and presentation styles.
This package requires emacs 24.4+ and Org 9.0+. It is available on Melpa (https://melpa.org/#/ox-hugo).
Once the package is installed, you will need to require it so that the ox-hugo
export options are available in the Org Export Dispatcher menu (the one you see when you hit C-c C-e
to initiate any export).
You can do that by adding the below to your config:
(with-eval-after-load 'ox
(require 'ox-hugo))
If you use =use-package=, you can do the below instead:
(use-package ox-hugo
:ensure t ;Auto-install the package from Melpa (optional)
:after ox)
Also see the Auto Exporting section.
Spacemacs users can use ox-hugo
by setting the variable org-enable-hugo-support
.
(setq-default dotspacemacs-configuration-layers
'((org :variables
org-enable-hugo-support t)))
This was verified to work on Spacemacs =develop= branch (ref).
Before you export check that these properties are set as you need:
~/hugo/
, the exported Markdown files will be saved to
~/hugo/content/<HUGO_SECTION>/
directory[fn:-1-section_more]. By default, the Markdown files reside in a hierarchy under the
content/
directory in the site root directory (
ref).
If you try to export without setting this property, you will get this error:
user-error: It is mandatory to set the HUGO_BASE_DIR property or the `org-hugo-base-dir' local variable
This property can be set by one of two ways:
#+hugo_base_dir:
keyword in the Org file.org-hugo-base-dir
variable in a .dir-locals.el
or File Local Variables.posts
or
blog
. The default value is set using
org-hugo-default-section-directory
. See
Hugo Section for details.
Important: If you choose to export an Org subtree as a post, you need to set the EXPORT_FILE_NAME
subtree property. That property is used by this package to figure out where the current post starts.
[fn:-1-section_more] The HUGO_SECTION
is the bare-minimum requirement to specify the destination path. That path can be further tweaked using HUGO_BUNDLE
key (and the associated EXPORT_HUGO_BUNDLE
property), and the EXPORT_HUGO_SECTION*
property (only for per-subtree exports).
The common ox-hugo
export bindings are:
C-c C-e H H
A valid Hugo post subtree is an Org subtree that has the EXPORT_FILE_NAME
property set.
#+title
keyword), export the whole Org file to a Hugo post in Markdown.C-c C-e H A
#+title
keyword), export the whole Org file to a Hugo post in Markdown.C-c C-e H h
Do M-x customize-group
, and select org-export-hugo
to see the available customization options for this package.
org-hugo-pandoc-cite-references-heading
This is the Markdown heading that gets inserted before the section of references inserted by Pandoc inserted (See Pandoc Citations) at the end of the post.
To prevent the insertion of that Markdown heading, set this variable to an empty string (=”“=).
resources
front-matter (Hugo v0.33+) – #115.headless
front-matter (Hugo v0.35+).#+attr_html
and #+attr_css
(this one is unique to ox-hugo
) above Org tables. See its documentation – #93.
#+attr_html
and #+attr_css
for paragraphs, example blocks, source blocks, plain lists and quote blocks too – #113.publishDate
front-matter property gets auto-derived from the SCHEDULED
special property if associated with the valid Hugo post subtree – commit 0807f42d.
C-c .
binding in the HUGO_PUBLISHDATE
and HUGO_EXPIRYDATE
properties too.figcaption,
.src-block-caption,
.table-caption {
font-style: italic;
text-align: center;
}
#+begin_mark
/Some/ *marked* text
#+end_mark
:EXPORT_HUGO_SECTION:
in the valid Hugo post subtree itself.HUGO_FRONT_MATTER_KEY_REPLACE
– see commit b72a5fb0.title
as a valid property of menu
front-matter (Hugo v0.32+).#+hugo_tags
, #+hugo_categories
and #+keywords
. See this commit for details and examples – commit 319435db.HUGO_LEVEL_OFFSET
not getting set – #117, thanks @*shimmy1996*!#+name
– commit fef0ec50.*
, _
and `
show up fine, verbatim, in the title.#
and ![
in Markdown export – #110 (fix in upstream =ox-md.el=).hugo-bare-min-theme
used for the test site is made more portable (at some point, that theme might be moved to a separate repo).outputs
front-matter variable is a list.#+author
and #+creator
keywords and their respective Org Export Options – #106.nil
i.e. be not be a part of the front-matter .. because you can.ox-hugo
on doing per-subtree or per-file exports.. the progress of files exported using per-subtree flow is now clearer, and the name of the file exported using per-file flow is now explicit.. Helps when you batch export a dozen files with a mix of these 2 flows.org-hugo-export-wim-to-md
for details. If you are using the Auto-export on saving flow, note the function name change there too!
HUGO_CODE_FENCE
keyword – #102.(c)
, (r)
, (tm)
inside Latex equations – #104 (Upstream bug workaround).ox-hugo
works on emacs 24.4 too (but please upgrade to the latest Emacs and Org stable versions!).num
export option. Now you can prefix all post headings (or some not.. the ones with UNNUMBERED
property set to t
) with their section numbers – #76.<l>
, <r>
, <c>
) are now exported to equivalent Markdown tables.. so a center-aligned column in Org buffer will remain center-aligned in the final HTML too! – #95.HUGO_SECTION
values (subtree-based exports) for those alias prefixes.md
) source blocks, they will be auto-escaped (useful when you want to document/talk about some Hugo shortcode in a blog post) – #94.ATTR_HTML
above even hyper-linked images works (earlier it worked only above non-hyper-linked images).num
Org export option is default to nil
(only for ox-hugo
). So Org TOC’s are exported without section numbers by default. To get section numbers, set num
to t
or onlytoc
.ox-hugo
then exports those to Markdown, and then Hugo publishes those to HTML (as before) — all on Netlify.ox-hugo
yourself
#+attr_html
above http/https/ftp links is now supported (useful for specifying the target
, rel
, attributes, for example).:height
parameter in the #+attr_html
above image links. That eventually gets transformed to the height
parameter in the figure
tag in the HTML generated by Hugo. This feature requires building Hugo from its master branch with commit 488631fe (or Hugo v0.31+).EXPORT_HUGO_SECTION
not getting inherited #90.#+tags
. Now that keyword (and the EXPORT_TAGS
property) is not used by ox-hugo
. Fixes #89.#+hugo_tags
to set the post tags.EXPORT_HUGO_TAGS
property to override Org-style tags on the same headline (and the ones inherited from Org-style tags from any of the parent subtrees and #+filetags
).
#+filetags
can be used to set tags globally in the file. Earlier #+tags
was used for that purpose.EXPORT_HUGO_CATEGORIES
property to override Org-style categories (tags with “@” prefix) on the same headline (and the ones inherited from Org-style categories from any of the parent subtrees and #+filetags
).
#+filetags
can be used to set categories (tags with “@”) globally in the file.See the new section added to documentation: *Tags and Categories*
:width
parameter in the #+attr_html
above image links. That eventually gets transformed to the width
parameter in the figure
tag in the HTML generated by Hugo.See Source Blocks for details.
org-hugo-slug
earlier stripped off only the code
HTML tag (<code> .. </code>
) from the input string, if present. Now it does that for any HTML tag, like span
. For example, this HTML gets stripped off from the above heading (only inside org-hugo-slug
when deriving the slug string): ~<span class=”timestamp-wrapper”><span class=”timestamp”><2017-10-11 Wed></span></span>~.ox-hugo
by default requires text, to be sub/super-scripted, to be wrapped in {}
. So now a_b
will be exported as a_b
, but a_{b}
will be exported as a<sub>b</sub>
. To revert back to the earlier behavior, user needs to add #+options: ^:t
to their Org file.HUGO_WEIGHT
set to auto
for per-file exports #83.figure
shortcode parameters #79.org-hugo-delete-trailing-ws
defaults to t
; now Hugo deletes trailing white-spaces by default.org-hugo-default-static-subdirectory-for-externals
and org-hugo-external-file-extensions-allowed-for-copying
(related to #69).HUGO_STATIC_IMAGE
option; fix attachment re-write #69.HUGO_PRESERVE_FILLING
.org-hugo-use-code-for-kbd
option to nil
[ 88ba15ae ].#+hugo_code_fence: nil
, will evaluate as nil instead of t, as now org-hugo--plist-get-true-p
is used to parse boolean keys instead of plist-get
.org-hugo--date-time-regexp
. Earlier time zones ahead of UTC (with +
sign) were not detected as dates in org-hugo--quote-string
and thus were unnecessarily quoted.org-entry-get
at places instead of maintaining global variables.http://whyarethingsthewaytheyare.com/setting-up-the-blog/
(not hyperlinking the link as it is insecure — not https), http://www.holgerschurig.de/en/emacs-blog-from-org-to-hugo/
(not hyperlinking the link as it is insecure — not https) and the =goorgeous= project by Chase Adams (@chaseadamsio) for inspiration to start this project.