From 18f2b82658b6f0ea82c867c2c4d40cf0772841d2 Mon Sep 17 00:00:00 2001 From: spf13 Date: Tue, 1 Oct 2013 22:45:24 -0400 Subject: [PATCH] Switching to the rjson library which is more friendly to human generated json. --- commands/server.go | 2 +- hugolib/page.go | 5 ++--- hugolib/page_test.go | 16 ++++++++++++++++ parser/parse_frontmatter_test.go | 3 +++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/commands/server.go b/commands/server.go index fb2feead6..b4d37d3e6 100644 --- a/commands/server.go +++ b/commands/server.go @@ -61,7 +61,7 @@ func serve(port int) { fmt.Println("Serving pages from " + Config.GetAbsPath(Config.PublishDir)) } - fmt.Println("Web Server is available at http://localhost:", port) + fmt.Printf("Web Server is available at http://localhost:%v\n", port) fmt.Println("Press ctrl+c to stop") panic(http.ListenAndServe(":"+strconv.Itoa(port), http.FileServer(http.Dir(Config.GetAbsPath(Config.PublishDir))))) } diff --git a/hugolib/page.go b/hugolib/page.go index 9d978c984..7bb51ebb0 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -15,7 +15,6 @@ package hugolib import ( "bytes" - "encoding/json" "errors" "fmt" "github.com/BurntSushi/toml" @@ -26,11 +25,12 @@ import ( "html/template" "io" "launchpad.net/goyaml" + json "launchpad.net/rjson" + "net/url" "path" "sort" "strings" "time" - "net/url" ) type Page struct { @@ -467,4 +467,3 @@ func (p *Page) TargetPath() (outfile string) { return path.Join(p.Dir, strings.TrimSpace(outfile)) } - diff --git a/hugolib/page_test.go b/hugolib/page_test.go index d16d7f071..bf5e97352 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -49,6 +49,21 @@ Leading "slug": "spf13-vim-3-0-release-and-new-website" } +Content of the file goes Here +` + SIMPLE_PAGE_JSON_LOOSE = ` +{ +"title": "spf13-vim 3.0 release and new website" +"description": "spf13-vim is a cross platform distribution of vim plugins and resources for Vim." +"tags": [ ".vimrc", "plugins", "spf13-vim", "vim" ] +"date": "2012-04-06" +"categories": [ + "Development" + "VIM" +], +"slug": "spf13-vim-3-0-release-and-new-website" +} + Content of the file goes Here ` SIMPLE_PAGE_RFC3339_DATE = "---\ntitle: RFC3339 Date\ndate: \"2013-05-17T16:59:30Z\"\n---\nrfc3339 content" @@ -223,6 +238,7 @@ func TestCreatePage(t *testing.T) { r string }{ {SIMPLE_PAGE_JSON}, + {SIMPLE_PAGE_JSON_LOOSE}, {SIMPLE_PAGE_JSON_MULTIPLE}, //{strings.NewReader(SIMPLE_PAGE_JSON_COMPACT)}, } diff --git a/parser/parse_frontmatter_test.go b/parser/parse_frontmatter_test.go index 6d65d9dcb..87666542a 100644 --- a/parser/parse_frontmatter_test.go +++ b/parser/parse_frontmatter_test.go @@ -29,6 +29,7 @@ var ( CONTENT_SLUG_BUG = "---\ntitle: slug doc 2\nslug: slug-doc-2\n---\nslug doc 2 content" CONTENT_FM_NO_DOC = "---\ntitle: no doc\n---" CONTENT_WITH_JS_FM = "{\n \"categories\": \"d\",\n \"tags\": [\n \"a\", \n \"b\", \n \"c\"\n ]\n}\nJSON Front Matter with tags and categories" + CONTENT_WITH_JS_LOOSE_FM = "{\n \"categories\": \"d\"\n \"tags\": [\n \"a\" \n \"b\" \n \"c\"\n ]\n}\nJSON Front Matter with tags and categories" ) var lineEndings = []string{"\n", "\r\n"} @@ -113,6 +114,7 @@ func TestStandaloneCreatePageFrom(t *testing.T) { {CONTENT_LWS_HTML, false, true, "", ""}, {CONTENT_LWS_LF_HTML, false, true, "", ""}, {CONTENT_WITH_JS_FM, true, false, "{\n \"categories\": \"d\",\n \"tags\": [\n \"a\", \n \"b\", \n \"c\"\n ]\n}", "JSON Front Matter with tags and categories"}, + {CONTENT_WITH_JS_LOOSE_FM, true, false, "{\n \"categories\": \"d\"\n \"tags\": [\n \"a\" \n \"b\" \n \"c\"\n ]\n}", "JSON Front Matter with tags and categories"}, {CONTENT_SLUG_WORKING, true, false, "---\ntitle: slug doc 2\nslug: slug-doc-2\n\n---\n", "slug doc 2 content"}, {CONTENT_SLUG_WORKING_VARIATION, true, false, "---\ntitle: slug doc 3\nslug: slug-doc 3\n---\n", "slug doc 3 content"}, {CONTENT_SLUG_BUG, true, false, "---\ntitle: slug doc 2\nslug: slug-doc-2\n---\n", "slug doc 2 content"}, @@ -281,6 +283,7 @@ func TestExtractFrontMatterDelim(t *testing.T) { {"{ { } { } }", "{ { } { } }", noErrExpected}, {"{\n{\n}\n}\n", "{\n{\n}\n}", noErrExpected}, {"{\n \"categories\": \"d\",\n \"tags\": [\n \"a\", \n \"b\", \n \"c\"\n ]\n}\nJSON Front Matter with tags and categories", "{\n \"categories\": \"d\",\n \"tags\": [\n \"a\", \n \"b\", \n \"c\"\n ]\n}", noErrExpected}, + {"{\n \"categories\": \"d\"\n \"tags\": [\n \"a\" \n \"b\" \n \"c\"\n ]\n}\nJSON Front Matter with tags and categories", "{\n \"categories\": \"d\"\n \"tags\": [\n \"a\" \n \"b\" \n \"c\"\n ]\n}", noErrExpected}, } for _, test := range tests {