mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
1f55cb767d
commit
5be0448635
2 changed files with 67 additions and 47 deletions
|
@ -85,7 +85,7 @@ func (p *Page) initTargetPathDescriptor() error {
|
||||||
Kind: p.Kind,
|
Kind: p.Kind,
|
||||||
Sections: p.sections,
|
Sections: p.sections,
|
||||||
UglyURLs: p.s.Info.uglyURLs,
|
UglyURLs: p.s.Info.uglyURLs,
|
||||||
Dir: filepath.ToSlash(strings.ToLower(p.Source.Dir())),
|
Dir: filepath.ToSlash(p.Source.Dir()),
|
||||||
URL: p.URLPath.URL,
|
URL: p.URLPath.URL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1417,70 +1417,90 @@ func TestShouldBuild(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue #1885 and #2110
|
// "dot" in path: #1885 and #2110
|
||||||
func TestDotInPath(t *testing.T) {
|
// disablePathToLower regression: #3374
|
||||||
|
func TestPathIssues(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
for _, disablePathToLower := range []bool{false, true} {
|
||||||
|
for _, uglyURLs := range []bool{false, true} {
|
||||||
|
t.Run(fmt.Sprintf("disablePathToLower=%t,uglyURLs=%t", disablePathToLower, uglyURLs), func(t *testing.T) {
|
||||||
|
|
||||||
for _, uglyURLs := range []bool{false, true} {
|
cfg, fs := newTestCfg()
|
||||||
t.Run(fmt.Sprintf("uglyURLs=%t", uglyURLs), func(t *testing.T) {
|
th := testHelper{cfg, fs, t}
|
||||||
|
|
||||||
cfg, fs := newTestCfg()
|
cfg.Set("permalinks", map[string]string{
|
||||||
th := testHelper{cfg, fs, t}
|
"post": ":section/:title",
|
||||||
|
})
|
||||||
|
|
||||||
cfg.Set("permalinks", map[string]string{
|
cfg.Set("uglyURLs", uglyURLs)
|
||||||
"post": ":section/:title",
|
cfg.Set("disablePathToLower", disablePathToLower)
|
||||||
})
|
cfg.Set("paginate", 1)
|
||||||
|
|
||||||
cfg.Set("uglyURLs", uglyURLs)
|
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), "<html><body>{{.Content}}</body></html>")
|
||||||
cfg.Set("paginate", 1)
|
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
|
||||||
|
"<html><body>P{{.Paginator.PageNumber}}|URL: {{.Paginator.URL}}|{{ if .Paginator.HasNext }}Next: {{.Paginator.Next.URL }}{{ end }}</body></html>")
|
||||||
|
|
||||||
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), "<html><body>{{.Content}}</body></html>")
|
for i := 0; i < 3; i++ {
|
||||||
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
|
writeSource(t, fs, filepath.Join("content", "post", fmt.Sprintf("doc%d.md", i)),
|
||||||
"<html><body>P{{.Paginator.PageNumber}}|URL: {{.Paginator.URL}}|{{ if .Paginator.HasNext }}Next: {{.Paginator.Next.URL }}{{ end }}</body></html>")
|
fmt.Sprintf(`---
|
||||||
|
|
||||||
for i := 0; i < 3; i++ {
|
|
||||||
writeSource(t, fs, filepath.Join("content", "post", fmt.Sprintf("doc%d.md", i)),
|
|
||||||
fmt.Sprintf(`---
|
|
||||||
title: "test%d.dot"
|
title: "test%d.dot"
|
||||||
tags:
|
tags:
|
||||||
- ".net"
|
- ".net"
|
||||||
---
|
---
|
||||||
# doc1
|
# doc1
|
||||||
*some content*`, i))
|
*some content*`, i))
|
||||||
}
|
|
||||||
|
|
||||||
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
|
||||||
require.Len(t, s.RegularPages, 3)
|
|
||||||
|
|
||||||
pathFunc := func(s string) string {
|
|
||||||
if uglyURLs {
|
|
||||||
return strings.Replace(s, "/index.html", ".html", 1)
|
|
||||||
}
|
}
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
th.assertFileContent(pathFunc("public/post/test0.dot/index.html"), "some content")
|
writeSource(t, fs, filepath.Join("content", "Blog", "Blog1.md"),
|
||||||
|
fmt.Sprintf(`---
|
||||||
|
title: "testBlog"
|
||||||
|
tags:
|
||||||
|
- "Blog"
|
||||||
|
---
|
||||||
|
# doc1
|
||||||
|
*some blog content*`))
|
||||||
|
|
||||||
if uglyURLs {
|
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
||||||
th.assertFileContent("public/post/page/1.html", `canonical" href="/post.html"/`)
|
require.Len(t, s.RegularPages, 4)
|
||||||
th.assertFileContent("public/post.html", `<body>P1|URL: /post.html|Next: /post/page/2.html</body>`)
|
|
||||||
th.assertFileContent("public/post/page/2.html", `<body>P2|URL: /post/page/2.html|Next: /post/page/3.html</body>`)
|
|
||||||
} else {
|
|
||||||
th.assertFileContent("public/post/page/1/index.html", `canonical" href="/post/"/`)
|
|
||||||
th.assertFileContent("public/post/index.html", `<body>P1|URL: /post/|Next: /post/page/2/</body>`)
|
|
||||||
th.assertFileContent("public/post/page/2/index.html", `<body>P2|URL: /post/page/2/|Next: /post/page/3/</body>`)
|
|
||||||
th.assertFileContent("public/tags/.net/index.html", `<body>P1|URL: /tags/.net/|Next: /tags/.net/page/2/</body>`)
|
|
||||||
|
|
||||||
}
|
pathFunc := func(s string) string {
|
||||||
|
if uglyURLs {
|
||||||
|
return strings.Replace(s, "/index.html", ".html", 1)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
p := s.RegularPages[0]
|
blog := "blog"
|
||||||
if uglyURLs {
|
|
||||||
require.Equal(t, "/post/test0.dot.html", p.RelPermalink())
|
|
||||||
} else {
|
|
||||||
require.Equal(t, "/post/test0.dot/", p.RelPermalink())
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
if disablePathToLower {
|
||||||
|
blog = "Blog"
|
||||||
|
}
|
||||||
|
|
||||||
|
th.assertFileContent(pathFunc("public/"+blog+"/"+blog+"1/index.html"), "some blog content")
|
||||||
|
|
||||||
|
th.assertFileContent(pathFunc("public/post/test0.dot/index.html"), "some content")
|
||||||
|
|
||||||
|
if uglyURLs {
|
||||||
|
th.assertFileContent("public/post/page/1.html", `canonical" href="/post.html"/`)
|
||||||
|
th.assertFileContent("public/post.html", `<body>P1|URL: /post.html|Next: /post/page/2.html</body>`)
|
||||||
|
th.assertFileContent("public/post/page/2.html", `<body>P2|URL: /post/page/2.html|Next: /post/page/3.html</body>`)
|
||||||
|
} else {
|
||||||
|
th.assertFileContent("public/post/page/1/index.html", `canonical" href="/post/"/`)
|
||||||
|
th.assertFileContent("public/post/index.html", `<body>P1|URL: /post/|Next: /post/page/2/</body>`)
|
||||||
|
th.assertFileContent("public/post/page/2/index.html", `<body>P2|URL: /post/page/2/|Next: /post/page/3/</body>`)
|
||||||
|
th.assertFileContent("public/tags/.net/index.html", `<body>P1|URL: /tags/.net/|Next: /tags/.net/page/2/</body>`)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
p := s.RegularPages[0]
|
||||||
|
if uglyURLs {
|
||||||
|
require.Equal(t, "/post/test0.dot.html", p.RelPermalink())
|
||||||
|
} else {
|
||||||
|
require.Equal(t, "/post/test0.dot/", p.RelPermalink())
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue