Skip to content

Commit

Permalink
Improve normalizePagePath in file adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
henvo committed Jun 15, 2023
1 parent 6ed12ce commit fd7a335
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions adapter_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,19 @@ func (a *FileAdapter) LoadPages() (pages []Page, err error) {

// Takes a file path and returns the corresponding URL path.
func normalizePagePath(path string) string {
return strings.TrimSuffix(
strings.TrimSuffix(
strings.TrimPrefix(path, "pages/"),
filepath.Ext(path),
),
"index",
)
// Remove the pages directory
np := strings.TrimPrefix(path, "pages/")

// Remove the "html" file ending
np = strings.TrimSuffix(np, filepath.Ext(path))

// Remove the optional 'index' from the end
np = strings.TrimSuffix(np, "index")

// Add a trailing slash for SEO optimization.
if !strings.HasSuffix(np, "/") {
np = np + "/"
}

return np
}

0 comments on commit fd7a335

Please sign in to comment.