diff options
author | Paul Gottschling <paul.gottschling@gmail.com> | 2022-01-03 11:17:51 -0500 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-01-04 10:38:38 +0100 |
commit | d3c4fdb8ffdc8845c7da54a5580758a33934dc6f (patch) | |
tree | 0994f2aa6334a6f92b12049f25365e6193fe50e5 /hugolib/site_output_test.go | |
parent | d632dd7d74a1b338df97babfc7a1915c0c8814de (diff) |
Fix surprise OutputFormat.Rel overwriting
In page.NewOutputFormat, we take an output.Format f and use it to
create a page.OutputFormat. If the format is canonical, we assign
the final OutputFormat's Rel to "canonical" rather than using
f.Rel. However, this leads to unexpected behavior for custom
output formats, where a user can define a "rel" for a format
via the config file.
For example, the standard for "humans.txt" files requires using
rel="author" in HTML "link" elements. Meanwhile, humans.txt is
usually the only format used for its content. As a result, for
Hugo configurations that define a humans.txt custom output format,
Hugo will render "link" elements to content in this format with
rel="canonical," rather than "author" as required by the standard.
This commit changes page.NewOutputFormat to check whether a given
format is user defined and, if so, skips assigning Rel to
"canonical," even if isCanonical is true.
Fixes #8030
Diffstat (limited to 'hugolib/site_output_test.go')
-rw-r--r-- | hugolib/site_output_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go index f3455f369..815625ff1 100644 --- a/hugolib/site_output_test.go +++ b/hugolib/site_output_test.go @@ -324,6 +324,36 @@ baseName = "customdelimbase" c.Assert(outputs.Get("CUS").RelPermalink(), qt.Equals, "/blog/customdelimbase_del") } +// Issue 8030 +func TestGetOutputFormatRel(t *testing.T) { + b := newTestSitesBuilder(t). + WithSimpleConfigFileAndSettings(map[string]interface{}{ + "outputFormats": map[string]interface{}{ + "humansTXT": map[string]interface{}{ + "name": "HUMANS", + "mediaType": "text/plain", + "baseName": "humans", + "isPlainText": true, + "rel": "author", + }, + }, + }).WithTemplates("index.html", ` +{{- with ($.Site.GetPage "humans").OutputFormats.Get "humans" -}} +<link rel="{{ .Rel }}" type="{{ .MediaType.String }}" href="{{ .Permalink }}"> +{{- end -}} +`).WithContent("humans.md", `--- +outputs: +- HUMANS +--- +This is my content. +`) + + b.Build(BuildCfg{}) + b.AssertFileContent("public/index.html", ` +<link rel="author" type="text/plain" href="/humans.txt"> +`) +} + func TestCreateSiteOutputFormats(t *testing.T) { t.Run("Basic", func(t *testing.T) { c := qt.New(t) |