Skip to content

Commit

Permalink
Revert "Fix broken _index.json paths (#341)."
Browse files Browse the repository at this point in the history
This reverts commit 1f93327.
  • Loading branch information
jimafisk committed Sep 12, 2024
1 parent 1f93327 commit eafcb16
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 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", fileName, -1)
slug = strings.Replace(slug, ":filename", strings.TrimSuffix(fileName, ".json"), -1)

// Replace :fields().
fieldReplacements := reField.FindAllStringSubmatch(slug, -1)
Expand Down Expand Up @@ -412,17 +412,19 @@ 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" {
if fileName == "_index.json" {
// 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 eafcb16

Please sign in to comment.