|
|
@@ -34,19 +34,19 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
TEMPLATE_TITLE = "{{ .Title }}"
|
|
|
|
templateTitle = "{{ .Title }}"
|
|
|
|
PAGE_SIMPLE_TITLE = `---
|
|
|
|
pageSimpleTitle = `---
|
|
|
|
title: simple template
|
|
|
|
title: simple template
|
|
|
|
---
|
|
|
|
---
|
|
|
|
content`
|
|
|
|
content`
|
|
|
|
|
|
|
|
|
|
|
|
TEMPLATE_MISSING_FUNC = "{{ .Title | funcdoesnotexists }}"
|
|
|
|
templateMissingFunc = "{{ .Title | funcdoesnotexists }}"
|
|
|
|
TEMPLATE_FUNC = "{{ .Title | urlize }}"
|
|
|
|
templateFunc = "{{ .Title | urlize }}"
|
|
|
|
TEMPLATE_CONTENT = "{{ .Content }}"
|
|
|
|
templateContent = "{{ .Content }}"
|
|
|
|
TEMPLATE_DATE = "{{ .Date }}"
|
|
|
|
templateDate = "{{ .Date }}"
|
|
|
|
TEMPLATE_WITH_URL_ABS = "<a href=\"/foobar.jpg\">Going</a>"
|
|
|
|
templateWithURLAbs = "<a href=\"/foobar.jpg\">Going</a>"
|
|
|
|
|
|
|
|
|
|
|
|
PAGE_WITH_MD = `---
|
|
|
|
pageWithMd = `---
|
|
|
|
title: page with md
|
|
|
|
title: page with md
|
|
|
|
---
|
|
|
|
---
|
|
|
|
# heading 1
|
|
|
|
# heading 1
|
|
|
@@ -113,7 +113,7 @@ func pageMust(p *Page, err error) *Page {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestDegenerateRenderThingMissingTemplate(t *testing.T) {
|
|
|
|
func TestDegenerateRenderThingMissingTemplate(t *testing.T) {
|
|
|
|
p, _ := NewPageFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
|
|
|
|
p, _ := NewPageFrom(strings.NewReader(pageSimpleTitle), "content/a/file.md")
|
|
|
|
p.Convert()
|
|
|
|
p.Convert()
|
|
|
|
s := new(Site)
|
|
|
|
s := new(Site)
|
|
|
|
s.prepTemplates()
|
|
|
|
s.prepTemplates()
|
|
|
@@ -125,7 +125,7 @@ func TestDegenerateRenderThingMissingTemplate(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestAddInvalidTemplate(t *testing.T) {
|
|
|
|
func TestAddInvalidTemplate(t *testing.T) {
|
|
|
|
s := new(Site)
|
|
|
|
s := new(Site)
|
|
|
|
err := s.prepTemplates("missing", TEMPLATE_MISSING_FUNC)
|
|
|
|
err := s.prepTemplates("missing", templateMissingFunc)
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("Expecting the template to return an error")
|
|
|
|
t.Fatalf("Expecting the template to return an error")
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -147,10 +147,10 @@ func TestRenderThing(t *testing.T) {
|
|
|
|
template string
|
|
|
|
template string
|
|
|
|
expected string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
}{
|
|
|
|
{PAGE_SIMPLE_TITLE, TEMPLATE_TITLE, "simple template"},
|
|
|
|
{pageSimpleTitle, templateTitle, "simple template"},
|
|
|
|
{PAGE_SIMPLE_TITLE, TEMPLATE_FUNC, "simple-template"},
|
|
|
|
{pageSimpleTitle, templateFunc, "simple-template"},
|
|
|
|
{PAGE_WITH_MD, TEMPLATE_CONTENT, "\n\n<h1 id=\"heading-1:91b5c4a22fc6103c73bb91e4a40568f8\">heading 1</h1>\n\n<p>text</p>\n\n<h2 id=\"heading-2:91b5c4a22fc6103c73bb91e4a40568f8\">heading 2</h2>\n\n<p>more text</p>\n"},
|
|
|
|
{pageWithMd, templateContent, "\n\n<h1 id=\"heading-1:91b5c4a22fc6103c73bb91e4a40568f8\">heading 1</h1>\n\n<p>text</p>\n\n<h2 id=\"heading-2:91b5c4a22fc6103c73bb91e4a40568f8\">heading 2</h2>\n\n<p>more text</p>\n"},
|
|
|
|
{simplePageRFC3339Date, TEMPLATE_DATE, "2013-05-17 16:59:30 +0000 UTC"},
|
|
|
|
{simplePageRFC3339Date, templateDate, "2013-05-17 16:59:30 +0000 UTC"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
for i, test := range tests {
|
|
|
@@ -193,10 +193,10 @@ func TestRenderThingOrDefault(t *testing.T) {
|
|
|
|
template string
|
|
|
|
template string
|
|
|
|
expected string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
}{
|
|
|
|
{true, TEMPLATE_TITLE, HTML("simple template")},
|
|
|
|
{true, templateTitle, HTML("simple template")},
|
|
|
|
{true, TEMPLATE_FUNC, HTML("simple-template")},
|
|
|
|
{true, templateFunc, HTML("simple-template")},
|
|
|
|
{false, TEMPLATE_TITLE, HTML("simple template")},
|
|
|
|
{false, templateTitle, HTML("simple template")},
|
|
|
|
{false, TEMPLATE_FUNC, HTML("simple-template")},
|
|
|
|
{false, templateFunc, HTML("simple-template")},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hugofs.InitMemFs()
|
|
|
|
hugofs.InitMemFs()
|
|
|
@@ -205,7 +205,7 @@ func TestRenderThingOrDefault(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
s := &Site{}
|
|
|
|
s := &Site{}
|
|
|
|
|
|
|
|
|
|
|
|
p, err := NewPageFrom(strings.NewReader(PAGE_SIMPLE_TITLE), "content/a/file.md")
|
|
|
|
p, err := NewPageFrom(strings.NewReader(pageSimpleTitle), "content/a/file.md")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error parsing buffer: %s", err)
|
|
|
|
t.Fatalf("Error parsing buffer: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
@@ -638,7 +638,7 @@ func TestAbsURLify(t *testing.T) {
|
|
|
|
t.Logf("Rendering with BaseURL %q and CanonifyURLs set %v", viper.GetString("baseURL"), canonify)
|
|
|
|
t.Logf("Rendering with BaseURL %q and CanonifyURLs set %v", viper.GetString("baseURL"), canonify)
|
|
|
|
s.initializeSiteInfo()
|
|
|
|
s.initializeSiteInfo()
|
|
|
|
|
|
|
|
|
|
|
|
s.prepTemplates("blue/single.html", TEMPLATE_WITH_URL_ABS)
|
|
|
|
s.prepTemplates("blue/single.html", templateWithURLAbs)
|
|
|
|
|
|
|
|
|
|
|
|
if err := s.CreatePages(); err != nil {
|
|
|
|
if err := s.CreatePages(); err != nil {
|
|
|
|
t.Fatalf("Unable to create pages: %s", err)
|
|
|
|
t.Fatalf("Unable to create pages: %s", err)
|
|
|
@@ -681,7 +681,7 @@ func TestAbsURLify(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var WEIGHTED_PAGE_1 = []byte(`+++
|
|
|
|
var weightedPage1 = []byte(`+++
|
|
|
|
weight = "2"
|
|
|
|
weight = "2"
|
|
|
|
title = "One"
|
|
|
|
title = "One"
|
|
|
|
my_param = "foo"
|
|
|
|
my_param = "foo"
|
|
|
@@ -689,7 +689,7 @@ my_date = 1979-05-27T07:32:00Z
|
|
|
|
+++
|
|
|
|
+++
|
|
|
|
Front Matter with Ordered Pages`)
|
|
|
|
Front Matter with Ordered Pages`)
|
|
|
|
|
|
|
|
|
|
|
|
var WEIGHTED_PAGE_2 = []byte(`+++
|
|
|
|
var weightedPage2 = []byte(`+++
|
|
|
|
weight = "6"
|
|
|
|
weight = "6"
|
|
|
|
title = "Two"
|
|
|
|
title = "Two"
|
|
|
|
publishdate = "2012-03-05"
|
|
|
|
publishdate = "2012-03-05"
|
|
|
@@ -697,7 +697,7 @@ my_param = "foo"
|
|
|
|
+++
|
|
|
|
+++
|
|
|
|
Front Matter with Ordered Pages 2`)
|
|
|
|
Front Matter with Ordered Pages 2`)
|
|
|
|
|
|
|
|
|
|
|
|
var WEIGHTED_PAGE_3 = []byte(`+++
|
|
|
|
var weightedPage3 = []byte(`+++
|
|
|
|
weight = "4"
|
|
|
|
weight = "4"
|
|
|
|
title = "Three"
|
|
|
|
title = "Three"
|
|
|
|
date = "2012-04-06"
|
|
|
|
date = "2012-04-06"
|
|
|
@@ -708,7 +708,7 @@ my_date = 2010-05-27T07:32:00Z
|
|
|
|
+++
|
|
|
|
+++
|
|
|
|
Front Matter with Ordered Pages 3`)
|
|
|
|
Front Matter with Ordered Pages 3`)
|
|
|
|
|
|
|
|
|
|
|
|
var WEIGHTED_PAGE_4 = []byte(`+++
|
|
|
|
var weightedPage4 = []byte(`+++
|
|
|
|
weight = "4"
|
|
|
|
weight = "4"
|
|
|
|
title = "Four"
|
|
|
|
title = "Four"
|
|
|
|
date = "2012-01-01"
|
|
|
|
date = "2012-01-01"
|
|
|
@@ -718,11 +718,11 @@ my_date = 2010-05-27T07:32:00Z
|
|
|
|
+++
|
|
|
|
+++
|
|
|
|
Front Matter with Ordered Pages 4. This is longer content`)
|
|
|
|
Front Matter with Ordered Pages 4. This is longer content`)
|
|
|
|
|
|
|
|
|
|
|
|
var WEIGHTED_SOURCES = []source.ByteSource{
|
|
|
|
var weightedSources = []source.ByteSource{
|
|
|
|
{filepath.FromSlash("sect/doc1.md"), WEIGHTED_PAGE_1},
|
|
|
|
{filepath.FromSlash("sect/doc1.md"), weightedPage1},
|
|
|
|
{filepath.FromSlash("sect/doc2.md"), WEIGHTED_PAGE_2},
|
|
|
|
{filepath.FromSlash("sect/doc2.md"), weightedPage2},
|
|
|
|
{filepath.FromSlash("sect/doc3.md"), WEIGHTED_PAGE_3},
|
|
|
|
{filepath.FromSlash("sect/doc3.md"), weightedPage3},
|
|
|
|
{filepath.FromSlash("sect/doc4.md"), WEIGHTED_PAGE_4},
|
|
|
|
{filepath.FromSlash("sect/doc4.md"), weightedPage4},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestOrderedPages(t *testing.T) {
|
|
|
|
func TestOrderedPages(t *testing.T) {
|
|
|
@@ -733,7 +733,7 @@ func TestOrderedPages(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
viper.Set("baseurl", "http://auth/bub")
|
|
|
|
viper.Set("baseurl", "http://auth/bub")
|
|
|
|
s := &Site{
|
|
|
|
s := &Site{
|
|
|
|
Source: &source.InMemorySource{ByteSource: WEIGHTED_SOURCES},
|
|
|
|
Source: &source.InMemorySource{ByteSource: weightedSources},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.initializeSiteInfo()
|
|
|
|
s.initializeSiteInfo()
|
|
|
|
|
|
|
|
|
|
|
@@ -786,11 +786,11 @@ func TestOrderedPages(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var GROUPED_SOURCES = []source.ByteSource{
|
|
|
|
var groupedSources = []source.ByteSource{
|
|
|
|
{filepath.FromSlash("sect1/doc1.md"), WEIGHTED_PAGE_1},
|
|
|
|
{filepath.FromSlash("sect1/doc1.md"), weightedPage1},
|
|
|
|
{filepath.FromSlash("sect1/doc2.md"), WEIGHTED_PAGE_2},
|
|
|
|
{filepath.FromSlash("sect1/doc2.md"), weightedPage2},
|
|
|
|
{filepath.FromSlash("sect2/doc3.md"), WEIGHTED_PAGE_3},
|
|
|
|
{filepath.FromSlash("sect2/doc3.md"), weightedPage3},
|
|
|
|
{filepath.FromSlash("sect3/doc4.md"), WEIGHTED_PAGE_4},
|
|
|
|
{filepath.FromSlash("sect3/doc4.md"), weightedPage4},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestGroupedPages(t *testing.T) {
|
|
|
|
func TestGroupedPages(t *testing.T) {
|
|
|
@@ -807,7 +807,7 @@ func TestGroupedPages(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
viper.Set("baseurl", "http://auth/bub")
|
|
|
|
viper.Set("baseurl", "http://auth/bub")
|
|
|
|
s := &Site{
|
|
|
|
s := &Site{
|
|
|
|
Source: &source.InMemorySource{ByteSource: GROUPED_SOURCES},
|
|
|
|
Source: &source.InMemorySource{ByteSource: groupedSources},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.initializeSiteInfo()
|
|
|
|
s.initializeSiteInfo()
|
|
|
|
|
|
|
|
|
|
|
@@ -950,7 +950,7 @@ func TestGroupedPages(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var PAGE_WITH_WEIGHTED_TAXONOMIES_2 = []byte(`+++
|
|
|
|
var pageWithWeightedTaxonomies1 = []byte(`+++
|
|
|
|
tags = [ "a", "b", "c" ]
|
|
|
|
tags = [ "a", "b", "c" ]
|
|
|
|
tags_weight = 22
|
|
|
|
tags_weight = 22
|
|
|
|
categories = ["d"]
|
|
|
|
categories = ["d"]
|
|
|
@@ -959,7 +959,7 @@ categories_weight = 44
|
|
|
|
+++
|
|
|
|
+++
|
|
|
|
Front Matter with weighted tags and categories`)
|
|
|
|
Front Matter with weighted tags and categories`)
|
|
|
|
|
|
|
|
|
|
|
|
var PAGE_WITH_WEIGHTED_TAXONOMIES_1 = []byte(`+++
|
|
|
|
var pageWithWeightedTaxonomies2 = []byte(`+++
|
|
|
|
tags = "a"
|
|
|
|
tags = "a"
|
|
|
|
tags_weight = 33
|
|
|
|
tags_weight = 33
|
|
|
|
title = "bar"
|
|
|
|
title = "bar"
|
|
|
@@ -970,7 +970,7 @@ date = 1979-05-27T07:32:00Z
|
|
|
|
+++
|
|
|
|
+++
|
|
|
|
Front Matter with weighted tags and categories`)
|
|
|
|
Front Matter with weighted tags and categories`)
|
|
|
|
|
|
|
|
|
|
|
|
var PAGE_WITH_WEIGHTED_TAXONOMIES_3 = []byte(`+++
|
|
|
|
var pageWithWeightedTaxonomies3 = []byte(`+++
|
|
|
|
title = "bza"
|
|
|
|
title = "bza"
|
|
|
|
categories = [ "e" ]
|
|
|
|
categories = [ "e" ]
|
|
|
|
categories_weight = 11
|
|
|
|
categories_weight = 11
|
|
|
@@ -985,9 +985,9 @@ func TestWeightedTaxonomies(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
hugofs.InitMemFs()
|
|
|
|
hugofs.InitMemFs()
|
|
|
|
sources := []source.ByteSource{
|
|
|
|
sources := []source.ByteSource{
|
|
|
|
{filepath.FromSlash("sect/doc1.md"), PAGE_WITH_WEIGHTED_TAXONOMIES_1},
|
|
|
|
{filepath.FromSlash("sect/doc1.md"), pageWithWeightedTaxonomies2},
|
|
|
|
{filepath.FromSlash("sect/doc2.md"), PAGE_WITH_WEIGHTED_TAXONOMIES_2},
|
|
|
|
{filepath.FromSlash("sect/doc2.md"), pageWithWeightedTaxonomies1},
|
|
|
|
{filepath.FromSlash("sect/doc3.md"), PAGE_WITH_WEIGHTED_TAXONOMIES_3},
|
|
|
|
{filepath.FromSlash("sect/doc3.md"), pageWithWeightedTaxonomies3},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
taxonomies := make(map[string]string)
|
|
|
|
taxonomies := make(map[string]string)
|
|
|
|
|
|
|
|
|
|
|
|