Skip to content

Commit f967212

Browse files
bepjmooring
andcommitted
Fix branch paths when OutputFormat.Path is configured (note)
Fixes #13829 Co-authored-by: Joe Mooring <joe.mooring@veriphor.com>
1 parent 1b4c423 commit f967212

File tree

2 files changed

+105
-4
lines changed

2 files changed

+105
-4
lines changed

‎resources/page/page_paths.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
145145
pb.isUgly = true
146146
}
147147

148+
if d.Type.Path != "" {
149+
pb.Add(d.Type.Path)
150+
}
151+
148152
if d.Type == output.HTTPStatus404HTMLFormat || d.Type == output.SitemapFormat || d.Type == output.RobotsTxtFormat {
149153
pb.noSubResources = true
150154
} else if d.Kind != kinds.KindPage && d.URL == "" && d.Section.Base() != "/" {
@@ -156,10 +160,6 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) {
156160
needsBase = false
157161
}
158162

159-
if d.Type.Path != "" {
160-
pb.Add(d.Type.Path)
161-
}
162-
163163
if d.Kind != kinds.KindHome && d.URL != "" {
164164
pb.Add(paths.FieldsSlash(d.URL)...)
165165

‎resources/page/path_integration_test.go‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package page_test
1515

1616
import (
17+
"strings"
1718
"testing"
1819

1920
"github.com/gohugoio/hugo/hugolib"
@@ -53,3 +54,103 @@ title: p#2
5354

5455
b.AssertFileContentExact("public/index.html", "/|/s1/p%231/|/s2/p%232/|/tags/test%23tag%23/|")
5556
}
57+
58+
func TestOutputFormatWithPathIssue13829(t *testing.T) {
59+
t.Parallel()
60+
61+
files := `
62+
-- hugo.toml --
63+
uglyURLs = false
64+
65+
[outputFormats.print]
66+
isPlainText = true
67+
mediaType = 'text/plain'
68+
path = 'print'
69+
70+
[outputs]
71+
home = ['html','print']
72+
page = ['html','print']
73+
section = ['html','print']
74+
taxonomy = ['html','print']
75+
term = ['html','print']
76+
77+
[taxonomies]
78+
tag = 'tags'
79+
-- content/_index.md --
80+
---
81+
title: home
82+
---
83+
-- content/s1/_index.md --
84+
---
85+
title: s1
86+
---
87+
-- content/s1/p1.md --
88+
---
89+
title: p1
90+
tags: ['red']
91+
---
92+
-- content/tags/_index.md --
93+
---
94+
title: tags
95+
---
96+
-- content/tags/red/_index.md --
97+
---
98+
title: red
99+
---
100+
`
101+
102+
templates := []string{
103+
"layouts/home.html",
104+
"layouts/home.print.txt",
105+
"layouts/page.html",
106+
"layouts/page.print.txt",
107+
"layouts/section.html",
108+
"layouts/section.print.txt",
109+
"layouts/taxonomy.html",
110+
"layouts/taxonomy.print.txt",
111+
"layouts/term.html",
112+
"layouts/term.print.txt",
113+
}
114+
115+
const code string = "TITLE: {{ .Title }} | AOFRP: {{ range .AlternativeOutputFormats }}{{ .RelPermalink }}{{ end }} | TEMPLATE: {{ templates.Current.Name }}"
116+
117+
for _, template := range templates {
118+
files += "-- " + template + " --\n" + code + "\n"
119+
}
120+
121+
b := hugolib.Test(t, files)
122+
123+
// uglyURLs: false, outputFormat: html
124+
b.AssertFileContent("public/index.html", "TITLE: home | AOFRP: /print/index.txt | TEMPLATE: home.html")
125+
b.AssertFileContent("public/s1/index.html", "TITLE: s1 | AOFRP: /print/s1/index.txt | TEMPLATE: section.html")
126+
b.AssertFileContent("public/s1/p1/index.html", "TITLE: p1 | AOFRP: /print/s1/p1/index.txt | TEMPLATE: page.html")
127+
b.AssertFileContent("public/tags/index.html", "TITLE: tags | AOFRP: /print/tags/index.txt | TEMPLATE: taxonomy.html")
128+
b.AssertFileContent("public/tags/red/index.html", "TITLE: red | AOFRP: /print/tags/red/index.txt | TEMPLATE: term.html")
129+
130+
// uglyURLs: false, outputFormat: print
131+
b.AssertFileContent("public/print/index.txt", "TITLE: home | AOFRP: / | TEMPLATE: home.print.txt")
132+
b.AssertFileContent("public/print/s1/index.txt", "TITLE: s1 | AOFRP: /s1/ | TEMPLATE: section.print.txt")
133+
b.AssertFileContent("public/print/s1/p1/index.txt", "TITLE: p1 | AOFRP: /s1/p1/ | TEMPLATE: page.print.txt")
134+
b.AssertFileContent("public/print/tags/index.txt", "TITLE: tags | AOFRP: /tags/ | TEMPLATE: taxonomy.print.txt")
135+
b.AssertFileContent("public/print/tags/red/index.txt", "TITLE: red | AOFRP: /tags/red/ | TEMPLATE: term.print.txt")
136+
137+
files = strings.ReplaceAll(files, "uglyURLs = false", "uglyURLs = true")
138+
b = hugolib.Test(t, files)
139+
140+
// The assertions below assume that https://github.com/gohugoio/hugo/issues/4428
141+
// and https://github.com/gohugoio/hugo/issues/7497 have been fixed.
142+
143+
// uglyURLs: true, outputFormat: html
144+
/*b.AssertFileContent("public/index.html", "TITLE: home | AOFRP: /print/index.txt | TEMPLATE: home.html")
145+
b.AssertFileContent("public/s1/index.html", "TITLE: s1 | AOFRP: /print/s1/index.txt | TEMPLATE: section.html")
146+
b.AssertFileContent("public/s1/p1.html", "TITLE: p1 | AOFRP: /print/s1/p1.txt | TEMPLATE: page.html")
147+
b.AssertFileContent("public/tags/index.html", "TITLE: tags | AOFRP: /print/tags/index.txt | TEMPLATE: taxonomy.html")
148+
b.AssertFileContent("public/tags/red.html", "TITLE: red | AOFRP: /print/tags/red.txt | TEMPLATE: term.html")
149+
150+
// uglyURLs: true, outputFormat: print
151+
b.AssertFileContent("public/print/index.txt", "TITLE: home | AOFRP: /index.html | TEMPLATE: home.print.txt")
152+
b.AssertFileContent("public/print/s1/index.txt", "TITLE: s1 | AOFRP: /s1/index.html | TEMPLATE: section.print.txt")
153+
b.AssertFileContent("public/print/s1/p1.txt", "TITLE: p1 | AOFRP: /s1/p1.html | TEMPLATE: page.print.txt")
154+
b.AssertFileContent("public/print/tags/index.txt", "TITLE: tags | AOFRP: /tags/index.html | TEMPLATE: taxonomy.print.txt")
155+
b.AssertFileContent("public/print/tags/red.txt", "TITLE: red | AOFRP: /tags/red.html | TEMPLATE: term.print.txt")*/
156+
}

0 commit comments

Comments
 (0)