YAML support similar to jekyll (start and end with '---')

This commit is contained in:
spf13 2013-07-08 17:57:01 -04:00
parent 94e577740d
commit 3c80cd323c
16 changed files with 51 additions and 41 deletions

View file

@ -1,7 +1,7 @@
--- ---
title: "Configuring Hugo" title: "Configuring Hugo"
pubdate: "2013-07-01" pubdate: "2013-07-01"
... ---
The directory structure and templates provide the majority of the 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 configuration for a site. In fact a config file isn't even needed for many websites

View file

@ -1,7 +1,7 @@
--- ---
title: "Contributing to Hugo" title: "Contributing to Hugo"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
1. Fork it from https://github.com/spf13/hugo 1. Fork it from https://github.com/spf13/hugo
2. Create your feature branch (`git checkout -b my-new-feature`) 2. Create your feature branch (`git checkout -b my-new-feature`)

View file

@ -1,7 +1,7 @@
--- ---
title: "Contributors" title: "Contributors"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Hugo was built with love and golang by: Hugo was built with love and golang by:

View file

@ -1,7 +1,7 @@
--- ---
title: "Example Content File" title: "Example Content File"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Somethings are better shown than explained. The following is a very basic example of a content file: Somethings are better shown than explained. The following is a very basic example of a content file:

View file

@ -1,7 +1,7 @@
--- ---
title: "Front Matter" title: "Front Matter"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
The front matter is one of the features that gives Hugo it's strength. It enables 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 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" - "Development"
- "VIM" - "VIM"
Slug: "spf13-vim-3-0-release-and-new-website" Slug: "spf13-vim-3-0-release-and-new-website"
... ---
### Variables ### Variables

View file

@ -1,7 +1,7 @@
--- ---
title: "Installing Hugo" title: "Installing Hugo"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Hugo is written in GoLang with support for Windows, Linux, FreeBSD and OSX. Hugo is written in GoLang with support for Windows, Linux, FreeBSD and OSX.

View file

@ -1,7 +1,7 @@
--- ---
title: "License" title: "License"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Hugo is released under the Simple Public License. Hugo is released under the Simple Public License.

View file

@ -1,7 +1,7 @@
--- ---
title: "Organization" title: "Organization"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Hugo uses markdown files with headers commonly called the front matter. Hugo respects the organization 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 that you provide for your content to minimize any extra configuration, though this can be overridden

View file

@ -1,7 +1,7 @@
--- ---
title: "Release Notes" title: "Release Notes"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
* **0.7.0** July 4, 2013 * **0.7.0** July 4, 2013
* Hugo now includes a simple server * Hugo now includes a simple server

View file

@ -1,7 +1,7 @@
--- ---
title: "Roadmap" title: "Roadmap"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
In no particular order, here is what I'm working on: In no particular order, here is what I'm working on:

View file

@ -1,7 +1,7 @@
--- ---
title: "Shortcodes" title: "Shortcodes"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Because Hugo uses markdown for it's content format, it was clear that there's a lot of things that 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. markdown doesn't support well. This is good, the simple nature of markdown is exactly why we chose it.

View file

@ -1,7 +1,7 @@
--- ---
title: "Source Directory Organization" title: "Source Directory Organization"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Hugo takes a single directory and uses it as the input for creating a complete website. Hugo takes a single directory and uses it as the input for creating a complete website.

View file

@ -1,7 +1,7 @@
--- ---
title: "Templates" title: "Templates"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Hugo uses the excellent golang html/template library for it's template engine. It is an extremely 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 lightweight engine that provides a very small amount of logic. In our

View file

@ -1,7 +1,7 @@
--- ---
title: "Using Hugo" title: "Using Hugo"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Make sure either hugo is in your path or provide a path to it. Make sure either hugo is in your path or provide a path to it.

View file

@ -1,7 +1,7 @@
--- ---
title: "Variables" title: "Variables"
Pubdate: "2013-07-01" Pubdate: "2013-07-01"
... ---
Hugo makes a set of values available to the templates. Go templates are context based. The following 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. are available in the context for the templates.

View file

@ -16,11 +16,11 @@ package hugolib
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"launchpad.net/goyaml"
"fmt" "fmt"
"github.com/theplant/blackfriday" "github.com/theplant/blackfriday"
"html/template" "html/template"
"io/ioutil" "io/ioutil"
"launchpad.net/goyaml"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -32,17 +32,17 @@ import (
var _ = filepath.Base("") var _ = filepath.Base("")
type Page struct { type Page struct {
Status string Status string
Images []string Images []string
Content template.HTML Content template.HTML
Summary template.HTML Summary template.HTML
RawMarkdown string // TODO should be []byte RawMarkdown string // TODO should be []byte
Params map[string]interface{} Params map[string]interface{}
RenderedContent *bytes.Buffer RenderedContent *bytes.Buffer
contentType string contentType string
Draft bool Draft bool
Tmpl *template.Template Tmpl *template.Template
Markup string Markup string
PageMeta PageMeta
File File
Position Position
@ -67,12 +67,12 @@ type Position struct {
type Pages []*Page 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) 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 // 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 (p Pages) Limit(n int) Pages { return p[0:n] }
func initializePage(filename string) (page Page) { func initializePage(filename string) (page Page) {
@ -148,13 +148,12 @@ func (p *Page) analyzePage() {
func (page *Page) parseYamlMetaData(data []byte) ([]string, error) { func (page *Page) parseYamlMetaData(data []byte) ([]string, error) {
var err error var err error
datum, lines := splitPageContent(data, "---", "...") datum, lines := splitPageContent(data, "---", "---")
err = page.handleMetaData(page.handleYamlMetaData([]byte(strings.Join(datum, "\n")))) err = page.handleMetaData(page.handleYamlMetaData([]byte(strings.Join(datum, "\n"))))
return lines, err return lines, err
} }
func (page *Page) parseJsonMetaData(data []byte) ([]string, error) { func (page *Page) parseJsonMetaData(data []byte) ([]string, error) {
var err error var err error
@ -169,18 +168,30 @@ func splitPageContent(data []byte, start string, end string) ([]string, []string
datum := lines[0:] datum := lines[0:]
var found = 0 var found = 0
for i, line := range lines { if start != end {
for i, line := range lines {
if strings.HasPrefix(line, start) { if strings.HasPrefix(line, start) {
found += 1
}
if strings.HasPrefix(line, end) {
found -= 1
}
if found == 0 {
datum = lines[1 : i+1]
lines = lines[i+1:]
break
}
}
} else {
if found == 0 && strings.HasPrefix(line, start) {
found += 1 found += 1
} }
if strings.HasPrefix(line, end) { if found == 0 && strings.HasPrefix(line, end) {
found -= 1 datum = lines[1 : i+1]
}
if found == 0 {
datum = lines[1: i+1]
lines = lines[i+1:] lines = lines[i+1:]
break break
} }
@ -208,7 +219,6 @@ func (page *Page) handleYamlMetaData(datum []byte) interface{} {
return m return m
} }
func (page *Page) handleJsonMetaData(datum []byte) interface{} { func (page *Page) handleJsonMetaData(datum []byte) interface{} {
var f interface{} var f interface{}
if err := json.Unmarshal(datum, &f); err != nil { if err := json.Unmarshal(datum, &f); err != nil {