From eafcb16002c8a5afb660ed7e1de9492447e1db3c Mon Sep 17 00:00:00 2001 From: jimafisk Date: Thu, 12 Sep 2024 16:28:10 -0400 Subject: [PATCH] Revert "Fix broken _index.json paths (#341)." This reverts commit 1f933272566edfd6cc538c17dfc4bf8fae382d7b. --- cmd/build/data_source.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/build/data_source.go b/cmd/build/data_source.go index 44fb312e..0cddabeb 100644 --- a/cmd/build/data_source.go +++ b/cmd/build/data_source.go @@ -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) @@ -412,7 +412,6 @@ 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 } @@ -420,9 +419,12 @@ 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 }