Hi! I’m new to Hugo and one of the big plus for me has been the ability to specify custom output formats. Specifically I want to generate Web pages but also Gemtext content.
I also have defined a very simple template for both the home page (layouts/index.gmi) and single pages (layouts/_default/single.gmi). Running Hugo generates my Gemtext files fine, in the gemtext subfolder, with the .gmi extension, but shortcodes such as rel or relref are not processed, whereas in the generated HTML files they are correctly converted into links.
I’ve tried to write my own shortcode in layouts/shortcodes/, using a bunch of different extensions (relref.gemtext, relref.gemtext.text, relref.gemtext.html, relref.gmi, relref.gmi.text, with gemtext uppercased, etc) to no avail.
I’ve also tried to write a new shortcode with a unique name: it is easily rendered in the HTML pages but is left untouched in the Gemtext pages:
in content/test.md: {{< heyya >}}
in layouts/shortcodes/heyya.<everything-i-could-think-of>: {{- print "HEYYA" -}}
in public/gemtext/test.gmi: {{< heyya >}}
in public/test.html: <!-- html trimmed--> HEYYA
What am I missing? Let me know if you need additional snippets.
I’ve tried to play with .Content but discarded it because even though it correctly processes the shortcodes, it produces HTML content which is not the desired output. I just tried plainify but it removes all links and other Markdown semantics along the way
I expect the Markdown to not be rendered into HTML and kept mostly as-is, but with the shortcodes processed through definitions specific to that custom output format. Maybe it is a misleaded goal?
This is what I intended to do, but after following this thread my understanding is that the processing of shortcodes happens after the Markdown content has been initially processed (into HTML, JSON, etc) and I could not find a way to make Hugo use output-format-specific shortcodes without processing the Markdown.
Briefly:
.Content includes processed shortcodes but HTML is generated, which is not desired.
.RawContent is the Markdown as-is but skips shortcode processing.
What I wanted was only applying custom shortcodes (e.g. changing image or figure shortcodes into Markdown links to the images) but without rendering the Markdown into HTML or anything else, leaving the Markdown to Gemtext to an external, more appropriate tool. Even better would have been to render the Markdown into Gemtext as part of the Hugo execution, but I feel like this would require modifying Hugo itself. I may be wrong, again I’m discovering Hugo
When you call .Content the markdown is rendered to HTML. But if you have multiple versions of a given shortcode (language, output format), Hugo renders multiple versions of that same content.
I just tried it and indeed, with .Content I get the shortcodes “heyya”, defined differently both in heyya.html and heyya.gmi, to be used for the correct output formats in the resulting HTML and Gemtext pages.
This does not solve my issue (I do not want the Markdown to be rendered as HTML in my Gemtext pages) but at least I know how to make custom output format shortcodes work now.