| 1 |
// Copyright 2024 The Hugo Authors. All rights reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package page_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"strings" |
| 18 |
"testing" |
| 19 |
|
| 20 |
"github.com/gohugoio/hugo/hugolib" |
| 21 |
) |
| 22 |
|
| 23 |
// Issue 4926 |
| 24 |
// Issue 8232 |
| 25 |
// Issue 12342 |
| 26 |
func TestHashSignInPermalink(t *testing.T) { |
| 27 |
t.Parallel() |
| 28 |
|
| 29 |
files := ` |
| 30 |
-- hugo.toml -- |
| 31 |
disableKinds = ['section','rss','sitemap','taxonomy'] |
| 32 |
[permalinks] |
| 33 |
s1 = '/:section/:slug' |
| 34 |
-- layouts/list.html -- |
| 35 |
{{ range site.Pages }}{{ .RelPermalink }}|{{ end }} |
| 36 |
-- layouts/single.html -- |
| 37 |
{{ .Title }} |
| 38 |
-- content/s1/p1.md -- |
| 39 |
--- |
| 40 |
title: p#1 |
| 41 |
tags: test#tag# |
| 42 |
--- |
| 43 |
-- content/s2/p#2.md -- |
| 44 |
--- |
| 45 |
title: p#2 |
| 46 |
--- |
| 47 |
` |
| 48 |
|
| 49 |
b := hugolib.Test(t, files) |
| 50 |
|
| 51 |
b.AssertFileExists("public/s1/p#1/index.html", true) |
| 52 |
b.AssertFileExists("public/s2/p#2/index.html", true) |
| 53 |
b.AssertFileExists("public/tags/test#tag#/index.html", true) |
| 54 |
|
| 55 |
b.AssertFileContentExact("public/index.html", "/|/s1/p%231/|/s2/p%232/|/tags/test%23tag%23/|") |
| 56 |
} |
| 57 |
|
| 58 |
// Issues: 13829, 4428, 7497. |
| 59 |
func TestMiscPathIssues(t *testing.T) { |
| 60 |
t.Parallel() |
| 61 |
|
| 62 |
var filesTemplate strings.Builder |
| 63 |
filesTemplate.WriteString(` |
| 64 |
-- hugo.toml -- |
| 65 |
uglyURLs = false |
| 66 |
|
| 67 |
[outputFormats.print] |
| 68 |
isPlainText = true |
| 69 |
mediaType = 'text/plain' |
| 70 |
path = 'print' |
| 71 |
|
| 72 |
[outputs] |
| 73 |
home = ['html','print'] |
| 74 |
page = ['html','print'] |
| 75 |
section = ['html','print'] |
| 76 |
taxonomy = ['html','print'] |
| 77 |
term = ['html','print'] |
| 78 |
|
| 79 |
[taxonomies] |
| 80 |
tag = 'tags' |
| 81 |
-- content/_index.md -- |
| 82 |
--- |
| 83 |
title: home |
| 84 |
--- |
| 85 |
-- content/s1/_index.md -- |
| 86 |
--- |
| 87 |
title: s1 |
| 88 |
--- |
| 89 |
-- content/s1/p1.md -- |
| 90 |
--- |
| 91 |
title: p1 |
| 92 |
tags: ['red'] |
| 93 |
--- |
| 94 |
-- content/tags/_index.md -- |
| 95 |
--- |
| 96 |
title: tags |
| 97 |
--- |
| 98 |
-- content/tags/red/_index.md -- |
| 99 |
--- |
| 100 |
title: red |
| 101 |
--- |
| 102 |
`) |
| 103 |
|
| 104 |
templates := []string{ |
| 105 |
"layouts/home.html", |
| 106 |
"layouts/home.print.txt", |
| 107 |
"layouts/page.html", |
| 108 |
"layouts/page.print.txt", |
| 109 |
"layouts/section.html", |
| 110 |
"layouts/section.print.txt", |
| 111 |
"layouts/taxonomy.html", |
| 112 |
"layouts/taxonomy.print.txt", |
| 113 |
"layouts/term.html", |
| 114 |
"layouts/term.print.txt", |
| 115 |
} |
| 116 |
|
| 117 |
const code string = "TITLE: {{ .Title }} | AOFRP: {{ range .AlternativeOutputFormats }}{{ .RelPermalink }}{{ end }} | TEMPLATE: {{ templates.Current.Name }}" |
| 118 |
|
| 119 |
for _, template := range templates { |
| 120 |
filesTemplate.WriteString("-- " + template + " --\n" + code + "\n") |
| 121 |
} |
| 122 |
|
| 123 |
files := filesTemplate.String() |
| 124 |
|
| 125 |
b := hugolib.Test(t, files) |
| 126 |
|
| 127 |
// uglyURLs: false, outputFormat: html |
| 128 |
b.AssertFileContent("public/index.html", "TITLE: home | AOFRP: /print/index.txt | TEMPLATE: home.html") |
| 129 |
b.AssertFileContent("public/s1/index.html", "TITLE: s1 | AOFRP: /print/s1/index.txt | TEMPLATE: section.html") |
| 130 |
b.AssertFileContent("public/s1/p1/index.html", "TITLE: p1 | AOFRP: /print/s1/p1/index.txt | TEMPLATE: page.html") |
| 131 |
b.AssertFileContent("public/tags/index.html", "TITLE: tags | AOFRP: /print/tags/index.txt | TEMPLATE: taxonomy.html") |
| 132 |
b.AssertFileContent("public/tags/red/index.html", "TITLE: red | AOFRP: /print/tags/red/index.txt | TEMPLATE: term.html") |
| 133 |
|
| 134 |
// uglyURLs: false, outputFormat: print |
| 135 |
b.AssertFileContent("public/print/index.txt", "TITLE: home | AOFRP: / | TEMPLATE: home.print.txt") |
| 136 |
b.AssertFileContent("public/print/s1/index.txt", "TITLE: s1 | AOFRP: /s1/ | TEMPLATE: section.print.txt") |
| 137 |
b.AssertFileContent("public/print/s1/p1/index.txt", "TITLE: p1 | AOFRP: /s1/p1/ | TEMPLATE: page.print.txt") |
| 138 |
b.AssertFileContent("public/print/tags/index.txt", "TITLE: tags | AOFRP: /tags/ | TEMPLATE: taxonomy.print.txt") |
| 139 |
b.AssertFileContent("public/print/tags/red/index.txt", "TITLE: red | AOFRP: /tags/red/ | TEMPLATE: term.print.txt") |
| 140 |
|
| 141 |
files = strings.ReplaceAll(filesTemplate.String(), "uglyURLs = false", "uglyURLs = true") |
| 142 |
b = hugolib.Test(t, files) |
| 143 |
|
| 144 |
// uglyURLs: true, outputFormat: html |
| 145 |
b.AssertFileContent("public/index.html", "TITLE: home | AOFRP: /print/index.txt | TEMPLATE: home.html") |
| 146 |
b.AssertFileContent("public/s1/index.html", "TITLE: s1 | AOFRP: /print/s1/index.txt | TEMPLATE: section.html") |
| 147 |
b.AssertFileContent("public/s1/p1.html", "TITLE: p1 | AOFRP: /print/s1/p1.txt | TEMPLATE: page.html") |
| 148 |
b.AssertFileContent("public/tags/index.html", "TITLE: tags | AOFRP: /print/tags/index.txt | TEMPLATE: taxonomy.html") |
| 149 |
b.AssertFileContent("public/tags/red.html", "TITLE: red | AOFRP: /print/tags/red.txt | TEMPLATE: term.html") |
| 150 |
|
| 151 |
// uglyURLs: true, outputFormat: print |
| 152 |
b.AssertFileContent("public/print/index.txt", "TITLE: home | AOFRP: /index.html | TEMPLATE: home.print.txt") |
| 153 |
b.AssertFileContent("public/print/s1/index.txt", "TITLE: s1 | AOFRP: /s1/index.html | TEMPLATE: section.print.txt") |
| 154 |
b.AssertFileContent("public/print/s1/p1.txt", "TITLE: p1 | AOFRP: /s1/p1.html | TEMPLATE: page.print.txt") |
| 155 |
b.AssertFileContent("public/print/tags/index.txt", "TITLE: tags | AOFRP: /tags/index.html | TEMPLATE: taxonomy.print.txt") |
| 156 |
b.AssertFileContent("public/print/tags/red.txt", "TITLE: red | AOFRP: /tags/red.html | TEMPLATE: term.print.txt") |
| 157 |
} |