sanity: move from json to yaml
authortycho garen <garen@tychoish.com>
Sat, 6 Jul 2013 23:36:30 +0000 (19:36 -0400)
committertycho garen <garen@tychoish.com>
Sun, 7 Jul 2013 02:32:50 +0000 (22:32 -0400)
21 files changed:
docs/config.json [deleted file]
docs/config.yaml [new file with mode: 0644]
docs/content/doc/configuration.md
docs/content/doc/contributing.md
docs/content/doc/contributors.md
docs/content/doc/example.md
docs/content/doc/front-matter.md
docs/content/doc/installing.md
docs/content/doc/license.md
docs/content/doc/organization.md
docs/content/doc/release-notes.md
docs/content/doc/roadmap.md
docs/content/doc/shortcodes.md
docs/content/doc/source-directory.md
docs/content/doc/templates.md
docs/content/doc/usage.md
docs/content/doc/variables.md
hugolib/config.go
hugolib/helpers.go
hugolib/page.go
main.go

diff --git a/docs/config.json b/docs/config.json
deleted file mode 100644 (file)
index 6c8a198..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-    "Indexes" : {"tag": "tags"},
-    "BaseUrl"    : "http://localhost"
-}
diff --git a/docs/config.yaml b/docs/config.yaml
new file mode 100644 (file)
index 0000000..7715526
--- /dev/null
@@ -0,0 +1,4 @@
+Indexes:
+  tag: 'tags'
+BaseUrl: 'http://localhost'
+...
index bc8df19e08d41229275274cdacdd906de31df807..eea530f02c56058fcaea7bfc2d07660c4c125442 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Configuring Hugo",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Configuring Hugo"
+pubdate: "2013-07-01"
+...
 
 The directory structure and templates provide the majority of the
 configuration for a site. In fact a config file isn't even needed for many websites
index 8ff4fccb454ab923e182d9c20745958528eb7549..6b8aa82333cc6da2f5590797478adc66218496cd 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Contributing to Hugo",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Contributing to Hugo"
+Pubdate: "2013-07-01"
+...
 
 1. Fork it from https://github.com/spf13/hugo
 2. Create your feature branch (`git checkout -b my-new-feature`)
index 003d18553c6197ee0ad566b8566ff8eeb8881eaa..e8a8ad976144027537b8024102c7951c99dcfa95 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Contributors",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Contributors"
+Pubdate: "2013-07-01"
+...
 
 Hugo was built with love and golang by:
 
index 67311a1ca1970924263aa65777e95d11788b4661..75f35f2bfe97c618a0eabeb662ca3cebe2858c63 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Example Content File",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Example Content File"
+Pubdate: "2013-07-01"
+...
 
 Somethings are better shown than explained. The following is a very basic example of a content file:
 
index 6feb74e4ea1c8fa5b4b3ebc32161d13eb0137589..3f00837132791885f145fc12befadf73bebd67af 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Front Matter",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Front Matter"
+Pubdate: "2013-07-01"
+...
 
 The front matter is one of the features that gives Hugo it's strength. It enables
 you to include the meta data of the content right with it. Hugo supports a few 
index 303e9ffa8b6b1b16ca821e057f57bc0a42a7cf6e..1f0f02dedcb2b5b5b6dc471f29a3fa3e58639324 100644 (file)
@@ -1,7 +1,8 @@
-{
-    "title": "Installing Hugo",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Installing Hugo"
+Pubdate: "2013-07-01"
+...
+
 Hugo is written in GoLang with support for Windows, Linux, FreeBSD and OSX.
 
 The latest release can be found at [hugo releases](https://github.com/spf13/hugo/releases).
index 257c4cf93a5ed106c43d7e1ca20de85e52922b4e..43eba11e69bc1f9ba64e125419a5217b83329260 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "License",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "License"
+Pubdate: "2013-07-01"
+...
 
 Hugo is released under the Simple Public License.
 
index 49647c53ec0f6ea53c907b687db634013cc601d5..23238b26d70011c1800f70c2a22f213b73ab33af 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Organization",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Organization"
+Pubdate: "2013-07-01"
+...
 
 Hugo uses markdown files with headers commonly called the front matter. Hugo respects the organization
 that you provide for your content to minimize any extra configuration, though this can be overridden
index 34bd53156f89d35c1ea19035da497cf5dde905a3..a4b9e11e5744423f660bf57d400497bf0ce5c2e5 100644 (file)
@@ -1,8 +1,7 @@
-{
-    "title": "Release Notes",
-    "Pubdate": "2013-07-01"
-
-}
+---
+title: "Release Notes"
+Pubdate: "2013-07-01"
+...
 
 * **0.7.0** July 4, 2013
   * Hugo now includes a simple server
index 3a4faf725ac20b743aec04c1865cd15e5a2dbeeb..7cc5bc812fc8b446133aa474d2e0b9ce2b313e8f 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Roadmap",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Roadmap"
+Pubdate: "2013-07-01"
+...
 
 In no particular order, here is what I'm working on:
 
index 1d30aa8dc1b10d4de08fdbe376999c259567cbcc..abca668feb2626dbfc822f6602fe6065e9ab329b 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Shortcodes",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Shortcodes"
+Pubdate: "2013-07-01"
+...
 
 Because Hugo uses markdown for it's content format, it was clear that there's a lot of things that 
 markdown doesn't support well. This is good, the simple nature of markdown is exactly why we chose it.
index 326a556c3e8d2882dcde887ff96529d641149335..a33adb279cca911970bd3a782769816ad75e551c 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Source Directory Organization",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Source Directory Organization"
+Pubdate: "2013-07-01"
+...
 
 Hugo takes a single directory and uses it as the input for creating a complete website.
 
index e7403bc566977b28d887357d0afad3f012ae3d5d..c2164feb8d864750d29e403a17ce45c6e836410c 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Templates",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Templates"
+Pubdate: "2013-07-01"
+...
 
 Hugo uses the excellent golang html/template library for it's template engine. It is an extremely
 lightweight engine that provides a very small amount of logic. In our 
index 3c7033be4bafaa585734fe11e7934a3de77c775c..950c4abc8436e2279df907a48fb5d30f4c0399c6 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Using Hugo",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Using Hugo"
+Pubdate: "2013-07-01"
+...
 
 Make sure either hugo is in your path or provide a path to it.
 
index ec84ac21c309a79dffa8c371cde6bdf05cc7be9e..a5d70739ba68eff39ac3be8fc456caa33c09534e 100644 (file)
@@ -1,7 +1,7 @@
-{
-    "title": "Variables",
-    "Pubdate": "2013-07-01"
-}
+---
+title: "Variables"
+Pubdate: "2013-07-01"
+...
 
 Hugo makes a set of values available to the templates. Go templates are context based. The following
 are available in the context for the templates.
index abb25046a844f033137815a737be4bf2fa78071c..84d6ce966b1ebf93e969594f148d9eacb69addf7 100644 (file)
@@ -14,7 +14,7 @@
 package hugolib
 
 import (
-       "encoding/json"
+       "launchpad.net/goyaml"
        "fmt"
        "io/ioutil"
        "os"
@@ -55,7 +55,7 @@ func SetupConfig(cfgfile *string, path *string) *Config {
 
        file, err := ioutil.ReadFile(configPath)
        if err == nil {
-               if err := json.Unmarshal(file, &c); err != nil {
+               if err := goyaml.Unmarshal(file, &c); err != nil {
                        fmt.Printf("Error parsing config: %s", err)
                        os.Exit(1)
                }
index 1e02af90bbffc307c7f841004f8cd67f2dd5a62e..4ebeea9980464519e4ebfbb975e1685e13e92221 100644 (file)
@@ -81,7 +81,7 @@ func interfaceToBool(i interface{}) bool {
        case bool:
                return b
        default:
-               Error("Only Boolean values are supported for this JSON key")
+               Error("Only Boolean values are supported for this YAML key")
        }
 
        return false
@@ -106,7 +106,7 @@ func interfaceToString(i interface{}) string {
        case string:
                return s
        default:
-               Error("Only Strings are supported for this JSON key")
+               Error("Only Strings are supported for this YAML key")
        }
 
        return ""
index 2e07cf70d2f567c5520c6e9699683bea2de72784..46c56641291b93c0f56d6b2f06dd7776a199de6c 100644 (file)
@@ -15,7 +15,7 @@ package hugolib
 
 import (
        "bytes"
-       "encoding/json"
+       "launchpad.net/goyaml"
        "fmt"
        "github.com/theplant/blackfriday"
        "html/template"
@@ -141,23 +141,23 @@ func (p *Page) analyzePage() {
 }
 
 // TODO //rewrite to use byte methods instead
-func (page *Page) parseJsonMetaData(data []byte) ([]string, error) {
+func (page *Page) parseYamlMetaData(data []byte) ([]string, error) {
        var err error
 
        lines := strings.Split(string(data), "\n")
        datum := lines[0:]
 
-       // go through content parse between "{" and "}"
+       // go through content parse between "---" and "..."
        // must be on their own lines (for now)
        var found = 0
        for i, line := range lines {
                line = strings.TrimSpace(line)
 
-               if line == "{" {
+               if line == "---" {
                        found += 1
                }
 
-               if line == "}" {
+               if line == "..." {
                        found -= 1
                }
 
@@ -168,7 +168,7 @@ func (page *Page) parseJsonMetaData(data []byte) ([]string, error) {
                }
        }
 
-       err = page.handleJsonMetaData([]byte(strings.Join(datum, "\n")))
+       err = page.handleYamlMetaData([]byte(strings.Join(datum, "\n")))
 
        return lines, err
 }
@@ -185,10 +185,10 @@ func (p *Page) Permalink() template.HTML {
        }
 }
 
-func (page *Page) handleJsonMetaData(datum []byte) error {
+func (page *Page) handleYamlMetaData(datum []byte) error {
        var f interface{}
-       if err := json.Unmarshal(datum, &f); err != nil {
-               return fmt.Errorf("Invalide JSON in $v \nError parsing page meta data: %s", page.FileName, err)
+       if err := goyaml.Unmarshal(datum, &f); err != nil {
+               return fmt.Errorf("Invalide YAML in $v \nError parsing page meta data: %s", page.FileName, err)
        }
 
        m := f.(map[string]interface{})
@@ -309,7 +309,7 @@ func (page *Page) parseFileHeading(data []byte) ([]string, error) {
                if data[0] == '-' {
                        return page.parseFileMetaData(data)
                }
-               return page.parseJsonMetaData(data)
+               return page.parseYamlMetaData(data)
        }
        return nil, nil
 }
diff --git a/main.go b/main.go
index d7386c6c1b849fe5d72e0df05dd9cfcad91aa263..1de48f766518d45ed74e612904ca206e6b2d6586 100644 (file)
--- a/main.go
+++ b/main.go
@@ -17,7 +17,7 @@ import (
        "flag"
        "fmt"
        "github.com/howeyc/fsnotify"
-       "github.com/spf13/hugo/hugolib"
+       "./hugolib"
        "net/http"
        "os"
        "path/filepath"
@@ -26,12 +26,12 @@ import (
 )
 
 const (
-       cfgFiledefault = "config.json"
+       cfgFiledefault = "config.yaml"
 )
 
 var (
        baseUrl    = flag.String("b", "", "hostname (and path) to the root eg. http://spf13.com/")
-       cfgfile    = flag.String("c", cfgFiledefault, "config file (default is path/config.json)")
+       cfgfile    = flag.String("c", cfgFiledefault, "config file (default is path/config.yaml)")
        checkMode  = flag.Bool("k", false, "analyze content and provide feedback")
        draft      = flag.Bool("d", false, "include content marked as draft")
        help       = flag.Bool("h", false, "show this help")