shithub: hugo

Download patch

ref: e3e627e6b706a67abb3d7752b27326c07326b53d
parent: 83d03a5201f49552fad35302bfea31db2e447188
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Fri Jun 12 05:14:20 EDT 2020

Add a nested data dir test

Ref. a discussion.

--- a/hugolib/datafiles_test.go
+++ b/hugolib/datafiles_test.go
@@ -289,6 +289,23 @@
 	doTestDataDir(t, dd, expected, "theme", "mytheme")
 }
 
+// https://discourse.gohugo.io/t/recursive-data-file-parsing/26192
+func TestDataDirNestedDirectories(t *testing.T) {
+	t.Parallel()
+
+	var dd dataDir
+	dd.addSource("themes/mytheme/data/a.json", `["1", "2", "3"]`)
+	dd.addSource("data/test1/20/06/a.json", `{ "artist" : "Michael Brecker" }`)
+	dd.addSource("data/test1/20/05/b.json", `{ "artist" : "Charlie Parker" }`)
+
+	expected :=
+		map[string]interface{}{
+			"a":     []interface{}{"1", "2", "3"},
+			"test1": map[string]interface{}{"20": map[string]interface{}{"05": map[string]interface{}{"b": map[string]interface{}{"artist": "Charlie Parker"}}, "06": map[string]interface{}{"a": map[string]interface{}{"artist": "Michael Brecker"}}}}}
+
+	doTestDataDir(t, dd, expected, "theme", "mytheme")
+}
+
 type dataDir struct {
 	sources [][2]string
 }