Skip to content

Commit

Permalink
only add trailing slash to url path if not already
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Nov 24, 2023
1 parent 78e3709 commit 492e3c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gozer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func parseFilename(path string, rootDir string) (string, time.Time) {
}
}

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

Expand Down
9 changes: 7 additions & 2 deletions gozer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ func TestExampleSite(t *testing.T) {
[]byte("This is a blog post.")},
},
{"favicon.ico", nil},
{"feed.xml", nil},
{"sitemap.xml", [][]byte{[]byte("<url><loc>http://localhost:8080/</loc>")}},
{"feed.xml", [][]byte{
[]byte("<item><title>Hello, world!</title><link>http://localhost:8080/hello-world/</link>"),
}},
{"sitemap.xml", [][]byte{
[]byte("<url><loc>http://localhost:8080/</loc>"),
}},
{"sitemap.xsl", nil},
}

Expand Down Expand Up @@ -103,6 +107,7 @@ func TestFilepathToUrlpath(t *testing.T) {
}{
{input: "content/index.md", expectedUrlPath: "", expectedDatePublished: time.Time{}},
{input: "content/about.md", expectedUrlPath: "about/", expectedDatePublished: time.Time{}},
{input: "content/blog/index.md", expectedUrlPath: "blog/", expectedDatePublished: time.Time{}},
{input: "content/projects/gozer.md", expectedUrlPath: "projects/gozer/", expectedDatePublished: time.Time{}},
{input: "content/2023-11-23-hello-world.md", expectedUrlPath: "hello-world/", expectedDatePublished: time.Date(2023, 11, 23, 0, 0, 0, 0, time.UTC)},
{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)},
Expand Down

0 comments on commit 492e3c6

Please sign in to comment.