Switching to the rjson library which is more friendly to human generated json.

This commit is contained in:
spf13 2013-10-01 22:45:24 -04:00
parent 48e1068e3e
commit 18f2b82658
4 changed files with 22 additions and 4 deletions

View file

@ -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)))))
}

View file

@ -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))
}

View file

@ -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)},
}

View file

@ -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, "", "<html><body></body></html>"},
{CONTENT_LWS_LF_HTML, false, true, "", "<html><body></body></html>"},
{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 {