From a7f5f97bc2c8941cbe9ade740e3c0e54202d8613 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Sat, 6 Jul 2013 19:36:30 -0400 Subject: [PATCH 1/7] sanity: move from json to yaml --- docs/config.json | 4 ---- docs/config.yaml | 4 ++++ docs/content/doc/configuration.md | 8 ++++---- docs/content/doc/contributing.md | 8 ++++---- docs/content/doc/contributors.md | 8 ++++---- docs/content/doc/example.md | 8 ++++---- docs/content/doc/front-matter.md | 8 ++++---- docs/content/doc/installing.md | 9 +++++---- docs/content/doc/license.md | 8 ++++---- docs/content/doc/organization.md | 8 ++++---- docs/content/doc/release-notes.md | 9 ++++----- docs/content/doc/roadmap.md | 8 ++++---- docs/content/doc/shortcodes.md | 8 ++++---- docs/content/doc/source-directory.md | 8 ++++---- docs/content/doc/templates.md | 8 ++++---- docs/content/doc/usage.md | 8 ++++---- docs/content/doc/variables.md | 8 ++++---- hugolib/config.go | 4 ++-- hugolib/helpers.go | 4 ++-- hugolib/page.go | 20 ++++++++++---------- main.go | 6 +++--- 21 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 docs/config.json create mode 100644 docs/config.yaml diff --git a/docs/config.json b/docs/config.json deleted file mode 100644 index 6c8a198d809..00000000000 --- a/docs/config.json +++ /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 index 00000000000..771552606ff --- /dev/null +++ b/docs/config.yaml @@ -0,0 +1,4 @@ +Indexes: + tag: 'tags' +BaseUrl: 'http://localhost' +... diff --git a/docs/content/doc/configuration.md b/docs/content/doc/configuration.md index bc8df19e08d..eea530f02c5 100644 --- a/docs/content/doc/configuration.md +++ b/docs/content/doc/configuration.md @@ -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 diff --git a/docs/content/doc/contributing.md b/docs/content/doc/contributing.md index 8ff4fccb454..6b8aa82333c 100644 --- a/docs/content/doc/contributing.md +++ b/docs/content/doc/contributing.md @@ -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`) diff --git a/docs/content/doc/contributors.md b/docs/content/doc/contributors.md index 003d18553c6..e8a8ad97614 100644 --- a/docs/content/doc/contributors.md +++ b/docs/content/doc/contributors.md @@ -1,7 +1,7 @@ -{ - "title": "Contributors", - "Pubdate": "2013-07-01" -} +--- +title: "Contributors" +Pubdate: "2013-07-01" +... Hugo was built with love and golang by: diff --git a/docs/content/doc/example.md b/docs/content/doc/example.md index 67311a1ca19..75f35f2bfe9 100644 --- a/docs/content/doc/example.md +++ b/docs/content/doc/example.md @@ -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: diff --git a/docs/content/doc/front-matter.md b/docs/content/doc/front-matter.md index 6feb74e4ea1..3f008371327 100644 --- a/docs/content/doc/front-matter.md +++ b/docs/content/doc/front-matter.md @@ -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 diff --git a/docs/content/doc/installing.md b/docs/content/doc/installing.md index 303e9ffa8b6..1f0f02dedcb 100644 --- a/docs/content/doc/installing.md +++ b/docs/content/doc/installing.md @@ -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). diff --git a/docs/content/doc/license.md b/docs/content/doc/license.md index 257c4cf93a5..43eba11e69b 100644 --- a/docs/content/doc/license.md +++ b/docs/content/doc/license.md @@ -1,7 +1,7 @@ -{ - "title": "License", - "Pubdate": "2013-07-01" -} +--- +title: "License" +Pubdate: "2013-07-01" +... Hugo is released under the Simple Public License. diff --git a/docs/content/doc/organization.md b/docs/content/doc/organization.md index 49647c53ec0..23238b26d70 100644 --- a/docs/content/doc/organization.md +++ b/docs/content/doc/organization.md @@ -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 diff --git a/docs/content/doc/release-notes.md b/docs/content/doc/release-notes.md index 34bd53156f8..a4b9e11e574 100644 --- a/docs/content/doc/release-notes.md +++ b/docs/content/doc/release-notes.md @@ -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 diff --git a/docs/content/doc/roadmap.md b/docs/content/doc/roadmap.md index 3a4faf725ac..7cc5bc812fc 100644 --- a/docs/content/doc/roadmap.md +++ b/docs/content/doc/roadmap.md @@ -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: diff --git a/docs/content/doc/shortcodes.md b/docs/content/doc/shortcodes.md index 1d30aa8dc1b..abca668feb2 100644 --- a/docs/content/doc/shortcodes.md +++ b/docs/content/doc/shortcodes.md @@ -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. diff --git a/docs/content/doc/source-directory.md b/docs/content/doc/source-directory.md index 326a556c3e8..a33adb279cc 100644 --- a/docs/content/doc/source-directory.md +++ b/docs/content/doc/source-directory.md @@ -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. diff --git a/docs/content/doc/templates.md b/docs/content/doc/templates.md index e7403bc5669..c2164feb8d8 100644 --- a/docs/content/doc/templates.md +++ b/docs/content/doc/templates.md @@ -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 diff --git a/docs/content/doc/usage.md b/docs/content/doc/usage.md index 3c7033be4ba..950c4abc843 100644 --- a/docs/content/doc/usage.md +++ b/docs/content/doc/usage.md @@ -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. diff --git a/docs/content/doc/variables.md b/docs/content/doc/variables.md index ec84ac21c30..a5d70739ba6 100644 --- a/docs/content/doc/variables.md +++ b/docs/content/doc/variables.md @@ -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. diff --git a/hugolib/config.go b/hugolib/config.go index abb25046a84..84d6ce966b1 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -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) } diff --git a/hugolib/helpers.go b/hugolib/helpers.go index 1e02af90bbf..4ebeea99804 100644 --- a/hugolib/helpers.go +++ b/hugolib/helpers.go @@ -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 "" diff --git a/hugolib/page.go b/hugolib/page.go index 2e07cf70d2f..46c56641291 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -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 d7386c6c1b8..1de48f76651 100644 --- 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") From 431fa0e2d75ca8ddd145bd5db20e50a160772577 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Sat, 6 Jul 2013 22:31:43 -0400 Subject: [PATCH 2/7] changing to suport yaml rather than json and adding optional restructuredtext support --- docs/content/doc/configuration.md | 20 +++++++++++--------- docs/content/doc/example.md | 20 ++++++++++---------- docs/content/doc/front-matter.md | 25 +++++++++++++++---------- hugolib/page.go | 29 ++++++++++++++++++++++++++++- main.go | 2 +- 5 files changed, 65 insertions(+), 31 deletions(-) diff --git a/docs/content/doc/configuration.md b/docs/content/doc/configuration.md index eea530f02c5..09cfb48f3a5 100644 --- a/docs/content/doc/configuration.md +++ b/docs/content/doc/configuration.md @@ -7,13 +7,15 @@ 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 since the defaults used follow commonly used patterns. -The following is an example of a config file with the default values +The following is an example of a config file with the default values: + + SourceDir: "content" + LayoutDir: "layouts" + PublishDir: "public" + BuildDrafts: false + Tags: + category: "categories" + tag: "tags" + BaseUrl: "http://yourSite.com/" + ... - { - "SourceDir" : "content", - "LayoutDir" : "layouts", - "PublishDir" : "public", - "BuildDrafts" : false, - "Tags" : { "category" : "categories", "tag" : "tags" }, - "BaseUrl" : "http://yourSite.com/" - } diff --git a/docs/content/doc/example.md b/docs/content/doc/example.md index 75f35f2bfe9..03595ad10ad 100644 --- a/docs/content/doc/example.md +++ b/docs/content/doc/example.md @@ -7,16 +7,16 @@ Somethings are better shown than explained. The following is a very basic exampl **mysite/project/nitro.md <- http://mysite.com/project/nitro.html** - { - "Title": "Nitro : A quick and simple profiler for golang", - "Description": "", - "Keywords": [ "Development", "golang", "profiling" ], - "Tags": [ "Development", "golang", "profiling" ], - "Pubdate": "2013-06-19", - "Topics": [ "Development", "GoLang" ], - "Slug": "nitro", - "project_url": "http://github.com/spf13/nitro" - } + --- + Title: "Nitro : A quick and simple profiler for golang" + Description": "" + Keywords": [ "Development", "golang", "profiling" ] + Tags": [ "Development", "golang", "profiling" ] + Pubdate": "2013-06-19" + Topics": [ "Development", "GoLang" ] + Slug": "nitro" + project_url": "http://github.com/spf13/nitro" + ... # Nitro diff --git a/docs/content/doc/front-matter.md b/docs/content/doc/front-matter.md index 3f008371327..af930b25f86 100644 --- a/docs/content/doc/front-matter.md +++ b/docs/content/doc/front-matter.md @@ -5,18 +5,21 @@ 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 -different formats. The main format supported is JSON. Here is an example: - - { - "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" ], - "Pubdate": "2012-04-06", - "Categories": [ "Development", "VIM" ], - "Slug": "spf13-vim-3-0-release-and-new-website" - } +different formats. The main format supported is YAML. Here is an example: + + --- + 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" ] + Pubdate: "2012-04-06" + Categories: + - "Development" + - "VIM" + Slug: "spf13-vim-3-0-release-and-new-website" + ... ### Variables + There are a few predefined variables that Hugo is aware of and utilizes. The user can also create any variable they want to. These will be placed into the `.Params` variable available to the templates. @@ -31,6 +34,8 @@ any variable they want to. These will be placed into the `.Params` variable avai **Draft** If true the content will not be rendered unless `hugo` is called with -d
**Type** The type of the content (will be derived from the directory automatically if unset).
+**Markup** (Experimental) Specify "rst" for reStructuredText (requires + `rst2html`,) or "md" (default) for the Markdown.
**Slug** The token to appear in the tail of the url.
*or*
**Url** The full path to the content from the web root.
diff --git a/hugolib/page.go b/hugolib/page.go index 46c56641291..61b3cf0d351 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -21,6 +21,7 @@ import ( "html/template" "io/ioutil" "os" + "os/exec" "path/filepath" "sort" "strings" @@ -40,6 +41,7 @@ type Page struct { contentType string Draft bool Tmpl *template.Template + Markup string PageMeta File Position @@ -80,6 +82,7 @@ func initializePage(filename string) (page Page) { page.Extension = "html" page.Params = make(map[string]interface{}) page.Keywords = make([]string, 10, 30) + page.Markup = "md" page.setSection() return page @@ -216,6 +219,8 @@ func (page *Page) handleYamlMetaData(datum []byte) error { page.Draft = interfaceToBool(v) case "layout": page.layout = interfaceToString(v) + case "markup": + page.Markup = interfaceToString(v) case "status": page.Status = interfaceToString(v) default: @@ -352,7 +357,12 @@ func (page *Page) buildPageFromFile() error { return err } - page.convertMarkdown(content) + switch page.Markup { + case "md": + page.convertMarkdown(content) + case "rst": + page.convertRestructuredText(content) + } return nil } @@ -379,3 +389,20 @@ func (page *Page) convertMarkdown(lines []string) { page.Content = template.HTML(content) page.Summary = template.HTML(TruncateWordsToWholeSentence(StripHTML(StripShortcodes(content)), summaryLength)) } + +func (page *Page) convertRestructuredText(lines []string) { + + page.RawMarkdown = strings.Join(lines, " ") + + cmd := exec.Command("rst2html.py", "--template=/tmp/template.txt") + cmd.Stdin = strings.NewReader(page.RawMarkdown) + var out bytes.Buffer + cmd.Stdout = &out + if err := cmd.Run(); err != nil { + print(err) + } + + content := out.String() + page.Content = template.HTML(content) + page.Summary = template.HTML(TruncateWordsToWholeSentence(StripHTML(StripShortcodes(content)), summaryLength)) +} diff --git a/main.go b/main.go index 1de48f76651..3f4b6f96812 100644 --- a/main.go +++ b/main.go @@ -14,10 +14,10 @@ package main import ( + "./hugolib" "flag" "fmt" "github.com/howeyc/fsnotify" - "./hugolib" "net/http" "os" "path/filepath" From 6c42d3d49095a22f59b860b914b14ff40cb010ff Mon Sep 17 00:00:00 2001 From: tycho garen Date: Sat, 6 Jul 2013 22:58:08 -0400 Subject: [PATCH 3/7] fix: parsing of yaml forematter --- docs/content/doc/configuration.md | 2 +- docs/content/doc/contributing.md | 2 +- docs/content/doc/contributors.md | 2 +- docs/content/doc/example.md | 2 +- docs/content/doc/front-matter.md | 4 +- docs/content/doc/installing.md | 2 +- docs/content/doc/license.md | 2 +- docs/content/doc/organization.md | 2 +- docs/content/doc/release-notes.md | 2 +- docs/content/doc/roadmap.md | 2 +- docs/content/doc/rst.rst | 14 +++++++ docs/content/doc/shortcodes.md | 2 +- docs/content/doc/source-directory.md | 2 +- docs/content/doc/templates.md | 2 +- docs/content/doc/usage.md | 2 +- docs/content/doc/variables.md | 2 +- hugolib/page.go | 59 +++------------------------- 17 files changed, 36 insertions(+), 69 deletions(-) create mode 100644 docs/content/doc/rst.rst diff --git a/docs/content/doc/configuration.md b/docs/content/doc/configuration.md index 09cfb48f3a5..670a8e994f2 100644 --- a/docs/content/doc/configuration.md +++ b/docs/content/doc/configuration.md @@ -1,7 +1,7 @@ --- 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 diff --git a/docs/content/doc/contributing.md b/docs/content/doc/contributing.md index 6b8aa82333c..6ddb241f1b8 100644 --- a/docs/content/doc/contributing.md +++ b/docs/content/doc/contributing.md @@ -1,7 +1,7 @@ --- 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`) diff --git a/docs/content/doc/contributors.md b/docs/content/doc/contributors.md index e8a8ad97614..3a7d7e647d3 100644 --- a/docs/content/doc/contributors.md +++ b/docs/content/doc/contributors.md @@ -1,7 +1,7 @@ --- title: "Contributors" Pubdate: "2013-07-01" -... +--- Hugo was built with love and golang by: diff --git a/docs/content/doc/example.md b/docs/content/doc/example.md index 03595ad10ad..ab409c5954e 100644 --- a/docs/content/doc/example.md +++ b/docs/content/doc/example.md @@ -1,7 +1,7 @@ --- 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: diff --git a/docs/content/doc/front-matter.md b/docs/content/doc/front-matter.md index af930b25f86..e4342099fcc 100644 --- a/docs/content/doc/front-matter.md +++ b/docs/content/doc/front-matter.md @@ -1,7 +1,7 @@ --- 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 @@ -16,7 +16,7 @@ different formats. The main format supported is YAML. Here is an example: - "Development" - "VIM" Slug: "spf13-vim-3-0-release-and-new-website" - ... + --- ### Variables diff --git a/docs/content/doc/installing.md b/docs/content/doc/installing.md index 1f0f02dedcb..92a07dec947 100644 --- a/docs/content/doc/installing.md +++ b/docs/content/doc/installing.md @@ -1,7 +1,7 @@ --- title: "Installing Hugo" Pubdate: "2013-07-01" -... +--- Hugo is written in GoLang with support for Windows, Linux, FreeBSD and OSX. diff --git a/docs/content/doc/license.md b/docs/content/doc/license.md index 43eba11e69b..613a7ed27e0 100644 --- a/docs/content/doc/license.md +++ b/docs/content/doc/license.md @@ -1,7 +1,7 @@ --- title: "License" Pubdate: "2013-07-01" -... +--- Hugo is released under the Simple Public License. diff --git a/docs/content/doc/organization.md b/docs/content/doc/organization.md index 23238b26d70..f524c59d0c3 100644 --- a/docs/content/doc/organization.md +++ b/docs/content/doc/organization.md @@ -1,7 +1,7 @@ --- 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 diff --git a/docs/content/doc/release-notes.md b/docs/content/doc/release-notes.md index a4b9e11e574..e268a5c3e1c 100644 --- a/docs/content/doc/release-notes.md +++ b/docs/content/doc/release-notes.md @@ -1,7 +1,7 @@ --- title: "Release Notes" Pubdate: "2013-07-01" -... +--- * **0.7.0** July 4, 2013 * Hugo now includes a simple server diff --git a/docs/content/doc/roadmap.md b/docs/content/doc/roadmap.md index 7cc5bc812fc..93a7a83d40f 100644 --- a/docs/content/doc/roadmap.md +++ b/docs/content/doc/roadmap.md @@ -1,7 +1,7 @@ --- title: "Roadmap" Pubdate: "2013-07-01" -... +--- In no particular order, here is what I'm working on: diff --git a/docs/content/doc/rst.rst b/docs/content/doc/rst.rst new file mode 100644 index 00000000000..c2838eb0a4b --- /dev/null +++ b/docs/content/doc/rst.rst @@ -0,0 +1,14 @@ +--- +Markup: 'rst' +... + + +============== +This is a Test +============== + + +Really +------ + +text *here* and **HERE**. diff --git a/docs/content/doc/shortcodes.md b/docs/content/doc/shortcodes.md index abca668feb2..222963b03ff 100644 --- a/docs/content/doc/shortcodes.md +++ b/docs/content/doc/shortcodes.md @@ -1,7 +1,7 @@ --- 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. diff --git a/docs/content/doc/source-directory.md b/docs/content/doc/source-directory.md index a33adb279cc..9b0d1ae7e53 100644 --- a/docs/content/doc/source-directory.md +++ b/docs/content/doc/source-directory.md @@ -1,7 +1,7 @@ --- title: "Source Directory Organization" Pubdate: "2013-07-01" -... +--- Hugo takes a single directory and uses it as the input for creating a complete website. diff --git a/docs/content/doc/templates.md b/docs/content/doc/templates.md index c2164feb8d8..6b6e0f34c5f 100644 --- a/docs/content/doc/templates.md +++ b/docs/content/doc/templates.md @@ -1,7 +1,7 @@ --- 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 diff --git a/docs/content/doc/usage.md b/docs/content/doc/usage.md index 950c4abc843..772c1039453 100644 --- a/docs/content/doc/usage.md +++ b/docs/content/doc/usage.md @@ -1,7 +1,7 @@ --- title: "Using Hugo" Pubdate: "2013-07-01" -... +--- Make sure either hugo is in your path or provide a path to it. diff --git a/docs/content/doc/variables.md b/docs/content/doc/variables.md index a5d70739ba6..8a80fa175b4 100644 --- a/docs/content/doc/variables.md +++ b/docs/content/doc/variables.md @@ -1,7 +1,7 @@ --- 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. diff --git a/hugolib/page.go b/hugolib/page.go index 61b3cf0d351..b8863be2a3e 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -154,18 +154,17 @@ func (page *Page) parseYamlMetaData(data []byte) ([]string, error) { // must be on their own lines (for now) var found = 0 for i, line := range lines { - line = strings.TrimSpace(line) - if line == "---" { + if strings.HasPrefix(line, "---") { found += 1 } - if line == "..." { + if strings.HasPrefix(line, "---") { found -= 1 } if found == 0 { - datum = lines[0 : i+1] + datum = lines[0: i+1] lines = lines[i+1:] break } @@ -189,13 +188,11 @@ func (p *Page) Permalink() template.HTML { } func (page *Page) handleYamlMetaData(datum []byte) error { - var f interface{} - 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 := map[string]interface{}{} + if err := goyaml.Unmarshal(datum, &m); err != nil { + return fmt.Errorf("Invalid YAML in $v \nError parsing page meta data: %s", page.FileName, err) } - m := f.(map[string]interface{}) - for k, v := range m { switch strings.ToLower(k) { case "title": @@ -261,47 +258,6 @@ func (page *Page) GetParam(key string) interface{} { return nil } -func (page *Page) parseFileMetaData(data []byte) ([]string, error) { - lines := strings.Split(string(data), "\n") - - // go through content parse from --- to --- - var found = 0 - for i, line := range lines { - line = strings.TrimSpace(line) - - if found == 1 { - // parse line for param - colonIndex := strings.Index(line, ":") - if colonIndex > 0 { - key := strings.TrimSpace(line[:colonIndex]) - value := strings.TrimSpace(line[colonIndex+1:]) - value = strings.Trim(value, "\"") //remove quotes - switch key { - case "title": - page.Title = value - case "layout": - page.layout = value - case "extension": - page.Extension = "." + value - default: - page.Params[key] = value - } - } - - } else if found >= 2 { - // params over - lines = lines[i:] - break - } - - if line == "---" { - found += 1 - } - } - - return lines, nil -} - func (page *Page) Err(message string) { fmt.Println(page.FileName + " : " + message) } @@ -311,9 +267,6 @@ func (page *Page) parseFileHeading(data []byte) ([]string, error) { if len(data) == 0 { page.Err("Empty File, skipping") } else { - if data[0] == '-' { - return page.parseFileMetaData(data) - } return page.parseYamlMetaData(data) } return nil, nil From 67f4da30b184866434d14ae485e63910a66c62ef Mon Sep 17 00:00:00 2001 From: tycho garen Date: Sat, 6 Jul 2013 23:52:14 -0400 Subject: [PATCH 4/7] revert: adding json support --- hugolib/page.go | 62 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/hugolib/page.go b/hugolib/page.go index b8863be2a3e..a1bfffe3da3 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -15,6 +15,7 @@ package hugolib import ( "bytes" + "encoding/json" "launchpad.net/goyaml" "fmt" "github.com/theplant/blackfriday" @@ -31,17 +32,17 @@ import ( var _ = filepath.Base("") type Page struct { - Status string - Images []string - Content template.HTML - Summary template.HTML - RawMarkdown string // TODO should be []byte - Params map[string]interface{} + Status string + Images []string + Content template.HTML + Summary template.HTML + RawMarkdown string // TODO should be []byte + Params map[string]interface{} RenderedContent *bytes.Buffer - contentType string - Draft bool - Tmpl *template.Template - Markup string + contentType string + Draft bool + Tmpl *template.Template + Markup string PageMeta File Position @@ -66,12 +67,12 @@ type Position struct { type Pages []*Page -func (p Pages) Len() int { return len(p) } +func (p Pages) Len() int { return len(p) } func (p Pages) Less(i, j int) bool { return p[i].Date.Unix() > p[j].Date.Unix() } -func (p Pages) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p Pages) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // TODO eliminate unnecessary things -func (p Pages) Sort() { sort.Sort(p) } +func (p Pages) Sort() { sort.Sort(p) } func (p Pages) Limit(n int) Pages { return p[0:n] } func initializePage(filename string) (page Page) { @@ -175,6 +176,38 @@ func (page *Page) parseYamlMetaData(data []byte) ([]string, error) { return lines, err } +func (page *Page) parseJsonMetaData(data []byte) ([]string, error) { + var err error + + lines := strings.Split(string(data), "\n") + datum := lines[0:] + + // 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 == "{" { + found += 1 + } + + if line == "}" { + found -= 1 + } + + if found == 0 { + datum = lines[0 : i+1] + lines = lines[i+1:] + break + } + } + + err = page.handleJsonMetaData([]byte(strings.Join(datum, "\n"))) + + return lines, err +} + func (p *Page) Permalink() template.HTML { if len(strings.TrimSpace(p.Slug)) > 0 { return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+p.Slug)) @@ -267,6 +300,9 @@ func (page *Page) parseFileHeading(data []byte) ([]string, error) { if len(data) == 0 { page.Err("Empty File, skipping") } else { + if data[0] == '{' { + return page.parseJsonMetaData(data) + } return page.parseYamlMetaData(data) } return nil, nil From b024454ea99e647c2b85ce13b3c89c61a4cd0e54 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Sun, 7 Jul 2013 00:49:57 -0400 Subject: [PATCH 5/7] fixes: returning json parsing, error messages, yaml header offsets --- docs/content/doc/example.md | 2 +- hugolib/page.go | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/docs/content/doc/example.md b/docs/content/doc/example.md index ab409c5954e..51e3c160e04 100644 --- a/docs/content/doc/example.md +++ b/docs/content/doc/example.md @@ -16,7 +16,7 @@ Somethings are better shown than explained. The following is a very basic exampl Topics": [ "Development", "GoLang" ] Slug": "nitro" project_url": "http://github.com/spf13/nitro" - ... + --- # Nitro diff --git a/hugolib/page.go b/hugolib/page.go index a1bfffe3da3..b0e796e9716 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -165,14 +165,13 @@ func (page *Page) parseYamlMetaData(data []byte) ([]string, error) { } if found == 0 { - datum = lines[0: i+1] - lines = lines[i+1:] + datum = lines[1: i+2] + lines = lines[i+3:] break } } - err = page.handleYamlMetaData([]byte(strings.Join(datum, "\n"))) - + err = page.handleMetaData(page.handleYamlMetaData([]byte(strings.Join(datum, "\n")))) return lines, err } @@ -203,8 +202,7 @@ func (page *Page) parseJsonMetaData(data []byte) ([]string, error) { } } - err = page.handleJsonMetaData([]byte(strings.Join(datum, "\n"))) - + err = page.handleMetaData(page.handleJsonMetaData([]byte(strings.Join(datum, "\n")))) return lines, err } @@ -220,11 +218,25 @@ func (p *Page) Permalink() template.HTML { } } -func (page *Page) handleYamlMetaData(datum []byte) error { +func (page *Page) handleYamlMetaData(datum []byte) interface{} { m := map[string]interface{}{} if err := goyaml.Unmarshal(datum, &m); err != nil { - return fmt.Errorf("Invalid YAML in $v \nError parsing page meta data: %s", page.FileName, err) + return fmt.Errorf("Invalid YAML in %s \nError parsing page meta data: %s", page.FileName, err) } + return m +} + + +func (page *Page) handleJsonMetaData(datum []byte) interface{} { + 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) + } + return f +} + +func (page *Page) handleMetaData(f interface{}) error { + m := f.(map[string]interface{}) for k, v := range m { switch strings.ToLower(k) { @@ -271,8 +283,8 @@ func (page *Page) handleYamlMetaData(datum []byte) error { } } } - //Printer(page.Params) return nil + } func (page *Page) GetParam(key string) interface{} { @@ -388,7 +400,7 @@ func (page *Page) convertRestructuredText(lines []string) { var out bytes.Buffer cmd.Stdout = &out if err := cmd.Run(); err != nil { - print(err) + fmt.Println(err) } content := out.String() From f851c4162bf3e6e2fd596e2f911b1e62b0220358 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Sun, 7 Jul 2013 10:01:53 -0400 Subject: [PATCH 6/7] fix: changing terminal yaml line, generalizing forematter splitting --- docs/content/doc/configuration.md | 2 +- docs/content/doc/contributing.md | 2 +- docs/content/doc/contributors.md | 2 +- docs/content/doc/example.md | 2 +- docs/content/doc/front-matter.md | 4 +-- docs/content/doc/installing.md | 2 +- docs/content/doc/license.md | 2 +- docs/content/doc/organization.md | 2 +- docs/content/doc/release-notes.md | 2 +- docs/content/doc/roadmap.md | 2 +- docs/content/doc/shortcodes.md | 2 +- docs/content/doc/source-directory.md | 2 +- docs/content/doc/templates.md | 2 +- docs/content/doc/usage.md | 2 +- docs/content/doc/variables.md | 2 +- hugolib/page.go | 44 ++++++++-------------------- 16 files changed, 29 insertions(+), 47 deletions(-) diff --git a/docs/content/doc/configuration.md b/docs/content/doc/configuration.md index 670a8e994f2..09cfb48f3a5 100644 --- a/docs/content/doc/configuration.md +++ b/docs/content/doc/configuration.md @@ -1,7 +1,7 @@ --- 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 diff --git a/docs/content/doc/contributing.md b/docs/content/doc/contributing.md index 6ddb241f1b8..6b8aa82333c 100644 --- a/docs/content/doc/contributing.md +++ b/docs/content/doc/contributing.md @@ -1,7 +1,7 @@ --- 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`) diff --git a/docs/content/doc/contributors.md b/docs/content/doc/contributors.md index 3a7d7e647d3..e8a8ad97614 100644 --- a/docs/content/doc/contributors.md +++ b/docs/content/doc/contributors.md @@ -1,7 +1,7 @@ --- title: "Contributors" Pubdate: "2013-07-01" ---- +... Hugo was built with love and golang by: diff --git a/docs/content/doc/example.md b/docs/content/doc/example.md index 51e3c160e04..b13fa3e16b9 100644 --- a/docs/content/doc/example.md +++ b/docs/content/doc/example.md @@ -1,7 +1,7 @@ --- 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: diff --git a/docs/content/doc/front-matter.md b/docs/content/doc/front-matter.md index e4342099fcc..af930b25f86 100644 --- a/docs/content/doc/front-matter.md +++ b/docs/content/doc/front-matter.md @@ -1,7 +1,7 @@ --- 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 @@ -16,7 +16,7 @@ different formats. The main format supported is YAML. Here is an example: - "Development" - "VIM" Slug: "spf13-vim-3-0-release-and-new-website" - --- + ... ### Variables diff --git a/docs/content/doc/installing.md b/docs/content/doc/installing.md index 92a07dec947..1f0f02dedcb 100644 --- a/docs/content/doc/installing.md +++ b/docs/content/doc/installing.md @@ -1,7 +1,7 @@ --- title: "Installing Hugo" Pubdate: "2013-07-01" ---- +... Hugo is written in GoLang with support for Windows, Linux, FreeBSD and OSX. diff --git a/docs/content/doc/license.md b/docs/content/doc/license.md index 613a7ed27e0..43eba11e69b 100644 --- a/docs/content/doc/license.md +++ b/docs/content/doc/license.md @@ -1,7 +1,7 @@ --- title: "License" Pubdate: "2013-07-01" ---- +... Hugo is released under the Simple Public License. diff --git a/docs/content/doc/organization.md b/docs/content/doc/organization.md index f524c59d0c3..23238b26d70 100644 --- a/docs/content/doc/organization.md +++ b/docs/content/doc/organization.md @@ -1,7 +1,7 @@ --- 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 diff --git a/docs/content/doc/release-notes.md b/docs/content/doc/release-notes.md index e268a5c3e1c..a4b9e11e574 100644 --- a/docs/content/doc/release-notes.md +++ b/docs/content/doc/release-notes.md @@ -1,7 +1,7 @@ --- title: "Release Notes" Pubdate: "2013-07-01" ---- +... * **0.7.0** July 4, 2013 * Hugo now includes a simple server diff --git a/docs/content/doc/roadmap.md b/docs/content/doc/roadmap.md index 93a7a83d40f..7cc5bc812fc 100644 --- a/docs/content/doc/roadmap.md +++ b/docs/content/doc/roadmap.md @@ -1,7 +1,7 @@ --- title: "Roadmap" Pubdate: "2013-07-01" ---- +... In no particular order, here is what I'm working on: diff --git a/docs/content/doc/shortcodes.md b/docs/content/doc/shortcodes.md index 222963b03ff..abca668feb2 100644 --- a/docs/content/doc/shortcodes.md +++ b/docs/content/doc/shortcodes.md @@ -1,7 +1,7 @@ --- 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. diff --git a/docs/content/doc/source-directory.md b/docs/content/doc/source-directory.md index 9b0d1ae7e53..a33adb279cc 100644 --- a/docs/content/doc/source-directory.md +++ b/docs/content/doc/source-directory.md @@ -1,7 +1,7 @@ --- title: "Source Directory Organization" Pubdate: "2013-07-01" ---- +... Hugo takes a single directory and uses it as the input for creating a complete website. diff --git a/docs/content/doc/templates.md b/docs/content/doc/templates.md index 6b6e0f34c5f..c2164feb8d8 100644 --- a/docs/content/doc/templates.md +++ b/docs/content/doc/templates.md @@ -1,7 +1,7 @@ --- 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 diff --git a/docs/content/doc/usage.md b/docs/content/doc/usage.md index 772c1039453..950c4abc843 100644 --- a/docs/content/doc/usage.md +++ b/docs/content/doc/usage.md @@ -1,7 +1,7 @@ --- title: "Using Hugo" Pubdate: "2013-07-01" ---- +... Make sure either hugo is in your path or provide a path to it. diff --git a/docs/content/doc/variables.md b/docs/content/doc/variables.md index 8a80fa175b4..a5d70739ba6 100644 --- a/docs/content/doc/variables.md +++ b/docs/content/doc/variables.md @@ -1,7 +1,7 @@ --- 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. diff --git a/hugolib/page.go b/hugolib/page.go index b0e796e9716..c27bb7c54d2 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -148,62 +148,44 @@ func (p *Page) analyzePage() { 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 "..." - // must be on their own lines (for now) - var found = 0 - for i, line := range lines { - - if strings.HasPrefix(line, "---") { - found += 1 - } - - if strings.HasPrefix(line, "---") { - found -= 1 - } - - if found == 0 { - datum = lines[1: i+2] - lines = lines[i+3:] - break - } - } + datum, lines := splitPageContent(data, "---", "...") err = page.handleMetaData(page.handleYamlMetaData([]byte(strings.Join(datum, "\n")))) return lines, err } + func (page *Page) parseJsonMetaData(data []byte) ([]string, error) { var err error + datum, lines := splitPageContent(data, "{", "}") + + err = page.handleMetaData(page.handleJsonMetaData([]byte(strings.Join(datum, "\n")))) + return lines, err +} + +func splitPageContent(data []byte, start string, end string) ([]string, []string) { lines := strings.Split(string(data), "\n") datum := lines[0:] - // 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 strings.HasPrefix(line, start) { found += 1 } - if line == "}" { + if strings.HasPrefix(line, end) { found -= 1 } if found == 0 { - datum = lines[0 : i+1] + datum = lines[1: i+1] lines = lines[i+1:] break } } - - err = page.handleMetaData(page.handleJsonMetaData([]byte(strings.Join(datum, "\n")))) - return lines, err + return datum, lines } func (p *Page) Permalink() template.HTML { From d0ff31269aca793fbd9c7ae1c4f961a68464dbd8 Mon Sep 17 00:00:00 2001 From: tycho garen Date: Sun, 7 Jul 2013 11:59:19 -0400 Subject: [PATCH 7/7] minor: correcting example --- docs/content/doc/example.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/doc/example.md b/docs/content/doc/example.md index b13fa3e16b9..03595ad10ad 100644 --- a/docs/content/doc/example.md +++ b/docs/content/doc/example.md @@ -16,7 +16,7 @@ Somethings are better shown than explained. The following is a very basic exampl Topics": [ "Development", "GoLang" ] Slug": "nitro" project_url": "http://github.com/spf13/nitro" - --- + ... # Nitro