Hugo: Allow custom summary

Created on 27 Nov 2015  路  6Comments  路  Source: gohugoio/hugo

Automatically generated summaries are strange in many cases. Setting a marker to explicitly determine the end of the summary is not much better, since headings and the first sentences are merged together. Furthermore the first sentences of a text are not always the best summaries.

I suggest to make completely custom summaries possible. The summary should be a meta information of a page.

Most helpful comment

I guess what @helmbold wanted was a way to override the .Summary Page variable so you can just use .Summary in your template and let Hugo check if a custom summary is available in the front matter or not.
This would avoid the cumbersome
{{ if .Params.summary }}{{ .Params.summary }}{{ else }}{{ .Summary }}{{ end }}

All 6 comments

You can by putting the summary in the front matter, which is where all the meta info about the page lives.

@helmbold if your request is different than the solution that @bep already outlined then please reopen and provide more information

I tried it like this:

date = "2015-11-29T21:30:07+01:00"
draft = true
title = "My Title"
summary = "My compact summary"

But the rendered summary is the automatically generated summary. Could you add a little section to http://gohugo.io/content/summaries/ and explain how to create customized summaries?

Please have a look at the documentation about Page paramters, then combine this with the markdownify template func. It's all in the documentation - but you'll have to read and understand it, and stop guessing.

I guess what @helmbold wanted was a way to override the .Summary Page variable so you can just use .Summary in your template and let Hugo check if a custom summary is available in the front matter or not.
This would avoid the cumbersome
{{ if .Params.summary }}{{ .Params.summary }}{{ else }}{{ .Summary }}{{ end }}

In my experience this is not a rare need. We are preparing a documentation website where every page starts with "This page explains..." which is fine for page contents, but it makes some awkward summaries when listed in section pages. I can opt out by using Page parameters, but then summaries are not that useful outside of blog entries.

Was this page helpful?
0 / 5 - 0 ratings