• Stars
    star
    826
  • Rank 53,200 (Top 2 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created over 7 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A carefully crafted Org exporter back-end for Hugo

Ox-Hugo: A carefully crafted Org exporter back-end for Hugo

https://github.com/kaushalmodi/ox-hugo/actions/workflows/test.yml/badge.svg https://melpa.org/packages/ox-hugo-badge.svg https://img.shields.io/badge/License-GPL%20v3-blue.svg

If you have any questions or if you have anything interesting to share related to ox-hugo, feel free to do so on Discussions!

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.

Table of Contents

Screenshots

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).

One post per Org subtree (preferred)

https://raw.githubusercontent.com/kaushalmodi/ox-hugo/main/doc/static/images/one-post-per-subtree.png

Files in above screenshot
Org -> Markdown

One post per Org file

https://raw.githubusercontent.com/kaushalmodi/ox-hugo/main/doc/static/images/one-post-per-file.png

Files in above screenshot
Org -> Markdown

Editorial

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.

Documentation

ox-hugo uses itself to generate its documentation!

https://ox-hugo.scripter.co/

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:

Source of the Documentation site

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.

Demo

Org source=ox-hugo= Exported Markdownhttps://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.

Installation

This package requires at least GNU Emacs 26.3 and Org Mode 9.0. It is available on Melpa (https://melpa.org/#/ox-hugo), and it’s recommended to install this package from Melpa (​_not_ Melpa Stable).

You will need to require the package after installing it to get the ox-hugo export options 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))

Use Package

If you use =use-package=, you can do the below instead:

(use-package ox-hugo
  :ensure t   ;Auto-install the package from Melpa
  :pin melpa  ;`package-archives' should already have ("melpa" . "https://melpa.org/packages/")
  :after ox)

Spacemacs

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).

Usage

Before you export

Before you export check that these properties are set as you need:

HUGO_BASE_DIR
Root directory of the source for the Hugo site. If this is set to ~/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:

  1. Setting the #+hugo_base_dir: keyword in the Org file.
  2. Setting the org-hugo-base-dir variable in a .dir-locals.el or File Local Variables.
HUGO_SECTION
The default Hugo section name for all the posts. See here for more information on Hugo sections. It is common for this property to be set to 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. For that reason, a subtree with =EXPORT_FILE_NAME= property cannot nest another subtree with that property. If you can analogize with the branch/leaf data structure terminlogy, then the subtrees with EXPORT_FILE_NAME property need to be leaf nodes.

[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_FRAG property (only for per-subtree exports).

Export bindings

The common ox-hugo export bindings are:

For both one-post-per-subtree and one-post-per-file flows

C-c C-e H H
Export “What I Mean”. This is same as calling the org-hugo-export-wim-to-md function interactively or via (org-hugo-export-wim-to-md) in Emacs Lisp.
  • If point is in a valid Hugo post subtree, export that subtree to a Hugo post in Markdown.

    A valid Hugo post subtree is an Org subtree that has the EXPORT_FILE_NAME property set. *Note that a subtree with EXPORT_FILE_NAME property cannot nest a subtree with the same property set.* If you can analogize with the branch/leaf data structure terminlogy, then the subtrees with EXPORT_FILE_NAME property need to be leaf nodes.

  • If the file is intended to be exported as a whole (i.e. has the #+title keyword), export the whole Org file to a Hugo post in Markdown.
C-c C-e H A
Export all “What I Mean”. This is same as executing (org-hugo-export-wim-to-md :all-subtrees) in Emacs Lisp.
  • If the Org file has one or more ‘valid Hugo post subtrees’, export them to Hugo posts in Markdown.
  • If the file is intended to be exported as a whole (i.e. no ‘valid Hugo post subtrees’ at all, and has the #+title keyword), export the whole Org file to a Hugo post in Markdown.

For only the one-post-per-file flow

C-c C-e H h
Export the Org file to a Hugo post in Markdown. This is same as calling the org-hugo-export-to-md function interactively.

Also see the Auto Exporting section.

Customization Options

Do M-x customize-group, and select org-export-hugo to see the available customization options for this package.

Thanks

  • Matt Price (@titaniumbones)
  • Puneeth Chaganti (@punchagan)
  • Also thanks to 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.

More Repositories

1

.emacs.d

My emacs configuration
Emacs Lisp
258
star
2

eless

A Better 'less' - A bash script that loads emacs with minimal view-mode config - Created with Org mode
Shell
119
star
3

hugo-bare-min-theme

A bare minimum theme for Hugo (https://gohugo.io) to help develop and debug Hugo sites -- https://hugo-bare-min.netlify.com/,
HTML
78
star
4

hello_musl

NimScript (config.nims) for building a static binary using Nim + musl + pcre + libressl/openssl
Nim
77
star
5

hugo-search-fuse-js

Hugo theme component for implementing static site search using Fuse.js
HTML
65
star
6

nim_config

Global project-agnostic config.nims
Nim
58
star
7

hugo-debugprint

Hugo "debugprint.html" partial
HTML
47
star
8

dotfiles

Python
44
star
9

hugo-atom-feed

Hugo theme component for ATOM feed custom Output Format
33
star
10

custom_uvm_report_server

Customized UVM Report Server
SystemVerilog
29
star
11

hugo-onyx-theme

A Hugo theme built using the Hugo Alabaster theme as base
CSS
28
star
12

nim-systemverilog-dpic

Using Nim to interface with SystemVerilog test benches via DPI-C
SystemVerilog
21
star
13

ptr_math

Pointer arithmetic in Nim
Nim
11
star
14

ntodo

CLI app for Todoist written in Nim (REST API v8)
Nim
10
star
15

std_vector

Nim wrapper for C++ std::vector
Nim
10
star
16

ox-minutes

Plain text backend for Org for meeting minutes
Emacs Lisp
9
star
17

tomelr

Emacs-Lisp Library for converting S-expressions to TOML
Emacs Lisp
6
star
18

version

Fetch and parse the version number of most CLI apps
Nim
5
star
19

elnim

Collection of Nim procs/templates/macros which can serve as "phew! I am glad Nim has this!" for Emacs/Emacs-Lisp/Lisp enthusiasts.
Nim
5
star
20

strfmt

A string formatting module for Nim, inspired by Python's .format
Nim
4
star
21

nim-systemverilog-vpi

Using Nim to interface with Verilog and SystemVerilog test benches via VPI
C
3
star
22

hugo-micro-json

Hugo theme component for a custom JSON Output Format
2
star
23

p4ztag_to_json

Convert Perforce P4 Ztag data format to JSON
Nim
2
star
24

hugo-jf2

Hugo theme component for JF2 custom Output Format
2
star
25

nim-svdpi

Small wrapper for SystemVerilog DPI-C header svdpi.h
Nim
2
star
26

jenkins-minimal

Minimal Jenkins config repo
Shell
2
star
27

nim-eggx

Nim wrapper for EGGX / ProCALL X11 Graphics library
C
1
star
28

scripts

Bunch of scripts
Shell
1
star
29

iosevka-mirror

Repo to host Iosevka woff and woff2 for my sites (Credit: https://github.com/be5invis/Iosevka)
Shell
1
star
30

noxhugo

Utility to build Hugo sites using ox-hugo (Emacs + Org mode)
Nim
1
star
31

parse_c_header

Library to parse C header files
Nim
1
star
32

baser

Emacs-Lisp Library for converting to and from Decimal, Hexadecimal and Binary numbers
Emacs Lisp
1
star
33

nim-nightly-docs

Unofficial repo to host nightly builds of Nim docs from devel branch
HTML
1
star