From 1f933272566edfd6cc538c17dfc4bf8fae382d7b Mon Sep 17 00:00:00 2001 From: jimafisk Date: Tue, 10 Sep 2024 23:35:48 -0400 Subject: [PATCH] Fix broken _index.json paths (#341). --- cmd/build/data_source.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cmd/build/data_source.go b/cmd/build/data_source.go index 0cddabeb..44fb312e 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", strings.TrimSuffix(fileName, ".json"), -1) + slug = strings.Replace(slug, ":filename", fileName, -1) // Replace :fields(). fieldReplacements := reField.FindAllStringSubmatch(slug, -1) @@ -412,6 +412,7 @@ 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 } @@ -419,12 +420,9 @@ 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 }