Fix parsing edge case of frontmatter

When the frontmatter contains a - (or other delimiter) close to the
closing frontmatter delimiter, frontmatter detection would fail.
This commit is contained in:
Noah Campbell
2013-09-18 09:15:46 -07:00
parent a82efe5bb1
commit d8e1834910
8 changed files with 100 additions and 68 deletions

View File

@@ -19,10 +19,10 @@ import (
"errors"
"fmt"
"github.com/BurntSushi/toml"
"github.com/spf13/hugo/parser"
helper "github.com/spf13/hugo/template"
"github.com/spf13/hugo/template/bundle"
"github.com/theplant/blackfriday"
"github.com/spf13/hugo/parser"
"html/template"
"io"
"launchpad.net/goyaml"

View File

@@ -10,13 +10,8 @@ import (
var EMPTY_PAGE = ""
var SIMPLE_PAGE = `---
title: Simple
---
Simple Page
`
var INVALID_FRONT_MATTER_MISSING = `This is a test`
var SIMPLE_PAGE = "---\ntitle: Simple\n---\nSimple Page\n"
var INVALID_FRONT_MATTER_MISSING = "This is a test"
var INVALID_FRONT_MATTER_SHORT_DELIM = `
--
@@ -95,7 +90,7 @@ type and layout set`
var SIMPLE_PAGE_WITH_SUMMARY_DELIMITER = `---
title: Simple
---
Simple Page
Summary Next Line
<!--more-->
Some more text
@@ -104,7 +99,7 @@ Some more text
var SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE = `---
title: Simple
---
Simple Page<!--more-->
Summary Same Line<!--more-->
Some more text
`
@@ -144,7 +139,7 @@ func checkPageTitle(t *testing.T, page *Page, title string) {
func checkPageContent(t *testing.T, page *Page, content string) {
if page.Content != template.HTML(content) {
t.Fatalf("Page content is: %s. Expected %s", page.Content, content)
t.Fatalf("Page content mismatch\nexp: %q\ngot: %q", content, page.Content)
}
}
@@ -190,8 +185,8 @@ func TestPageWithDelimiter(t *testing.T) {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
checkPageTitle(t, p, "Simple")
checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n")
checkPageSummary(t, p, "<p>Simple Page</p>\n")
checkPageContent(t, p, "<p>Summary Next Line</p>\n\n<p>Some more text</p>\n")
checkPageSummary(t, p, "<p>Summary Next Line</p>\n")
checkPageType(t, p, "page")
checkPageLayout(t, p, "page/single.html")
@@ -203,8 +198,8 @@ func TestPageWithMoreTag(t *testing.T) {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
checkPageTitle(t, p, "Simple")
checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n")
checkPageSummary(t, p, "<p>Simple Page</p>\n")
checkPageContent(t, p, "<p>Summary Same Line</p>\n\n<p>Some more text</p>\n")
checkPageSummary(t, p, "<p>Summary Same Line</p>\n")
checkPageType(t, p, "page")
checkPageLayout(t, p, "page/single.html")
}
@@ -243,7 +238,7 @@ func TestDegenerateInvalidFrontMatterShortDelim(t *testing.T) {
err string
}{
{INVALID_FRONT_MATTER_SHORT_DELIM, "Unable to locate frontmatter"},
{INVALID_FRONT_MATTER_SHORT_DELIM_ENDING, "EOF"},
{INVALID_FRONT_MATTER_SHORT_DELIM_ENDING, "Unable to read frontmatter at filepos 45: EOF"},
{INVALID_FRONT_MATTER_MISSING, "Unable to locate frontmatter"},
}
for _, test := range tests {

View File

@@ -14,7 +14,6 @@
package hugolib
import (
"io"
"bitbucket.org/pkg/inflect"
"bytes"
"fmt"
@@ -25,6 +24,7 @@ import (
"github.com/spf13/hugo/transform"
"github.com/spf13/nitro"
"html/template"
"io"
"os"
"path"
"strings"
@@ -68,18 +68,18 @@ func PrintErr(str string, a ...interface{}) {
//
// 5. The entire collection of files is written to disk.
type Site struct {
Config Config
Pages Pages
Tmpl bundle.Template
Indexes IndexList
Source source.Input
Sections Index
Info SiteInfo
Shortcodes map[string]ShortcodeFunc
timer *nitro.B
Config Config
Pages Pages
Tmpl bundle.Template
Indexes IndexList
Source source.Input
Sections Index
Info SiteInfo
Shortcodes map[string]ShortcodeFunc
timer *nitro.B
Transformer *transform.Transformer
Target target.Output
Alias target.AliasPublisher
Target target.Output
Alias target.AliasPublisher
}
type SiteInfo struct {

View File

@@ -10,7 +10,12 @@ import (
const SLUG_DOC_1 = "---\ntitle: slug doc 1\nslug: slug-doc-1\naliases:\n - sd1/foo/\n - sd2\n - sd3/\n - sd4.html\n---\nslug doc 1 content\n"
const SLUG_DOC_2 = "---\ntitle: slug doc 2\nslug: slug-doc-2\n---\nslug doc 2 content\n"
const SLUG_DOC_2 = `---
title: slug doc 2
slug: slug-doc-2
---
slug doc 2 content
`
const INDEX_TEMPLATE = "{{ range .Data.Pages }}.{{ end }}"
@@ -58,7 +63,7 @@ func (t *InMemoryAliasTarget) Publish(label string, permalink template.HTML) (er
var urlFakeSource = []byteSource{
{"content/blue/doc1.md", []byte(SLUG_DOC_1)},
// {"content/blue/doc2.md", []byte(SLUG_DOC_2)},
{"content/blue/doc2.md", []byte(SLUG_DOC_2)},
}
func TestPageCount(t *testing.T) {
@@ -95,7 +100,7 @@ func TestPageCount(t *testing.T) {
t.Errorf("No indexed rendered. %v", target.files)
}
expected := "<html><head></head><body>.</body></html>"
expected := "<html><head></head><body>..</body></html>"
if string(blueIndex) != expected {
t.Errorf("Index template does not match expected: %q, got: %q", expected, string(blueIndex))
}