mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-21 03:13:53 +00:00
Fix links for non-HTML output formats
They were not correct for regular pages. Fixes #5877
This commit is contained in:
parent
7aeeb60d7e
commit
c7dd66bfe2
2 changed files with 58 additions and 33 deletions
|
@ -419,6 +419,8 @@ func TestOutputFormatPermalinkable(t *testing.T) {
|
||||||
config := `
|
config := `
|
||||||
baseURL = "https://example.com"
|
baseURL = "https://example.com"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# DAMP is similar to AMP, but not permalinkable.
|
# DAMP is similar to AMP, but not permalinkable.
|
||||||
[outputFormats]
|
[outputFormats]
|
||||||
[outputFormats.damp]
|
[outputFormats.damp]
|
||||||
|
@ -428,6 +430,14 @@ path = "damp"
|
||||||
mediaType = "text/html"
|
mediaType = "text/html"
|
||||||
path = "ramp"
|
path = "ramp"
|
||||||
permalinkable = true
|
permalinkable = true
|
||||||
|
[outputFormats.base]
|
||||||
|
mediaType = "text/html"
|
||||||
|
isHTML = true
|
||||||
|
baseName = "that"
|
||||||
|
permalinkable = true
|
||||||
|
[outputFormats.nobase]
|
||||||
|
mediaType = "application/json"
|
||||||
|
permalinkable = true
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -435,7 +445,7 @@ permalinkable = true
|
||||||
b.WithContent("_index.md", `
|
b.WithContent("_index.md", `
|
||||||
---
|
---
|
||||||
Title: Home Sweet Home
|
Title: Home Sweet Home
|
||||||
outputs: [ "html", "amp", "damp" ]
|
outputs: [ "html", "amp", "damp", "base" ]
|
||||||
---
|
---
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
@ -480,58 +490,73 @@ outputs: [ "amp" ]
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
|
||||||
b.WithTemplatesAdded("index.html", `
|
b.WithContent("blog/html-base-nobase.md", `
|
||||||
This RelPermalink: {{ .RelPermalink }}
|
---
|
||||||
Regular Pages: {{ range .Site.RegularPages }}{{ .Title }}|{{ .RelPermalink }}|{{ end }}
|
Title: HTML, Base and Nobase
|
||||||
Get AMP: {{ with .OutputFormats.Get "AMP" }}{{ .Permalink }}{{ end }}
|
outputs: [ "html", "base", "nobase" ]
|
||||||
Get HTML: {{ with .OutputFormats.Get "HTML" }}{{ .Permalink }}{{ end }}
|
---
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
|
||||||
b.WithTemplatesAdded("_default/single.html", `
|
const commonTemplate = `
|
||||||
This RelPermalink: {{ .RelPermalink }}
|
This RelPermalink: {{ .RelPermalink }}
|
||||||
Get AMP: {{ with .OutputFormats.Get "AMP" }}{{ .Permalink }}{{ end }}
|
Output Formats: {{ len .OutputFormats }};{{ range .OutputFormats }}{{ .Name }};{{ .RelPermalink }}|{{ end }}
|
||||||
Get HTML: {{ with .OutputFormats.Get "HTML" }}{{ .Permalink }}{{ end }}
|
|
||||||
Get DAMP: {{ with .OutputFormats.Get "DAMP" }}{{ .Permalink }}{{ end }}
|
`
|
||||||
Get RAMP: {{ with .OutputFormats.Get "RAMP" }}{{ .Permalink }}{{ end }}
|
|
||||||
`)
|
b.WithTemplatesAdded("index.html", commonTemplate)
|
||||||
|
b.WithTemplatesAdded("_default/single.html", commonTemplate)
|
||||||
|
b.WithTemplatesAdded("_default/single.json", commonTemplate)
|
||||||
|
|
||||||
b.Build(BuildCfg{})
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
htmlHomeOutput := "Regular Pages: AMP and HTML|/blog/html-amp/|AMP only|/amp/blog/amp/|DAMP and HTML|/blog/html-damp/|HTML only|/blog/html/|"
|
b.AssertFileContent("public/index.html",
|
||||||
|
|
||||||
b.AssertFileContent("public/index.html", htmlHomeOutput,
|
|
||||||
"This RelPermalink: /",
|
"This RelPermalink: /",
|
||||||
"Get AMP: https://example.com/amp/",
|
"Output Formats: 4;HTML;/|AMP;/amp/|damp;/damp/|base;/that.html|",
|
||||||
"Get HTML: https://example.com/")
|
)
|
||||||
|
|
||||||
b.AssertFileContent("public/amp/index.html",
|
b.AssertFileContent("public/amp/index.html",
|
||||||
"Regular Pages: AMP and HTML|/amp/blog/html-amp/|AMP only|/amp/blog/amp/|DAMP and HTML|/blog/html-damp/|HTML only|/blog/html/|")
|
"This RelPermalink: /amp/",
|
||||||
b.AssertFileContent("public/damp/index.html", htmlHomeOutput)
|
"Output Formats: 4;HTML;/|AMP;/amp/|damp;/damp/|base;/that.html|",
|
||||||
|
)
|
||||||
|
|
||||||
// https://github.com/gohugoio/hugo/issues/5877
|
|
||||||
b.AssertFileContent("public/blog/html-amp/index.html",
|
b.AssertFileContent("public/blog/html-amp/index.html",
|
||||||
"This RelPermalink: /blog/html-amp/",
|
"Output Formats: 2;HTML;/blog/html-amp/|AMP;/amp/blog/html-amp/|",
|
||||||
"Get AMP: https://example.com/amp/blog/html-amp/",
|
"This RelPermalink: /blog/html-amp/")
|
||||||
"Get HTML: https://example.com/blog/html-amp/")
|
|
||||||
|
|
||||||
b.AssertFileContent("public/amp/blog/html-amp/index.html",
|
b.AssertFileContent("public/amp/blog/html-amp/index.html",
|
||||||
"This RelPermalink: /amp/blog/html-amp/",
|
"Output Formats: 2;HTML;/blog/html-amp/|AMP;/amp/blog/html-amp/|",
|
||||||
"Get AMP: https://example.com/amp/blog/html-amp/",
|
"This RelPermalink: /amp/blog/html-amp/")
|
||||||
"Get HTML: https://example.com/blog/html-amp/")
|
|
||||||
|
|
||||||
|
// Damp is not permalinkable
|
||||||
b.AssertFileContent("public/damp/blog/html-damp/index.html",
|
b.AssertFileContent("public/damp/blog/html-damp/index.html",
|
||||||
"This RelPermalink: /blog/html-damp/",
|
"This RelPermalink: /blog/html-damp/",
|
||||||
"Get HTML: https://example.com/blog/html-damp/",
|
"Output Formats: 2;HTML;/blog/html-damp/|damp;/damp/blog/html-damp/|")
|
||||||
"Get DAMP: https://example.com/damp/blog/html-damp/")
|
|
||||||
|
|
||||||
b.AssertFileContent("public/blog/html-ramp/index.html",
|
b.AssertFileContent("public/blog/html-ramp/index.html",
|
||||||
"This RelPermalink: /blog/html-ramp/",
|
"This RelPermalink: /blog/html-ramp/",
|
||||||
"Get HTML: https://example.com/blog/html-ramp/",
|
"Output Formats: 2;HTML;/blog/html-ramp/|ramp;/ramp/blog/html-ramp/|")
|
||||||
"Get RAMP: https://example.com/ramp/blog/html-ramp/")
|
|
||||||
|
|
||||||
b.AssertFileContent("public/ramp/blog/html-ramp/index.html",
|
b.AssertFileContent("public/ramp/blog/html-ramp/index.html",
|
||||||
"This RelPermalink: /ramp/blog/html-ramp/",
|
"This RelPermalink: /ramp/blog/html-ramp/",
|
||||||
"Get HTML: https://example.com/blog/html-ramp/",
|
"Output Formats: 2;HTML;/blog/html-ramp/|ramp;/ramp/blog/html-ramp/|")
|
||||||
"Get RAMP: https://example.com/ramp/blog/html-ramp/")
|
|
||||||
|
// https://github.com/gohugoio/hugo/issues/5877
|
||||||
|
outputFormats := "Output Formats: 3;HTML;/blog/html-base-nobase/|base;/blog/html-base-nobase/that.html|nobase;/blog/html-base-nobase/index.json|"
|
||||||
|
|
||||||
|
b.AssertFileContent("public/blog/html-base-nobase/index.json",
|
||||||
|
"This RelPermalink: /blog/html-base-nobase/index.json",
|
||||||
|
outputFormats,
|
||||||
|
)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/blog/html-base-nobase/that.html",
|
||||||
|
"This RelPermalink: /blog/html-base-nobase/that.html",
|
||||||
|
outputFormats,
|
||||||
|
)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/blog/html-base-nobase/index.html",
|
||||||
|
"This RelPermalink: /blog/html-base-nobase/",
|
||||||
|
outputFormats,
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,7 +235,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
|
||||||
pagePath = pjoin(pagePath, d.Type.BaseName+d.Type.MediaType.FullSuffix())
|
pagePath = pjoin(pagePath, d.Type.BaseName+d.Type.MediaType.FullSuffix())
|
||||||
}
|
}
|
||||||
|
|
||||||
if isUgly && !isHtmlIndex(pagePath) {
|
if !isHtmlIndex(pagePath) {
|
||||||
link = pagePath
|
link = pagePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue