Skip to content

.Page.Truncated sometimes returns an incorrect value with automatic summaries #13968

@jmooring

Description

@jmooring

In the test below, all but the last assertion fail because the value of .Truncated is the opposite of what it should be.

func TestIssue13968(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
summaryLength = SUMMARY_LENGTH
-- layouts/all.html --
Title: {{ .Title }}|Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|
-- content/_index.md --
---
title: home
---
one two three
`

	tests := []struct {
		summaryLength int
		want          string
	}{
		{0, "Title: home|Summary: |Truncated: true|"},                      // fails
		{1, "Title: home|Summary: <p>one two three</p>|Truncated: false|"}, // fails
		{2, "Title: home|Summary: <p>one two three</p>|Truncated: false|"}, // fails
		{3, "Title: home|Summary: <p>one two three</p>|Truncated: false|"}, // fails
		{4, "Title: home|Summary: <p>one two three</p>|Truncated: false|"},
	}

	for _, tt := range tests {
		f := strings.ReplaceAll(files, "SUMMARY_LENGTH", strconv.Itoa(tt.summaryLength))
		b := hugolib.Test(t, f)
		b.AssertFileContent("public/index.html", tt.want)
	}
}

Reference: https://discourse.gohugo.io/t/problem-with-the-truncated-method-returning-true-when-it-shouldnt/55861

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions