Fix branch paths when OutputFormat.Path is configured (note)

Fixes #13829

Co-authored-by: Joe Mooring <joe.mooring@veriphor.com>
This commit is contained in:
Bjørn Erik Pedersen
2025-07-05 11:33:52 +02:00
parent 1b4c423667
commit f967212b72
2 changed files with 105 additions and 4 deletions

View File

@@ -145,6 +145,10 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
pb.isUgly = true
}
if d.Type.Path != "" {
pb.Add(d.Type.Path)
}
if d.Type == output.HTTPStatus404HTMLFormat || d.Type == output.SitemapFormat || d.Type == output.RobotsTxtFormat {
pb.noSubResources = true
} else if d.Kind != kinds.KindPage && d.URL == "" && d.Section.Base() != "/" {
@@ -156,10 +160,6 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
needsBase = false
}
if d.Type.Path != "" {
pb.Add(d.Type.Path)
}
if d.Kind != kinds.KindHome && d.URL != "" {
pb.Add(paths.FieldsSlash(d.URL)...)

View File

@@ -14,6 +14,7 @@
package page_test
import (
"strings"
"testing"
"github.com/gohugoio/hugo/hugolib"
@@ -53,3 +54,103 @@ title: p#2
b.AssertFileContentExact("public/index.html", "/|/s1/p%231/|/s2/p%232/|/tags/test%23tag%23/|")
}
func TestOutputFormatWithPathIssue13829(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
uglyURLs = false
[outputFormats.print]
isPlainText = true
mediaType = 'text/plain'
path = 'print'
[outputs]
home = ['html','print']
page = ['html','print']
section = ['html','print']
taxonomy = ['html','print']
term = ['html','print']
[taxonomies]
tag = 'tags'
-- content/_index.md --
---
title: home
---
-- content/s1/_index.md --
---
title: s1
---
-- content/s1/p1.md --
---
title: p1
tags: ['red']
---
-- content/tags/_index.md --
---
title: tags
---
-- content/tags/red/_index.md --
---
title: red
---
`
templates := []string{
"layouts/home.html",
"layouts/home.print.txt",
"layouts/page.html",
"layouts/page.print.txt",
"layouts/section.html",
"layouts/section.print.txt",
"layouts/taxonomy.html",
"layouts/taxonomy.print.txt",
"layouts/term.html",
"layouts/term.print.txt",
}
const code string = "TITLE: {{ .Title }} | AOFRP: {{ range .AlternativeOutputFormats }}{{ .RelPermalink }}{{ end }} | TEMPLATE: {{ templates.Current.Name }}"
for _, template := range templates {
files += "-- " + template + " --\n" + code + "\n"
}
b := hugolib.Test(t, files)
// uglyURLs: false, outputFormat: html
b.AssertFileContent("public/index.html", "TITLE: home | AOFRP: /print/index.txt | TEMPLATE: home.html")
b.AssertFileContent("public/s1/index.html", "TITLE: s1 | AOFRP: /print/s1/index.txt | TEMPLATE: section.html")
b.AssertFileContent("public/s1/p1/index.html", "TITLE: p1 | AOFRP: /print/s1/p1/index.txt | TEMPLATE: page.html")
b.AssertFileContent("public/tags/index.html", "TITLE: tags | AOFRP: /print/tags/index.txt | TEMPLATE: taxonomy.html")
b.AssertFileContent("public/tags/red/index.html", "TITLE: red | AOFRP: /print/tags/red/index.txt | TEMPLATE: term.html")
// uglyURLs: false, outputFormat: print
b.AssertFileContent("public/print/index.txt", "TITLE: home | AOFRP: / | TEMPLATE: home.print.txt")
b.AssertFileContent("public/print/s1/index.txt", "TITLE: s1 | AOFRP: /s1/ | TEMPLATE: section.print.txt")
b.AssertFileContent("public/print/s1/p1/index.txt", "TITLE: p1 | AOFRP: /s1/p1/ | TEMPLATE: page.print.txt")
b.AssertFileContent("public/print/tags/index.txt", "TITLE: tags | AOFRP: /tags/ | TEMPLATE: taxonomy.print.txt")
b.AssertFileContent("public/print/tags/red/index.txt", "TITLE: red | AOFRP: /tags/red/ | TEMPLATE: term.print.txt")
files = strings.ReplaceAll(files, "uglyURLs = false", "uglyURLs = true")
b = hugolib.Test(t, files)
// The assertions below assume that https://github.com/gohugoio/hugo/issues/4428
// and https://github.com/gohugoio/hugo/issues/7497 have been fixed.
// uglyURLs: true, outputFormat: html
/*b.AssertFileContent("public/index.html", "TITLE: home | AOFRP: /print/index.txt | TEMPLATE: home.html")
b.AssertFileContent("public/s1/index.html", "TITLE: s1 | AOFRP: /print/s1/index.txt | TEMPLATE: section.html")
b.AssertFileContent("public/s1/p1.html", "TITLE: p1 | AOFRP: /print/s1/p1.txt | TEMPLATE: page.html")
b.AssertFileContent("public/tags/index.html", "TITLE: tags | AOFRP: /print/tags/index.txt | TEMPLATE: taxonomy.html")
b.AssertFileContent("public/tags/red.html", "TITLE: red | AOFRP: /print/tags/red.txt | TEMPLATE: term.html")
// uglyURLs: true, outputFormat: print
b.AssertFileContent("public/print/index.txt", "TITLE: home | AOFRP: /index.html | TEMPLATE: home.print.txt")
b.AssertFileContent("public/print/s1/index.txt", "TITLE: s1 | AOFRP: /s1/index.html | TEMPLATE: section.print.txt")
b.AssertFileContent("public/print/s1/p1.txt", "TITLE: p1 | AOFRP: /s1/p1.html | TEMPLATE: page.print.txt")
b.AssertFileContent("public/print/tags/index.txt", "TITLE: tags | AOFRP: /tags/index.html | TEMPLATE: taxonomy.print.txt")
b.AssertFileContent("public/print/tags/red.txt", "TITLE: red | AOFRP: /tags/red.html | TEMPLATE: term.print.txt")*/
}