I’m using Hugo’s built-in excerpt/content feature, but when dealing with the single.html layout I want to remove the excerpt completely.
So I’m using this:
<article>
{{ $post := split .RawContent "<!--more-->" }}
{{ if index $post 1 }}
{{ index $post 1 | markdownify | emojify }}
{{ else }}
{{ .Content }}
{{ end }}
</article>
Unfortunately it seems that Hugo cannot render the shortcodes that reside inside the $post. I’ve tried looking for a filter (similar to markdownify or emojify) for shortcodes but no luck.
Am I doing things wrong? How can I render the shortcodes correctly?
Did you initialize index? What is the error output?
It’s not clear to me what the variables are but,
I would think something like this would work (after post line):
{{ range index, $element := $post }}
{{ (if eq index 1) }}
{{ $element | markdownify | emojify }}
{{ else }}
{{ .Content }}
{{ end }}
Index does not need to be initialized for this to work. Besides I don’t have any compilation error, it’s just that the shortcode is not interpreted and I get raw template syntax instead.
Your example doesn’t work though, as I do get a compilation error:
ERROR 2018/10/18 09:57:10 Failed to add template "blog/single.html" in path "blog/single.html": template: blog/single.html:53: unexpected "," in operand
I’m don’t think you should use the content summary feature. It doesn’t do what you want; it is for showing a short summary at the beginning of the post.
If you want an excerpt, I recommend using a front matter field, such as excerpt. Then you’ll have complete control as you want.
So if I understand correctly, it’s impossible to extract the main body of a post when using content summary. I feel like this is something that’s missing in Hugo.
Using a front matter field is a good workaround, I think I’ll use that. But since we can use .Summary and .Truncated, it could be nice to use something like .Detail to fetch the rest of a post. Or at leat Hugo should be able to interpret shortcodes inside these like I showed in the first post.
There is an issue about it as well, linked in one of the threads. But from a content standpoint, what you want is actually a separate field, and not a “summary” per se. A summary is still part of the content.