summaryrefslogtreecommitdiffstats
path: root/resources/page/page_outputformat.go
diff options
context:
space:
mode:
authorPaul Gottschling <paul.gottschling@gmail.com>2022-01-03 11:17:51 -0500
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-01-04 10:38:38 +0100
commitd3c4fdb8ffdc8845c7da54a5580758a33934dc6f (patch)
tree0994f2aa6334a6f92b12049f25365e6193fe50e5 /resources/page/page_outputformat.go
parentd632dd7d74a1b338df97babfc7a1915c0c8814de (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 'resources/page/page_outputformat.go')
-rw-r--r--resources/page/page_outputformat.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/resources/page/page_outputformat.go b/resources/page/page_outputformat.go
index 9eed8241e..44f290025 100644
--- a/resources/page/page_outputformat.go
+++ b/resources/page/page_outputformat.go
@@ -66,8 +66,18 @@ func (o OutputFormat) RelPermalink() string {
}
func NewOutputFormat(relPermalink, permalink string, isCanonical bool, f output.Format) OutputFormat {
+ isUserConfigured := true
+ for _, d := range output.DefaultFormats {
+ if strings.EqualFold(d.Name, f.Name) {
+ isUserConfigured = false
+ }
+ }
rel := f.Rel
- if isCanonical {
+ // If the output format is the canonical format for the content, we want
+ // to specify this in the "rel" attribute of an HTML "link" element.
+ // However, for custom output formats, we don't want to surprise users by
+ // overwriting "rel"
+ if isCanonical && !isUserConfigured {
rel = "canonical"
}
return OutputFormat{Rel: rel, Format: f, relPermalink: relPermalink, permalink: permalink}