Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

summaryLength doesn't count headers, lists, or code blocks as words #11863

Closed
akbyrd opened this issue Jan 6, 2024 · 4 comments
Closed

summaryLength doesn't count headers, lists, or code blocks as words #11863

akbyrd opened this issue Jan 6, 2024 · 4 comments

Comments

@akbyrd
Copy link

akbyrd commented Jan 6, 2024

What version of Hugo are you using (hugo version)?

0.122.0

Does this issue reproduce with the latest release?

Yes

Given a config with summaryLength = 2 and a post with the following content

asd

## Header
- TODO: 1
- TODO: 2
- TODO: 3

## Header
- TODO: 1
- TODO: 2
- TODO: 3

## Header
- TODO: 1
- TODO: 2
- TODO: 3

The summary will be much longer than 2 words

asd Header TODO: 1 TODO: 2 TODO: 3 Header TODO: 1 TODO: 2 TODO: 3 Header TODO: 1 TODO: 2 TODO: 3

Inserting a second asd somewhere will truncate the summary sooner.

asd

## Header
asd
- TODO: 1
- TODO: 2
- TODO: 3

## Header
- TODO: 1
- TODO: 2
- TODO: 3

## Header
- TODO: 1
- TODO: 2
- TODO: 3

asd Header asd

From this, I gather that headers and lists are not counted as words and can lead to arbitrarily long summaries. I think they should both count toward the word limit.

Interestingly, lists sometimes count towards the word limit.

asd

## Header
- TODO: 1
asd
- TODO: 2
- TODO: 3

asd Header TODO: 1

In this case TODO: 1 has been counted as a word and the second asd was not included in the summary.

This also affects code blocks. Entire code blocks of arbitrary size are included in summaries without affecting the world limit.

@jmooring
Copy link
Member

jmooring commented Jan 6, 2024

TLDR: Use a manual summary in this case.

Automatic summary

When rendering an automatic summary, Hugo uses the summaryLength as a minimum and attempts to truncate at a sensible point in the text (e.g., at the end of a sentence).

Example 1

summaryLength =2

content

The quick brown fox jumps over the lazy dog. Consequat dolor cupidatat adipisicing consequat ut id proident amet id excepteur deserunt. Minim aute reprehenderit cupidatat ea magna mollit amet sunt officia id consequat id deserunt.

summary (data type = template.HTML)

The quick brown fox jumps over the lazy dog.

Example 2

summaryLength = 9

content

The quick brown fox jumps over the lazy dog. Consequat dolor cupidatat adipisicing consequat ut id proident amet id excepteur deserunt. Minim aute reprehenderit cupidatat ea magna mollit amet sunt officia id consequat id deserunt.

summary (data type = template.HTML)

The quick brown fox jumps over the lazy dog. Consequat dolor cupidatat adipisicing consequat ut id proident amet id excepteur deserunt.

Manual summary

To truncate at a specific point in the content, use a manual summary (summaryLength is irrelevant).

content

The quick <!--more--> brown fox jumps over the lazy dog. Consequat dolor cupidatat adipisicing consequat ut id proident amet id excepteur deserunt. Minim aute reprehenderit cupidatat ea magna mollit amet sunt officia id consequat id deserunt.

summary (data type = template.HTML)

<p>The quick</p>

Summary in front matter

Or you can specify the summary in front matter (summaryLength and manual break are irrelevant).

+++
title = 'Something'
date = 2024-01-06T08:46:33-08:00
draft = false
summary = 'The quick brown fox'
+++

summary (data type = template.HTML)

<p>The quick brown fox</p>

Other

This comment describes some of the other differences between the 3 summary types.

Opinion

In my view there are 3 different related things:

  1. A teaser (the first N sentences,)
  2. A description (one sentence, typically used in meta data)
  3. A summary (very different than a teaser)

For this reason I usually define both description and summary in front matter. If I don't define the summary in front matter, I always use a manual summary to precisely control the result.

I am closing this because the existing behavior is expected.

@akbyrd
Copy link
Author

akbyrd commented Jan 6, 2024

Manual and front matter summaries are a reasonable workaround that I've already switched to using. However it seems quite reasonable to say that summaryLength does not work properly or consistently. Being able to set a word limit then have it ignored means that option is non-functional.

It might be reasonable to treat this as dupe of #1503, since that may or may not end up addressing this.

@jmooring
Copy link
Member

jmooring commented Jan 6, 2024

We will handle this in documentation, see gohugoio/hugoDocs#2388.

The summaryLength, as described above, is not a word limit. With that in mind, and the subtleties of finding a sensible breaking point, the existing behavior is working properly and consistently.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants