Skip to content

Commit

Permalink
fix: changing terminal yaml line, generalizing forematter splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
tychoish committed Jul 7, 2013
1 parent b024454 commit f851c41
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 47 deletions.
2 changes: 1 addition & 1 deletion docs/content/doc/configuration.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/contributing.md
Original file line number Diff line number Diff line change
@@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/contributors.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Contributors"
Pubdate: "2013-07-01"
---
...

Hugo was built with love and golang by:

Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/example.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
4 changes: 2 additions & 2 deletions docs/content/doc/front-matter.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/installing.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Installing Hugo"
Pubdate: "2013-07-01"
---
...

Hugo is written in GoLang with support for Windows, Linux, FreeBSD and OSX.

Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/license.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "License"
Pubdate: "2013-07-01"
---
...

Hugo is released under the Simple Public License.

Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/organization.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Release Notes"
Pubdate: "2013-07-01"
---
...

* **0.7.0** July 4, 2013
* Hugo now includes a simple server
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/roadmap.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Roadmap"
Pubdate: "2013-07-01"
---
...

In no particular order, here is what I'm working on:

Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/shortcodes.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/source-directory.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/templates.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/usage.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/variables.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
44 changes: 13 additions & 31 deletions hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f851c41

Please sign in to comment.