Hugo Include file shortcode
If you include large snippets of text, like source code, in you content the markdown gets bloated quite a lot. This shortcode provides a solution by allowing to include resource files as plain text which can be used as text in markdown and wrapped by other shortcodes, e.g. highlighting source code.
This article was written for Hugo 0.74
.
Usage
There are no options, just provide the name of the resource file. This is how all code snippets on this website are included in markdown.
Example, reading a file with sourcecode:
{{< read-file "readFile/read-file.html.txt" >}}
{{- (.Page.Resources.GetMatch (.Get 0)).Content | safeHTML -}}Code
The implementation is trivial, using just Hugo’s build in functionality.
|
|
- Permalink: //oostens.me/posts/hugo-include-file-shortcode/
- License: The text and content is licensed under CC BY-NC-SA 4.0. All source code I wrote on this page is licensed under The Unlicense; do as you please, I'm not liable nor provide warranty.
Noticed an error in this post? Corrections are
spam.appreciated.