Custom summary text in Blogdown
Update: This feature is now an official feature of the Tranquilpeak Theme!
By default, Hugo seems to summarize posts by taking the first 70 words. One can explicitly set the ‘fold’ by inserting <!--more-->
in the post’s Markdown file. However, this does not seem to work with Rmarkdown files in Blogdown. It seems that since Blogdown processes the files into an intermediate HTML form prior to feeding them to Hugo. Because of this, <!--more-->
winds up being carried along as an HTML comment versus splitting the Hugo summary.
To circumvent this limitation, I modified the Tranquilpeak theme to read in a per-post parameter .Params.Summary
(provided it exists) versus using Hugo’s .Summary
function. The explicit change was to modify layouts/_default/summary.html
by replacing {{ . Summary }}
with
{{ if .Params.Summary }}
{{ .Params.Summary | markdownify }}
{{ else }}
{{ .Summary }}
{{ end }}
I then created the summary for this post by including these lines in the YAML front matter:
summary: >
This post has custom summary text that displays on the homepage.
It is *not* actually present in the beginning of the post. The
rest of the post explains how I did this.
The handy pipe to markdownify allows for Markdown in the summary to be processed.