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

OutputFormats via GetPage ignores custom Rel #8030

Closed
toby3d opened this issue Dec 6, 2020 · 1 comment · Fixed by #9345
Closed

OutputFormats via GetPage ignores custom Rel #8030

toby3d opened this issue Dec 6, 2020 · 1 comment · Fixed by #9345

Comments

@toby3d
Copy link

toby3d commented Dec 6, 2020

.OutputFormats obtained through .Site.GetPage completely ignores the Rel value.

Example

Part of config.yaml config:

outputFormats:
  humansTXT:
    name: HUMANS
    mediaType: text/plain
    baseName: humans
    isPlainText: true
    rel: author

<head>...</head> part of layouts/_default/baseof.html template:

<!-- Get 'content/humans.md' with 'outputs: [ HUMANS ]' param -->
{{ with ($.Site.GetPage "humans").OutputFormats.Get "humans" }}
  <link rel="{{ .Rel }}" type="{{ .MediaType.String }}" href="{{ .Permalink }}">
{{ end }}

What did I expect

<link rel="author" type="text/plain" href="http://localhost:1313/humans.txt">

What did I get

<link rel="canonical" type="text/plain" href="http://localhost:1313/humans.txt">

Debug

Here is the content of the structure inside the block:

&page.OutputFormat{Rel:"canonical", Format:output.Format{Name:"HUMANS", MediaType:media.Type{MainType:"text", SubType:"plain", mimeSuffix:"", Delimiter:".", Suffixes:[]string{"txt"}, fileSuffix:""}, Path:"", BaseName:"humans", Rel:"author", Protocol:"", IsPlainText:true, IsHTML:false, NoUgly:false, NotAlternative:false, Permalinkable:false, Weight:0}, relPermalink:"/humans.txt", permalink:"http://localhost:1313/humans.txt"}

So, root .Rel is "canonical", but .Format.Rel is valid "author".

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

) hugo version
Hugo Static Site Generator v0.79.0/extended linux/amd64 BuildDate: unknown

Does this issue reproduce with the latest release?

Yes

ptgott added a commit to ptgott/hugo that referenced this issue Jan 3, 2022
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 gohugoio#8030
@bep bep closed this as completed in #9345 Jan 4, 2022
bep pushed a commit that referenced this issue Jan 4, 2022
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
@github-actions
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 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant