Skip to content

Commit

Permalink
Fix broken _index.json paths (#341).
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Sep 11, 2024
1 parent 4107658 commit 1f93327
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions cmd/build/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func getContent(path string, info os.FileInfo, err error, siteConfig readers.Sit
for configContentType, slug := range siteConfig.Routes {
if configContentType == contentType {
// Replace :filename.
slug = strings.Replace(slug, ":filename", strings.TrimSuffix(fileName, ".json"), -1)
slug = strings.Replace(slug, ":filename", fileName, -1)

// Replace :fields().
fieldReplacements := reField.FindAllStringSubmatch(slug, -1)
Expand Down Expand Up @@ -412,19 +412,17 @@ func getFileInfo(path string) (string, string, string) {
parts := strings.Split(path, "/")
contentType := parts[1]
fileName := parts[len(parts)-1]
fileName = strings.TrimSuffix(fileName, ".json")
return filePath, contentType, fileName
}

func makeWebPath(path string, fileName string) string {
// Remove the "content/" folder from path.
path = strings.TrimPrefix(path, "content/")
// Check for index file at any level.
if fileName == "_index.json" {
if fileName == "_index" {
// Remove entire filename from path.
path = strings.TrimSuffix(path, fileName)
} else {
// Remove file extension only from path for files other than index.json.
path = strings.TrimSuffix(path, ".json")
}
return path
}
Expand Down

0 comments on commit 1f93327

Please sign in to comment.