While I love Hugo for a lot of things, there are a few that I think can still be improved. For example, the default Disqus template bothered me for a long time. I’m very familiar with Disqus, so I know how to set it up correctly and reasonably using my custom template, but Hugo’s default Disqus template could be very confusing to beginners before version 0.25. Eventually I could not stand explaining it over and over again, so I sent a pull request #3639 to Hugo and changed its default template.
Hugo’s content summaries is another thing that I was not satisfied from the beginning: neither the automatic nor the user-defined summary (<!--more-->) looks good in my eyes. I think it can be easily improved with a few little tricks. After I commented on the blogdown issue #92, I think it may be a good idea to explain how I create a summary for a post in Hugo, and the idea can be generalized to other site generators, too. Below is the code to be inserted to a Hugo template (e.g. _default/list.html) where you want to display the summary:
{{ with .Description }}
{{ $.Scratch.Set "summary" (markdownify .) }}
{{ else }}
{{ $.Scratch.Set "summary" ((delimit (findRE "(?s)(<p.*?>.*?</p>)" .Content) "[…] ") | plainify | truncate (default 200 $.Site.Params.summary_length) (default " …" $.Site.Params.text.truncated ) | replaceRE "&" "&" | safeHTML) }}
{{ end }}
{{ $.Scratch.Get "summary" }}
It uses an intermediate variable summary in $.Scratch1 to store the summary. Although we often want to use automatic summaries, there may be cases in which user-defined summaries are more desirable. That is what {{ with .Description }} does: if you provide a field named description in the YAML metadata, it will be used as the post summary. The automatic summary computed from the 4th line looks a little complicated, but the ideas are:
-
Find all consecutive blocks of paragraphs
(<p>.*</p>)+from the content, which is an HTML fragment. If there is anything else between two blocks of paragraphs, fill in with “[…]” (i.e.,[…]). -
Strip HTML tags by
plainify. -
Truncate the text to 200 characters by default, and this number is configurable throught the site parameter
summary_lengthin config.toml, e.g.,[params] summary_length = 300 -
If the text is more than 200 characters, append “…” (similarly, this is configurable).
-
replaceRE "&" "&"is a hack that I don’t know if I should explain. I just want to preserve HTML entities.
I think this approach is better because it only generates the summary from paragraphs, and paragraphs are often more readable as plain text than other HTML elements like headings, code blocks, or bullet lists. All these elements will be substituted by “[…]”. The other major advantage is that the length of a summary is fixed, and this is important when you want to show summaries on a grid layout, since all boxes will be approximately of the same size.
I happily came up with this approach when I was designing the Hugo XMag theme, and I hope it can be useful to other Hugo users, too.
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:xie@yihui.name -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
xie@yihui.name. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).