Skip to content

Commit 492e3c6

Browse files
only add trailing slash to url path if not already
1 parent 78e3709 commit 492e3c6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

gozer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func parseFilename(path string, rootDir string) (string, time.Time) {
6767
}
6868
}
6969

70-
if path != "" {
70+
if path != "" && path[len(path)-1] != '/' {
7171
path += "/"
7272
}
7373

gozer_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ func TestExampleSite(t *testing.T) {
2828
[]byte("This is a blog post.")},
2929
},
3030
{"favicon.ico", nil},
31-
{"feed.xml", nil},
32-
{"sitemap.xml", [][]byte{[]byte("<url><loc>http://localhost:8080/</loc>")}},
31+
{"feed.xml", [][]byte{
32+
[]byte("<item><title>Hello, world!</title><link>http://localhost:8080/hello-world/</link>"),
33+
}},
34+
{"sitemap.xml", [][]byte{
35+
[]byte("<url><loc>http://localhost:8080/</loc>"),
36+
}},
3337
{"sitemap.xsl", nil},
3438
}
3539

@@ -103,6 +107,7 @@ func TestFilepathToUrlpath(t *testing.T) {
103107
}{
104108
{input: "content/index.md", expectedUrlPath: "", expectedDatePublished: time.Time{}},
105109
{input: "content/about.md", expectedUrlPath: "about/", expectedDatePublished: time.Time{}},
110+
{input: "content/blog/index.md", expectedUrlPath: "blog/", expectedDatePublished: time.Time{}},
106111
{input: "content/projects/gozer.md", expectedUrlPath: "projects/gozer/", expectedDatePublished: time.Time{}},
107112
{input: "content/2023-11-23-hello-world.md", expectedUrlPath: "hello-world/", expectedDatePublished: time.Date(2023, 11, 23, 0, 0, 0, 0, time.UTC)},
108113
{input: "content/blog/2023-11-23-here-we-are.md", expectedUrlPath: "blog/here-we-are/", expectedDatePublished: time.Date(2023, 11, 23, 0, 0, 0, 0, time.UTC)},

0 commit comments

Comments
 (0)