|
14 | 14 | package page_test |
15 | 15 |
|
16 | 16 | import ( |
| 17 | + "strings" |
17 | 18 | "testing" |
18 | 19 |
|
19 | 20 | "github.com/gohugoio/hugo/hugolib" |
@@ -53,3 +54,103 @@ title: p#2 |
53 | 54 |
|
54 | 55 | b.AssertFileContentExact("public/index.html", "/|/s1/p%231/|/s2/p%232/|/tags/test%23tag%23/|") |
55 | 56 | } |
| 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