Today I built a system to read a markdown file from one location in my Hugo project into another.
It has two parts, a shortcode that reads an argument and parses it as markdown:
<!-- layouts/shortcodes/include-markdown.html -->
{{ readFile (.Get 0) | markdownify }}
And using that shortcode:
<!-- about.md -->
{{< include-markdown "doc/about-content.md" >}}
This lets me put a file into docs/ and read it into my template, a handy way
to reduce duplication in my app.
- Get – Hugo docs
- markdownify – Hugo docs
- readFile – Hugo docs