Hugo Shortcode for Embedded Gists


Hugo is a fantastic static site generator written in Go. One particularly nice feature of Hugo is how simple it is to create custom shortcodes for customizing content generation beyond what’s supported by Markdown.

A common case for tech and development blogs is embedding code from GitHub Gists. Here’s a simple way to embed gists into your content without writing HTML in your Markdown:

  • Create a “layouts/shortcodes” directory if it doesn’t already exist
  • Add “gist.html” to “layouts/shortcodes” with the following content
  • To embed a gist, simply add the following to your Markdown content
	 {{< gist gist_sha1_hash >}} 

And you’ve got yourself an embedded gist!