summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hugolib/node.go2
-rw-r--r--hugolib/page.go2
-rw-r--r--hugolib/site.go2
-rw-r--r--hugolib/siteJSONEncode_test.go32
4 files changed, 35 insertions, 3 deletions
diff --git a/hugolib/node.go b/hugolib/node.go
index 7606e8896..cbc314049 100644
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -22,7 +22,7 @@ import (
type Node struct {
RSSLink template.HTML
- Site *SiteInfo
+ Site *SiteInfo `json:"-"`
// layout string
Data map[string]interface{}
Title string
diff --git a/hugolib/page.go b/hugolib/page.go
index fd51e7263..391fedf38 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -71,7 +71,7 @@ type Page struct {
renderingConfigInit sync.Once
PageMeta
Source
- Position
+ Position `json:"-"`
Node
pageMenus PageMenus
pageMenusInit sync.Once
diff --git a/hugolib/site.go b/hugolib/site.go
index 7f2016ace..67d8c50ec 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -79,7 +79,7 @@ type Site struct {
timer *nitro.B
Targets targetList
targetListInit sync.Once
- Completed chan bool
+ Completed chan bool `json:"-"`
RunMode runmode
params map[string]interface{}
draftCount int
diff --git a/hugolib/siteJSONEncode_test.go b/hugolib/siteJSONEncode_test.go
new file mode 100644
index 000000000..7c4bb48e3
--- /dev/null
+++ b/hugolib/siteJSONEncode_test.go
@@ -0,0 +1,32 @@
+package hugolib
+
+import (
+ "encoding/json"
+ "fmt"
+ "testing"
+)
+
+// Issue #1123
+// Testing prevention of cyclic refs in JSON encoding
+// May be smart to run with: -timeout 4000ms
+func TestEncodePage(t *testing.T) {
+
+ // borrowed from menu_test.go
+ s := createTestSite(MENU_PAGE_SOURCES)
+ testSiteSetup(s, t)
+
+ j, err := json.Marshal(s)
+ check(t, err)
+ fmt.Println("Site as JSON", string(j))
+
+ p, err := json.Marshal(s.Pages[0])
+ check(t, err)
+ fmt.Println("Page as JSON", string(p))
+
+}
+
+func check(t *testing.T, err error) {
+ if err != nil {
+ t.Fatalf("Failed %s", err)
+ }
+}