mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-29 23:20:49 +03:00
Adding support for TOML, updating documentation
This commit is contained in:
parent
3c80cd323c
commit
d2a6267ad7
7 changed files with 168 additions and 63 deletions
98
README.md
98
README.md
|
@ -262,35 +262,78 @@ Without any additional configuration the following will just work.
|
||||||
|
|
||||||
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
|
||||||
different formats. The main format supported is JSON. Here is an example:
|
different formats each with their own identifying tokens.
|
||||||
|
|
||||||
|
Supported formats: <br>
|
||||||
|
**YAML**, identified by '\-\-\-'. <br>
|
||||||
|
**TOML**, indentified with '+++'.<br>
|
||||||
|
**JSON**, a single JSON object which is surrounded by '{' and '}' each on their own line.
|
||||||
|
|
||||||
|
### YAML 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"
|
||||||
|
---
|
||||||
|
Content of the file goes Here
|
||||||
|
|
||||||
|
### TOML 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"
|
||||||
|
+++
|
||||||
|
Content of the file goes Here
|
||||||
|
|
||||||
|
### JSON Example
|
||||||
|
|
||||||
{
|
{
|
||||||
"Title": "spf13-vim 3.0 release and new website",
|
"title": "spf13-vim 3.0 release and new website",
|
||||||
"Description": "spf13-vim is a cross platform distribution of vim plugins and resources for Vim.",
|
"description": "spf13-vim is a cross platform distribution of vim plugins and resources for Vim.",
|
||||||
"Tags": [ ".vimrc", "plugins", "spf13-vim", "vim" ],
|
"tags": [ ".vimrc", "plugins", "spf13-vim", "vim" ],
|
||||||
"Pubdate": "2012-04-06",
|
"date": "2012-04-06",
|
||||||
"Categories": [ "Development", "VIM" ],
|
"categories": [
|
||||||
"Slug": "spf13-vim-3-0-release-and-new-website"
|
"Development",
|
||||||
|
"VIM"
|
||||||
|
],
|
||||||
|
"slug": "spf13-vim-3-0-release-and-new-website",
|
||||||
}
|
}
|
||||||
|
Content of the file goes Here
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
There are a few predefined variables that Hugo is aware of and utilizes. The user can also create
|
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.
|
any variable they want to. These will be placed into the `.Params` variable available to the templates.
|
||||||
|
**Field names are case insensitive.**
|
||||||
|
|
||||||
#### Required
|
#### Required
|
||||||
|
|
||||||
**Title** The title for the content. <br>
|
**title** The title for the content. <br>
|
||||||
**Description** The description for the content.<br>
|
**description** The description for the content.<br>
|
||||||
**Pubdate** The date the content will be sorted by.<br>
|
**date** The date the content will be sorted by.<br>
|
||||||
**Indexes** These will use the field name of the plural form of the index (see tags and categories above)
|
**indexes** These will use the field name of the plural form of the index (see tags and categories above)
|
||||||
|
|
||||||
#### Optional
|
#### Optional
|
||||||
|
|
||||||
**Draft** If true the content will not be rendered unless `hugo` is called with -d<br>
|
**draft** If true the content will not be rendered unless `hugo` is called with -d<br>
|
||||||
**Type** The type of the content (will be derived from the directory automatically if unset).<br>
|
**type** The type of the content (will be derived from the directory automatically if unset).<br>
|
||||||
**Slug** The token to appear in the tail of the url.<br>
|
**markup** (Experimental) Specify "rst" for reStructuredText (requires
|
||||||
|
`rst2html`,) or "md" (default) for the Markdown.<br>
|
||||||
|
**slug** The token to appear in the tail of the url.<br>
|
||||||
*or*<br>
|
*or*<br>
|
||||||
**Url** The full path to the content from the web root.<br>
|
**url** The full path to the content from the web root.<br>
|
||||||
*If neither is present the filename will be used.*
|
*If neither is present the filename will be used.*
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
@ -298,16 +341,16 @@ Somethings are better shown than explained. The following is a very basic exampl
|
||||||
|
|
||||||
**mysite/project/nitro.md <- http://mysite.com/project/nitro.html**
|
**mysite/project/nitro.md <- http://mysite.com/project/nitro.html**
|
||||||
|
|
||||||
{
|
---
|
||||||
"Title": "Nitro : A quick and simple profiler for golang",
|
Title: "Nitro : A quick and simple profiler for golang"
|
||||||
"Description": "",
|
Description": ""
|
||||||
"Keywords": [ "Development", "golang", "profiling" ],
|
Keywords": [ "Development", "golang", "profiling" ]
|
||||||
"Tags": [ "Development", "golang", "profiling" ],
|
Tags": [ "Development", "golang", "profiling" ]
|
||||||
"Pubdate": "2013-06-19",
|
Pubdate": "2013-06-19"
|
||||||
"Topics": [ "Development", "GoLang" ],
|
Topics": [ "Development", "GoLang" ]
|
||||||
"Slug": "nitro",
|
Slug": "nitro"
|
||||||
"project_url": "http://github.com/spf13/nitro"
|
project_url": "http://github.com/spf13/nitro"
|
||||||
}
|
---
|
||||||
|
|
||||||
# Nitro
|
# Nitro
|
||||||
|
|
||||||
|
@ -329,7 +372,6 @@ Somethings are better shown than explained. The following is a very basic exampl
|
||||||
Next include nitro in your application.
|
Next include nitro in your application.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Extras
|
# Extras
|
||||||
|
|
||||||
## Shortcodes
|
## Shortcodes
|
||||||
|
@ -423,8 +465,8 @@ In no particular order, here is what I'm working on:
|
||||||
* Syntax highlighting
|
* Syntax highlighting
|
||||||
* Previous & Next
|
* Previous & Next
|
||||||
* Related Posts
|
* Related Posts
|
||||||
* Support for TOML front matter
|
* Support for TOML front matter -- in head
|
||||||
* Proper YAML support for front matter
|
* Proper YAML support for front matter -- in head
|
||||||
* Support for other formats
|
* Support for other formats
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
title: "Contributors"
|
title: "Contributors"
|
||||||
Pubdate: "2013-07-01"
|
date: "2013-07-01"
|
||||||
---
|
---
|
||||||
|
|
||||||
Hugo was built with love and golang by:
|
Hugo was built with love and golang by:
|
||||||
|
|
|
@ -16,7 +16,7 @@ Somethings are better shown than explained. The following is a very basic exampl
|
||||||
Topics": [ "Development", "GoLang" ]
|
Topics": [ "Development", "GoLang" ]
|
||||||
Slug": "nitro"
|
Slug": "nitro"
|
||||||
project_url": "http://github.com/spf13/nitro"
|
project_url": "http://github.com/spf13/nitro"
|
||||||
...
|
---
|
||||||
|
|
||||||
# Nitro
|
# Nitro
|
||||||
|
|
||||||
|
|
|
@ -1,43 +1,82 @@
|
||||||
---
|
+++
|
||||||
title: "Front Matter"
|
title = "Front Matter"
|
||||||
Pubdate: "2013-07-01"
|
date = "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
|
||||||
different formats. The main format supported is YAML. Here is an example:
|
different formats each with their own identifying tokens.
|
||||||
|
|
||||||
|
Supported formats: <br>
|
||||||
|
**YAML**, identified by '\-\-\-'. <br>
|
||||||
|
**TOML**, indentified with '+++'.<br>
|
||||||
|
**JSON**, a single JSON object which is surrounded by '{' and '}' each on their own line.
|
||||||
|
|
||||||
|
### YAML Example
|
||||||
|
|
||||||
---
|
---
|
||||||
Title: "spf13-vim 3.0 release and new website"
|
title: "spf13-vim 3.0 release and new website"
|
||||||
Description: "spf13-vim is a cross platform distribution of vim plugins and resources for Vim."
|
description: "spf13-vim is a cross platform distribution of vim plugins and resources for Vim."
|
||||||
Tags: [ ".vimrc", "plugins", "spf13-vim", "vim" ]
|
tags: [ ".vimrc", "plugins", "spf13-vim", "vim" ]
|
||||||
Pubdate: "2012-04-06"
|
pubdate: "2012-04-06"
|
||||||
Categories:
|
categories:
|
||||||
- "Development"
|
- "Development"
|
||||||
- "VIM"
|
- "VIM"
|
||||||
Slug: "spf13-vim-3-0-release-and-new-website"
|
slug: "spf13-vim-3-0-release-and-new-website"
|
||||||
---
|
---
|
||||||
|
Content of the file goes Here
|
||||||
|
|
||||||
|
### TOML 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"
|
||||||
|
+++
|
||||||
|
Content of the file goes Here
|
||||||
|
|
||||||
|
### JSON 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" ],
|
||||||
|
"date": "2012-04-06",
|
||||||
|
"categories": [
|
||||||
|
"Development",
|
||||||
|
"VIM"
|
||||||
|
],
|
||||||
|
"slug": "spf13-vim-3-0-release-and-new-website",
|
||||||
|
}
|
||||||
|
Content of the file goes Here
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
There are a few predefined variables that Hugo is aware of and utilizes. The user can also create
|
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.
|
any variable they want to. These will be placed into the `.Params` variable available to the templates.
|
||||||
|
**Field names are case insensitive.**
|
||||||
|
|
||||||
#### Required
|
#### Required
|
||||||
|
|
||||||
**Title** The title for the content. <br>
|
**title** The title for the content. <br>
|
||||||
**Description** The description for the content.<br>
|
**description** The description for the content.<br>
|
||||||
**Pubdate** The date the content will be sorted by.<br>
|
**date** The date the content will be sorted by.<br>
|
||||||
**Indexes** These will use the field name of the plural form of the index (see tags and categories above)
|
**indexes** These will use the field name of the plural form of the index (see tags and categories above)
|
||||||
|
|
||||||
#### Optional
|
#### Optional
|
||||||
|
|
||||||
**Draft** If true the content will not be rendered unless `hugo` is called with -d<br>
|
**draft** If true the content will not be rendered unless `hugo` is called with -d<br>
|
||||||
**Type** The type of the content (will be derived from the directory automatically if unset).<br>
|
**type** The type of the content (will be derived from the directory automatically if unset).<br>
|
||||||
**Markup** (Experimental) Specify "rst" for reStructuredText (requires
|
**markup** (Experimental) Specify "rst" for reStructuredText (requires
|
||||||
`rst2html`,) or "md" (default) for the Markdown.<br>
|
`rst2html`,) or "md" (default) for the Markdown.<br>
|
||||||
**Slug** The token to appear in the tail of the url.<br>
|
**slug** The token to appear in the tail of the url.<br>
|
||||||
*or*<br>
|
*or*<br>
|
||||||
**Url** The full path to the content from the web root.<br>
|
**url** The full path to the content from the web root.<br>
|
||||||
*If neither is present the filename will be used.*
|
*If neither is present the filename will be used.*
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ In no particular order, here is what I'm working on:
|
||||||
* Syntax highlighting
|
* Syntax highlighting
|
||||||
* Previous & Next
|
* Previous & Next
|
||||||
* Related Posts
|
* Related Posts
|
||||||
* Support for TOML front matter
|
* Support for TOML front matter -- in head
|
||||||
* Proper YAML support for front matter
|
* Proper YAML support for front matter -- in head
|
||||||
* Support for other formats
|
* Support for other formats
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
Markup: 'rst'
|
Markup: 'rst'
|
||||||
...
|
---
|
||||||
|
|
||||||
|
|
||||||
==============
|
==============
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/theplant/blackfriday"
|
"github.com/theplant/blackfriday"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -154,6 +155,15 @@ func (page *Page) parseYamlMetaData(data []byte) ([]string, error) {
|
||||||
return lines, err
|
return lines, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (page *Page) parseTomlMetaData(data []byte) ([]string, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
datum, lines := splitPageContent(data, "+++", "+++")
|
||||||
|
|
||||||
|
err = page.handleMetaData(page.handleTomlMetaData([]byte(strings.Join(datum, "\n"))))
|
||||||
|
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
|
||||||
|
|
||||||
|
@ -185,16 +195,18 @@ func splitPageContent(data []byte, start string, end string) ([]string, []string
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else { // Start token & end token are the same
|
||||||
if found == 0 && strings.HasPrefix(line, start) {
|
for i, line := range lines {
|
||||||
found += 1
|
if found == 1 && strings.HasPrefix(line, end) {
|
||||||
}
|
datum = lines[1:i]
|
||||||
|
|
||||||
if found == 0 && strings.HasPrefix(line, end) {
|
|
||||||
datum = lines[1 : i+1]
|
|
||||||
lines = lines[i+1:]
|
lines = lines[i+1:]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if found == 0 && strings.HasPrefix(line, start) {
|
||||||
|
found = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return datum, lines
|
return datum, lines
|
||||||
}
|
}
|
||||||
|
@ -211,6 +223,14 @@ func (p *Page) Permalink() template.HTML {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (page *Page) handleTomlMetaData(datum []byte) interface{} {
|
||||||
|
m := map[string]interface{}{}
|
||||||
|
if _, err := toml.Decode(string(datum), &m); err != nil {
|
||||||
|
return fmt.Errorf("Invalid TOML in %s \nError parsing page meta data: %s", page.FileName, err)
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
func (page *Page) handleYamlMetaData(datum []byte) interface{} {
|
func (page *Page) handleYamlMetaData(datum []byte) interface{} {
|
||||||
m := map[string]interface{}{}
|
m := map[string]interface{}{}
|
||||||
if err := goyaml.Unmarshal(datum, &m); err != nil {
|
if err := goyaml.Unmarshal(datum, &m); err != nil {
|
||||||
|
@ -304,10 +324,14 @@ func (page *Page) parseFileHeading(data []byte) ([]string, error) {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
page.Err("Empty File, skipping")
|
page.Err("Empty File, skipping")
|
||||||
} else {
|
} else {
|
||||||
if data[0] == '{' {
|
switch data[0] {
|
||||||
|
case '{':
|
||||||
return page.parseJsonMetaData(data)
|
return page.parseJsonMetaData(data)
|
||||||
}
|
case '-':
|
||||||
return page.parseYamlMetaData(data)
|
return page.parseYamlMetaData(data)
|
||||||
|
case '+':
|
||||||
|
return page.parseTomlMetaData(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue