| 
									
										
										
										
											2016-03-22 00:28:42 +01:00
										 |  |  | // Copyright 2016 The Hugo Authors. All rights reserved.
 | 
					
						
							| 
									
										
										
										
											2015-12-10 15:19:38 -07:00
										 |  |  | //
 | 
					
						
							|  |  |  | // Licensed under the Apache License, Version 2.0 (the "License");
 | 
					
						
							|  |  |  | // you may not use this file except in compliance with the License.
 | 
					
						
							|  |  |  | // You may obtain a copy of the License at
 | 
					
						
							|  |  |  | // http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Unless required by applicable law or agreed to in writing, software
 | 
					
						
							|  |  |  | // distributed under the License is distributed on an "AS IS" BASIS,
 | 
					
						
							|  |  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					
						
							|  |  |  | // See the License for the specific language governing permissions and
 | 
					
						
							|  |  |  | // limitations under the License.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-23 14:47:03 -07:00
										 |  |  | package hugolib
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	"fmt"
 | 
					
						
							| 
									
										
										
										
											2015-05-20 02:21:21 -04:00
										 |  |  | 	"path/filepath"
 | 
					
						
							|  |  |  | 	"strings"
 | 
					
						
							|  |  |  | 	"testing"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 21:11:44 +02:00
										 |  |  | 	"github.com/bep/inflect"
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 	jww "github.com/spf13/jwalterweatherman"
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 11:44:13 -04:00
										 |  |  | 	"github.com/spf13/hugo/helpers"
 | 
					
						
							|  |  |  | 	"github.com/spf13/hugo/source"
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	"github.com/spf13/hugo/deps"
 | 
					
						
							|  |  |  | 	"github.com/spf13/hugo/hugofs"
 | 
					
						
							| 
									
										
										
										
											2015-05-28 03:19:59 +02:00
										 |  |  | 	"github.com/stretchr/testify/assert"
 | 
					
						
							| 
									
										
										
										
											2016-08-01 23:04:44 +02:00
										 |  |  | 	"github.com/stretchr/testify/require"
 | 
					
						
							| 
									
										
										
										
											2013-08-23 14:47:03 -07:00
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-18 10:27:56 -07:00
										 |  |  | const (
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | 	pageSimpleTitle = `---
 | 
					
						
							| 
									
										
										
										
											2013-08-23 14:47:03 -07:00
										 |  |  | title: simple template
 | 
					
						
							|  |  |  | ---
 | 
					
						
							|  |  |  | content`
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | 	templateMissingFunc = "{{ .Title | funcdoesnotexists }}"
 | 
					
						
							|  |  |  | 	templateWithURLAbs  = "<a href=\"/foobar.jpg\">Going</a>"
 | 
					
						
							| 
									
										
										
										
											2013-09-18 10:27:56 -07:00
										 |  |  | )
 | 
					
						
							| 
									
										
										
										
											2013-09-01 12:02:05 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-09 14:05:31 +01:00
										 |  |  | func init() {
 | 
					
						
							|  |  |  | 	testMode = true
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 15:01:06 +02:00
										 |  |  | func pageMust(p *Page, err error) *Page {
 | 
					
						
							|  |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		panic(err)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return p
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | func TestRenderWithInvalidTemplate(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							|  |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("content", "foo.md"), "foo")
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	withTemplate := createWithTemplateFromNameValues("missing", templateMissingFunc)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg, WithTemplate: withTemplate}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	errCount := s.Log.LogCountForLevelsGreaterThanorEqualTo(jww.LevelError)
 | 
					
						
							| 
									
										
										
										
											2017-01-10 01:36:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	// TODO(bep) clean up the template error handling
 | 
					
						
							| 
									
										
										
										
											2017-01-10 01:36:59 +01:00
										 |  |  | 	// The template errors are stored in a slice etc. so we get 4 log entries
 | 
					
						
							|  |  |  | 	// When we should get only 1
 | 
					
						
							|  |  |  | 	if errCount == 0 {
 | 
					
						
							|  |  |  | 		t.Fatalf("Expecting the template to log 1 ERROR, got %d", errCount)
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2013-08-30 14:38:33 -07:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2013-08-29 09:37:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | func TestDraftAndFutureRender(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("sect/doc1.md"), Content: []byte("---\ntitle: doc1\ndraft: true\npublishdate: \"2414-05-29\"\n---\n# doc1\n*some content*")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc2.md"), Content: []byte("---\ntitle: doc2\ndraft: true\npublishdate: \"2012-05-29\"\n---\n# doc2\n*some content*")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc3.md"), Content: []byte("---\ntitle: doc3\ndraft: false\npublishdate: \"2414-05-29\"\n---\n# doc3\n*some content*")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc4.md"), Content: []byte("---\ntitle: doc4\ndraft: false\npublishdate: \"2012-05-29\"\n---\n# doc4\n*some content*")},
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	siteSetup := func(t *testing.T, configKeyValues ...interface{}) *Site {
 | 
					
						
							|  |  |  | 		cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		cfg.Set("baseURL", "http://auth/bub")
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for i := 0; i < len(configKeyValues); i += 2 {
 | 
					
						
							|  |  |  | 			cfg.Set(configKeyValues[i].(string), configKeyValues[i+1])
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for _, src := range sources {
 | 
					
						
							|  |  |  | 			writeSource(t, fs, filepath.Join("content", src.Name), string(src.Content))
 | 
					
						
							| 
									
										
										
										
											2015-06-21 15:01:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2016-05-14 00:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 		return buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2015-06-21 15:01:06 +02:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | 	// Testing Defaults.. Only draft:true and publishDate in the past should be rendered
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 	s := siteSetup(t)
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	if len(s.RegularPages) != 1 {
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | 		t.Fatal("Draft or Future dated content published unexpectedly")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// only publishDate in the past should be rendered
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s = siteSetup(t, "buildDrafts", true)
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	if len(s.RegularPages) != 2 {
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | 		t.Fatal("Future Dated Posts published unexpectedly")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//  drafts should not be rendered, but all dates should
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s = siteSetup(t,
 | 
					
						
							|  |  |  | 		"buildDrafts", false,
 | 
					
						
							|  |  |  | 		"buildFuture", true)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	if len(s.RegularPages) != 2 {
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | 		t.Fatal("Draft posts published unexpectedly")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// all 4 should be included
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s = siteSetup(t,
 | 
					
						
							|  |  |  | 		"buildDrafts", true,
 | 
					
						
							|  |  |  | 		"buildFuture", true)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	if len(s.RegularPages) != 4 {
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | 		t.Fatal("Drafts or Future posts not included as expected")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2015-06-21 15:01:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 00:48:40 -04:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | func TestFutureExpirationRender(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("sect/doc3.md"), Content: []byte("---\ntitle: doc1\nexpirydate: \"2400-05-29\"\n---\n# doc1\n*some content*")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc4.md"), Content: []byte("---\ntitle: doc2\nexpirydate: \"2000-05-29\"\n---\n# doc2\n*some content*")},
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 	siteSetup := func(t *testing.T) *Site {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 		cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 		cfg.Set("baseURL", "http://auth/bub")
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for _, src := range sources {
 | 
					
						
							|  |  |  | 			writeSource(t, fs, filepath.Join("content", src.Name), string(src.Content))
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2016-05-14 00:35:16 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 		return buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 	s := siteSetup(t)
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 00:35:16 -04:00
										 |  |  | 	if len(s.AllPages) != 1 {
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 		if len(s.RegularPages) > 1 {
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | 			t.Fatal("Expired content published unexpectedly")
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 		if len(s.RegularPages) < 1 {
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | 			t.Fatal("Valid content expired unexpectedly")
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-14 00:35:16 -04:00
										 |  |  | 	if s.AllPages[0].Title == "doc2" {
 | 
					
						
							| 
									
										
										
										
											2016-05-11 10:04:53 -04:00
										 |  |  | 		t.Fatal("Expired content published unexpectedly")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-19 11:15:08 +01:00
										 |  |  | func TestLastChange(t *testing.T) {
 | 
					
						
							|  |  |  | 	t.Parallel()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("content", "sect/doc1.md"), "---\ntitle: doc1\nweight: 1\ndate: 2014-05-29\n---\n# doc1\n*some content*")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("content", "sect/doc2.md"), "---\ntitle: doc2\nweight: 2\ndate: 2015-05-29\n---\n# doc2\n*some content*")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("content", "sect/doc3.md"), "---\ntitle: doc3\nweight: 3\ndate: 2017-05-29\n---\n# doc3\n*some content*")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("content", "sect/doc4.md"), "---\ntitle: doc4\nweight: 4\ndate: 2016-05-29\n---\n# doc4\n*some content*")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("content", "sect/doc5.md"), "---\ntitle: doc5\nweight: 3\n---\n# doc5\n*some content*")
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	require.False(t, s.Info.LastChange.IsZero(), "Site.LastChange is zero")
 | 
					
						
							|  |  |  | 	require.Equal(t, 2017, s.Info.LastChange.Year(), "Site.LastChange should be set to the page with latest Lastmod (year 2017)")
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-25 09:56:00 +01:00
										 |  |  | // Issue #_index
 | 
					
						
							|  |  |  | func TestPageWithUnderScoreIndexInFilename(t *testing.T) {
 | 
					
						
							|  |  |  | 	t.Parallel()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("content", "sect/my_index_file.md"), "---\ntitle: doc1\nweight: 1\ndate: 2014-05-29\n---\n# doc1\n*some content*")
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	require.Len(t, s.RegularPages, 1)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | // Issue #957
 | 
					
						
							|  |  |  | func TestCrossrefs(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | 	for _, uglyURLs := range []bool{true, false} {
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 		for _, relative := range []bool{true, false} {
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | 			doTestCrossrefs(t, relative, uglyURLs)
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | func doTestCrossrefs(t *testing.T, relative, uglyURLs bool) {
 | 
					
						
							| 
									
										
										
										
											2015-05-20 02:21:21 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | 	baseURL := "http://foo/bar"
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var refShortcode string
 | 
					
						
							|  |  |  | 	var expectedBase string
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | 	var expectedURLSuffix string
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 	var expectedPathSuffix string
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if relative {
 | 
					
						
							|  |  |  | 		refShortcode = "relref"
 | 
					
						
							|  |  |  | 		expectedBase = "/bar"
 | 
					
						
							|  |  |  | 	} else {
 | 
					
						
							|  |  |  | 		refShortcode = "ref"
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | 		expectedBase = baseURL
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | 	if uglyURLs {
 | 
					
						
							|  |  |  | 		expectedURLSuffix = ".html"
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 		expectedPathSuffix = ".html"
 | 
					
						
							|  |  |  | 	} else {
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | 		expectedURLSuffix = "/"
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 		expectedPathSuffix = "/index.html"
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{
 | 
					
						
							|  |  |  | 			Name:    filepath.FromSlash("sect/doc1.md"),
 | 
					
						
							|  |  |  | 			Content: []byte(fmt.Sprintf(`Ref 2: {{< %s "sect/doc2.md" >}}`, refShortcode)),
 | 
					
						
							|  |  |  | 		},
 | 
					
						
							| 
									
										
										
										
											2015-06-21 13:08:30 +02:00
										 |  |  | 		// Issue #1148: Make sure that no P-tags is added around shortcodes.
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{
 | 
					
						
							|  |  |  | 			Name: filepath.FromSlash("sect/doc2.md"),
 | 
					
						
							| 
									
										
										
										
											2016-10-24 20:56:00 +02:00
										 |  |  | 			Content: []byte(fmt.Sprintf(`**Ref 1:**
 | 
					
						
							| 
									
										
										
										
											2015-08-04 11:59:32 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 13:08:30 +02:00
										 |  |  | {{< %s "sect/doc1.md" >}}
 | 
					
						
							| 
									
										
										
										
											2015-08-04 11:59:32 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | THE END.`, refShortcode)),
 | 
					
						
							|  |  |  | 		},
 | 
					
						
							| 
									
										
										
										
											2016-01-04 23:48:05 +01:00
										 |  |  | 		// Issue #1753: Should not add a trailing newline after shortcode.
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{
 | 
					
						
							|  |  |  | 			Name:    filepath.FromSlash("sect/doc3.md"),
 | 
					
						
							|  |  |  | 			Content: []byte(fmt.Sprintf(`**Ref 1:**{{< %s "sect/doc3.md" >}}.`, refShortcode)),
 | 
					
						
							|  |  |  | 		},
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cfg.Set("baseURL", baseURL)
 | 
					
						
							|  |  |  | 	cfg.Set("uglyURLs", uglyURLs)
 | 
					
						
							|  |  |  | 	cfg.Set("verbose", true)
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	for _, src := range sources {
 | 
					
						
							|  |  |  | 		writeSource(t, fs, filepath.Join("content", src.Name), string(src.Content))
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	s := buildSingleSite(
 | 
					
						
							|  |  |  | 		t,
 | 
					
						
							|  |  |  | 		deps.DepsCfg{
 | 
					
						
							|  |  |  | 			Fs:           fs,
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 			Cfg:          cfg,
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 			WithTemplate: createWithTemplateFromNameValues("_default/single.html", "{{.Content}}")},
 | 
					
						
							|  |  |  | 		BuildCfg{})
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	if len(s.RegularPages) != 3 {
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		t.Fatalf("Expected 3 got %d pages", len(s.AllPages))
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 20:52:50 +01:00
										 |  |  | 	th := testHelper{s.Cfg, s.Fs, t}
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 	tests := []struct {
 | 
					
						
							|  |  |  | 		doc      string
 | 
					
						
							|  |  |  | 		expected string
 | 
					
						
							|  |  |  | 	}{
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 		{filepath.FromSlash(fmt.Sprintf("public/sect/doc1%s", expectedPathSuffix)), fmt.Sprintf("<p>Ref 2: %s/sect/doc2%s</p>\n", expectedBase, expectedURLSuffix)},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash(fmt.Sprintf("public/sect/doc2%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong></p>\n\n%s/sect/doc1%s\n\n<p>THE END.</p>\n", expectedBase, expectedURLSuffix)},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash(fmt.Sprintf("public/sect/doc3%s", expectedPathSuffix)), fmt.Sprintf("<p><strong>Ref 1:</strong>%s/sect/doc3%s.</p>\n", expectedBase, expectedURLSuffix)},
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, test := range tests {
 | 
					
						
							| 
									
										
										
										
											2017-02-17 21:14:52 +01:00
										 |  |  | 		th.assertFileContent(test.doc, test.expected)
 | 
					
						
							| 
									
										
										
										
											2015-03-17 18:14:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-17 15:38:48 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | // Issue #939
 | 
					
						
							| 
									
										
										
										
											2016-03-05 20:18:17 +01:00
										 |  |  | // Issue #1923
 | 
					
						
							|  |  |  | func TestShouldAlwaysHaveUglyURLs(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2015-03-11 11:34:57 -06:00
										 |  |  | 	for _, uglyURLs := range []bool{true, false} {
 | 
					
						
							| 
									
										
										
										
											2016-03-05 20:18:17 +01:00
										 |  |  | 		doTestShouldAlwaysHaveUglyURLs(t, uglyURLs)
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-05 20:18:17 +01:00
										 |  |  | func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cfg.Set("verbose", true)
 | 
					
						
							|  |  |  | 	cfg.Set("baseURL", "http://auth/bub")
 | 
					
						
							|  |  |  | 	cfg.Set("disableSitemap", false)
 | 
					
						
							|  |  |  | 	cfg.Set("disableRSS", false)
 | 
					
						
							|  |  |  | 	cfg.Set("rssURI", "index.xml")
 | 
					
						
							|  |  |  | 	cfg.Set("blackfriday",
 | 
					
						
							| 
									
										
										
										
											2016-03-05 20:18:17 +01:00
										 |  |  | 		map[string]interface{}{
 | 
					
						
							| 
									
										
										
										
											2016-10-24 21:33:11 +02:00
										 |  |  | 			"plainIDAnchors": true})
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg.Set("uglyURLs", uglyURLs)
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("sect/doc1.md"), Content: []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc2.md"), Content: []byte("---\nurl: /ugly.html\nmarkup: markdown\n---\n# title\ndoc2 *content*")},
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	for _, src := range sources {
 | 
					
						
							|  |  |  | 		writeSource(t, fs, filepath.Join("content", src.Name), string(src.Content))
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	writeSource(t, fs, filepath.Join("layouts", "index.html"), "Home Sweet {{ if.IsHome  }}Home{{ end }}.")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("layouts", "_default/single.html"), "{{.Content}}{{ if.IsHome  }}This is not home!{{ end }}")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("layouts", "404.html"), "Page Not Found.{{ if.IsHome  }}This is not home!{{ end }}")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("layouts", "rss.xml"), "<root>RSS</root>")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("layouts", "sitemap.xml"), "<root>SITEMAP</root>")
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 	var expectedPagePath string
 | 
					
						
							| 
									
										
										
										
											2015-03-11 11:34:57 -06:00
										 |  |  | 	if uglyURLs {
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		expectedPagePath = "public/sect/doc1.html"
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 	} else {
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		expectedPagePath = "public/sect/doc1/index.html"
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tests := []struct {
 | 
					
						
							|  |  |  | 		doc      string
 | 
					
						
							|  |  |  | 		expected string
 | 
					
						
							|  |  |  | 	}{
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		{filepath.FromSlash("public/index.html"), "Home Sweet Home."},
 | 
					
						
							| 
									
										
										
										
											2016-03-06 00:41:11 +01:00
										 |  |  | 		{filepath.FromSlash(expectedPagePath), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		{filepath.FromSlash("public/404.html"), "Page Not Found."},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/index.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n<root>RSS</root>"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/sitemap.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n<root>SITEMAP</root>"},
 | 
					
						
							| 
									
										
										
										
											2016-03-05 20:18:17 +01:00
										 |  |  | 		// Issue #1923
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		{filepath.FromSlash("public/ugly.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>doc2 <em>content</em></p>\n"},
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	for _, p := range s.RegularPages {
 | 
					
						
							| 
									
										
										
										
											2016-10-30 17:59:24 +01:00
										 |  |  | 		assert.False(t, p.IsHome())
 | 
					
						
							| 
									
										
										
										
											2015-05-28 03:19:59 +02:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 	for _, test := range tests {
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 		content := readDestination(t, fs, test.doc)
 | 
					
						
							| 
									
										
										
										
											2015-03-17 18:14:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if content != test.expected {
 | 
					
						
							|  |  |  | 			t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content)
 | 
					
						
							| 
									
										
										
										
											2015-03-07 15:18:00 +01:00
										 |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-15 10:00:34 +01:00
										 |  |  | func TestNewSiteDefaultLang(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2017-02-15 10:00:34 +01:00
										 |  |  | 	s, err := NewSiteDefaultLang()
 | 
					
						
							|  |  |  | 	require.NoError(t, err)
 | 
					
						
							|  |  |  | 	require.Equal(t, hugofs.Os, s.Fs.Source)
 | 
					
						
							|  |  |  | 	require.Equal(t, hugofs.Os, s.Fs.Destination)
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:05:13 +02:00
										 |  |  | // Issue #1176
 | 
					
						
							|  |  |  | func TestSectionNaming(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:05:13 +02:00
										 |  |  | 	for _, canonify := range []bool{true, false} {
 | 
					
						
							|  |  |  | 		for _, uglify := range []bool{true, false} {
 | 
					
						
							|  |  |  | 			for _, pluralize := range []bool{true, false} {
 | 
					
						
							|  |  |  | 				doTestSectionNaming(t, canonify, uglify, pluralize)
 | 
					
						
							|  |  |  | 			}
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func doTestSectionNaming(t *testing.T, canonify, uglify, pluralize bool) {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var expectedPathSuffix string
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if uglify {
 | 
					
						
							|  |  |  | 		expectedPathSuffix = ".html"
 | 
					
						
							|  |  |  | 	} else {
 | 
					
						
							|  |  |  | 		expectedPathSuffix = "/index.html"
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("sect/doc1.html"), Content: []byte("doc1")},
 | 
					
						
							| 
									
										
										
										
											2017-04-07 13:03:34 +02:00
										 |  |  | 		// Add one more page to sect to make sure sect is picked in mainSections
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/sect.html"), Content: []byte("sect")},
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("Fish and Chips/doc2.html"), Content: []byte("doc2")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("ラーメン/doc3.html"), Content: []byte("doc3")},
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:05:13 +02:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cfg.Set("baseURL", "http://auth/sub/")
 | 
					
						
							|  |  |  | 	cfg.Set("uglyURLs", uglify)
 | 
					
						
							|  |  |  | 	cfg.Set("pluralizeListTitles", pluralize)
 | 
					
						
							|  |  |  | 	cfg.Set("canonifyURLs", canonify)
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-08 23:34:52 +01:00
										 |  |  | 	for _, source := range sources {
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 		writeSource(t, fs, filepath.Join("content", source.Name), string(source.Content))
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:05:13 +02:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	writeSource(t, fs, filepath.Join("layouts", "_default/single.html"), "{{.Content}}")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("layouts", "_default/list.html"), "{{.Title}}")
 | 
					
						
							| 
									
										
										
										
											2016-11-08 23:34:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2017-04-07 13:03:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mainSections, err := s.Info.Param("mainSections")
 | 
					
						
							|  |  |  | 	require.NoError(t, err)
 | 
					
						
							|  |  |  | 	require.Equal(t, mainSections, []string{"sect"})
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 20:52:50 +01:00
										 |  |  | 	th := testHelper{s.Cfg, s.Fs, t}
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:05:13 +02:00
										 |  |  | 	tests := []struct {
 | 
					
						
							|  |  |  | 		doc         string
 | 
					
						
							|  |  |  | 		pluralAware bool
 | 
					
						
							|  |  |  | 		expected    string
 | 
					
						
							|  |  |  | 	}{
 | 
					
						
							|  |  |  | 		{filepath.FromSlash(fmt.Sprintf("sect/doc1%s", expectedPathSuffix)), false, "doc1"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash(fmt.Sprintf("sect%s", expectedPathSuffix)), true, "Sect"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash(fmt.Sprintf("fish-and-chips/doc2%s", expectedPathSuffix)), false, "doc2"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash(fmt.Sprintf("fish-and-chips%s", expectedPathSuffix)), true, "Fish and Chips"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash(fmt.Sprintf("ラーメン/doc3%s", expectedPathSuffix)), false, "doc3"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash(fmt.Sprintf("ラーメン%s", expectedPathSuffix)), true, "ラーメン"},
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, test := range tests {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if test.pluralAware && pluralize {
 | 
					
						
							|  |  |  | 			test.expected = inflect.Pluralize(test.expected)
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 21:14:52 +01:00
										 |  |  | 		th.assertFileContent(filepath.Join("public", test.doc), test.expected)
 | 
					
						
							| 
									
										
										
										
											2015-05-28 23:05:13 +02:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2013-09-18 14:21:27 -07:00
										 |  |  | func TestSkipRender(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("sect/doc1.html"), Content: []byte("---\nmarkup: markdown\n---\n# title\nsome *content*")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc2.html"), Content: []byte("<!doctype html><html><body>more content</body></html>")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc3.md"), Content: []byte("# doc3\n*some* content")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc4.md"), Content: []byte("---\ntitle: doc4\n---\n# doc4\n*some content*")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc5.html"), Content: []byte("<!doctype html><html>{{ template \"head\" }}<body>body5</body></html>")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc6.html"), Content: []byte("<!doctype html><html>{{ template \"head_abs\" }}<body>body5</body></html>")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("doc7.html"), Content: []byte("<html><body>doc7 content</body></html>")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc8.html"), Content: []byte("---\nmarkup: md\n---\n# title\nsome *content*")},
 | 
					
						
							| 
									
										
										
										
											2017-02-10 17:26:28 +07:00
										 |  |  | 		// Issue #3021
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("doc9.html"), Content: []byte("<html><body>doc9: {{< myshortcode >}}</body></html>")},
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg.Set("verbose", true)
 | 
					
						
							|  |  |  | 	cfg.Set("canonifyURLs", true)
 | 
					
						
							|  |  |  | 	cfg.Set("uglyURLs", true)
 | 
					
						
							|  |  |  | 	cfg.Set("baseURL", "http://auth/bub")
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for _, src := range sources {
 | 
					
						
							|  |  |  | 		writeSource(t, fs, filepath.Join("content", src.Name), string(src.Content))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	writeSource(t, fs, filepath.Join("layouts", "_default/single.html"), "{{.Content}}")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("layouts", "head"), "<head><script src=\"script.js\"></script></head>")
 | 
					
						
							|  |  |  | 	writeSource(t, fs, filepath.Join("layouts", "head_abs"), "<head><script src=\"/script.js\"></script></head>")
 | 
					
						
							| 
									
										
										
										
											2017-02-10 17:26:28 +07:00
										 |  |  | 	writeSource(t, fs, filepath.Join("layouts", "shortcodes", "myshortcode.html"), "SHORT")
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	tests := []struct {
 | 
					
						
							|  |  |  | 		doc      string
 | 
					
						
							|  |  |  | 		expected string
 | 
					
						
							|  |  |  | 	}{
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 		{filepath.FromSlash("public/sect/doc1.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/sect/doc2.html"), "<!doctype html><html><body>more content</body></html>"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/sect/doc3.html"), "\n\n<h1 id=\"doc3\">doc3</h1>\n\n<p><em>some</em> content</p>\n"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/sect/doc4.html"), "\n\n<h1 id=\"doc4\">doc4</h1>\n\n<p><em>some content</em></p>\n"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/sect/doc5.html"), "<!doctype html><html><head><script src=\"script.js\"></script></head><body>body5</body></html>"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/sect/doc6.html"), "<!doctype html><html><head><script src=\"http://auth/bub/script.js\"></script></head><body>body5</body></html>"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/doc7.html"), "<html><body>doc7 content</body></html>"},
 | 
					
						
							|  |  |  | 		{filepath.FromSlash("public/sect/doc8.html"), "\n\n<h1 id=\"title\">title</h1>\n\n<p>some <em>content</em></p>\n"},
 | 
					
						
							| 
									
										
										
										
											2017-02-10 17:26:28 +07:00
										 |  |  | 		{filepath.FromSlash("public/doc9.html"), "<html><body>doc9: SHORT</body></html>"},
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, test := range tests {
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 		file, err := fs.Destination.Open(test.doc)
 | 
					
						
							| 
									
										
										
										
											2014-11-04 00:41:47 -05:00
										 |  |  | 		if err != nil {
 | 
					
						
							|  |  |  | 			t.Fatalf("Did not find %s in target.", test.doc)
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 		}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-17 18:14:29 +01:00
										 |  |  | 		content := helpers.ReaderToString(file)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if content != test.expected {
 | 
					
						
							|  |  |  | 			t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content)
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2013-09-18 14:21:27 -07:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-08 23:27:55 -06:00
										 |  |  | func TestAbsURLify(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("sect/doc1.html"), Content: []byte("<!doctype html><html><head></head><body><a href=\"#frag1\">link</a></body></html>")},
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 		{Name: filepath.FromSlash("blue/doc2.html"), Content: []byte("---\nf: t\n---\n<!doctype html><html><body>more content</body></html>")},
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2016-04-17 19:55:38 +02:00
										 |  |  | 	for _, baseURL := range []string{"http://auth/bub", "http://base", "//base"} {
 | 
					
						
							|  |  |  | 		for _, canonify := range []bool{true, false} {
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 			cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			cfg.Set("uglyURLs", true)
 | 
					
						
							|  |  |  | 			cfg.Set("canonifyURLs", canonify)
 | 
					
						
							|  |  |  | 			cfg.Set("baseURL", baseURL)
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for _, src := range sources {
 | 
					
						
							|  |  |  | 				writeSource(t, fs, filepath.Join("content", src.Name), string(src.Content))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 			}
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 			writeSource(t, fs, filepath.Join("layouts", "blue/single.html"), templateWithURLAbs)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 			s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2017-02-17 20:52:50 +01:00
										 |  |  | 			th := testHelper{s.Cfg, s.Fs, t}
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 19:55:38 +02:00
										 |  |  | 			tests := []struct {
 | 
					
						
							|  |  |  | 				file, expected string
 | 
					
						
							|  |  |  | 			}{
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 				{"public/blue/doc2.html", "<a href=\"%s/foobar.jpg\">Going</a>"},
 | 
					
						
							|  |  |  | 				{"public/sect/doc1.html", "<!doctype html><html><head></head><body><a href=\"#frag1\">link</a></body></html>"},
 | 
					
						
							| 
									
										
										
										
											2016-04-17 19:55:38 +02:00
										 |  |  | 			}
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 19:55:38 +02:00
										 |  |  | 			for _, test := range tests {
 | 
					
						
							| 
									
										
										
										
											2014-11-04 00:41:47 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 19:55:38 +02:00
										 |  |  | 				expected := test.expected
 | 
					
						
							| 
									
										
										
										
											2015-03-17 18:14:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-17 19:55:38 +02:00
										 |  |  | 				if strings.Contains(expected, "%s") {
 | 
					
						
							|  |  |  | 					expected = fmt.Sprintf(expected, baseURL)
 | 
					
						
							|  |  |  | 				}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if !canonify {
 | 
					
						
							|  |  |  | 					expected = strings.Replace(expected, baseURL, "", -1)
 | 
					
						
							|  |  |  | 				}
 | 
					
						
							| 
									
										
										
										
											2015-03-17 18:14:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 21:14:52 +01:00
										 |  |  | 				th.assertFileContent(test.file, expected)
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 			}
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2013-09-17 14:16:06 -07:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var weightedPage1 = []byte(`+++
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | weight = "2"
 | 
					
						
							|  |  |  | title = "One"
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | my_param = "foo"
 | 
					
						
							|  |  |  | my_date = 1979-05-27T07:32:00Z
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | +++
 | 
					
						
							|  |  |  | Front Matter with Ordered Pages`)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var weightedPage2 = []byte(`+++
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | weight = "6"
 | 
					
						
							|  |  |  | title = "Two"
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | publishdate = "2012-03-05"
 | 
					
						
							|  |  |  | my_param = "foo"
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | +++
 | 
					
						
							|  |  |  | Front Matter with Ordered Pages 2`)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var weightedPage3 = []byte(`+++
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | weight = "4"
 | 
					
						
							|  |  |  | title = "Three"
 | 
					
						
							|  |  |  | date = "2012-04-06"
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | publishdate = "2012-04-06"
 | 
					
						
							|  |  |  | my_param = "bar"
 | 
					
						
							|  |  |  | only_one = "yes"
 | 
					
						
							|  |  |  | my_date = 2010-05-27T07:32:00Z
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | +++
 | 
					
						
							|  |  |  | Front Matter with Ordered Pages 3`)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var weightedPage4 = []byte(`+++
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | weight = "4"
 | 
					
						
							|  |  |  | title = "Four"
 | 
					
						
							|  |  |  | date = "2012-01-01"
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | publishdate = "2012-01-01"
 | 
					
						
							|  |  |  | my_param = "baz"
 | 
					
						
							|  |  |  | my_date = 2010-05-27T07:32:00Z
 | 
					
						
							| 
									
										
										
										
											2016-10-28 14:46:33 +02:00
										 |  |  | categories = [ "hugo" ]
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | +++
 | 
					
						
							| 
									
										
										
										
											2013-12-20 09:10:05 -05:00
										 |  |  | Front Matter with Ordered Pages 4. This is longer content`)
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var weightedSources = []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 	{Name: filepath.FromSlash("sect/doc1.md"), Content: weightedPage1},
 | 
					
						
							|  |  |  | 	{Name: filepath.FromSlash("sect/doc2.md"), Content: weightedPage2},
 | 
					
						
							|  |  |  | 	{Name: filepath.FromSlash("sect/doc3.md"), Content: weightedPage3},
 | 
					
						
							|  |  |  | 	{Name: filepath.FromSlash("sect/doc4.md"), Content: weightedPage4},
 | 
					
						
							| 
									
										
										
										
											2013-11-05 05:29:37 +00:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | func TestOrderedPages(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							|  |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 	cfg.Set("baseURL", "http://auth/bub")
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for _, src := range weightedSources {
 | 
					
						
							|  |  |  | 		writeSource(t, fs, filepath.Join("content", src.Name), string(src.Content))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-28 09:30:58 +02:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	if s.Sections["sect"][0].Weight != 2 || s.Sections["sect"][3].Weight != 6 {
 | 
					
						
							| 
									
										
										
										
											2014-02-28 22:31:21 -07:00
										 |  |  | 		t.Errorf("Pages in unexpected order. First should be '%d', got '%d'", 2, s.Sections["sect"][0].Weight)
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if s.Sections["sect"][1].Page.Title != "Three" || s.Sections["sect"][2].Page.Title != "Four" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order. Second should be '%s', got '%s'", "Three", s.Sections["sect"][1].Page.Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	bydate := s.RegularPages.ByDate()
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if bydate[0].Title != "One" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "One", bydate[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rev := bydate.Reverse()
 | 
					
						
							|  |  |  | 	if rev[0].Title != "Three" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "Three", rev[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	bypubdate := s.RegularPages.ByPublishDate()
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if bypubdate[0].Title != "One" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "One", bypubdate[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rbypubdate := bypubdate.Reverse()
 | 
					
						
							|  |  |  | 	if rbypubdate[0].Title != "Three" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "Three", rbypubdate[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	bylength := s.RegularPages.ByLength()
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	if bylength[0].Title != "One" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "One", bylength[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rbylength := bylength.Reverse()
 | 
					
						
							|  |  |  | 	if rbylength[0].Title != "Four" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order. First should be '%s', got '%s'", "Four", rbylength[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2013-10-18 11:01:31 -04:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2013-10-24 15:24:47 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var groupedSources = []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 	{Name: filepath.FromSlash("sect1/doc1.md"), Content: weightedPage1},
 | 
					
						
							|  |  |  | 	{Name: filepath.FromSlash("sect1/doc2.md"), Content: weightedPage2},
 | 
					
						
							|  |  |  | 	{Name: filepath.FromSlash("sect2/doc3.md"), Content: weightedPage3},
 | 
					
						
							|  |  |  | 	{Name: filepath.FromSlash("sect3/doc4.md"), Content: weightedPage4},
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestGroupedPages(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2014-10-16 20:20:09 -04:00
										 |  |  | 	defer func() {
 | 
					
						
							|  |  |  | 		if r := recover(); r != nil {
 | 
					
						
							|  |  |  | 			fmt.Println("Recovered in f", r)
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}()
 | 
					
						
							| 
									
										
										
										
											2014-11-04 00:41:47 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 	cfg.Set("baseURL", "http://auth/bub")
 | 
					
						
							| 
									
										
										
										
											2015-06-21 15:01:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	writeSourcesToSource(t, "content", fs, groupedSources...)
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	rbysection, err := s.RegularPages.GroupBy("Section", "desc")
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		t.Fatalf("Unable to make PageGroup array: %s", err)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 	if rbysection[0].Key != "sect3" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. First group key should be '%s', got '%s'", "sect3", rbysection[0].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if rbysection[1].Key != "sect2" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Second group key should be '%s', got '%s'", "sect2", rbysection[1].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if rbysection[2].Key != "sect1" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Third group key should be '%s', got '%s'", "sect1", rbysection[2].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-08-29 23:48:24 -04:00
										 |  |  | 	if rbysection[0].Pages[0].Title != "Four" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has an unexpected page. First group's pages should have '%s', got '%s'", "Four", rbysection[0].Pages[0].Title)
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-08-29 23:48:24 -04:00
										 |  |  | 	if len(rbysection[2].Pages) != 2 {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has unexpected number of pages. Third group should have '%d' pages, got '%d' pages", 2, len(rbysection[2].Pages))
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	bytype, err := s.RegularPages.GroupBy("Type", "asc")
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		t.Fatalf("Unable to make PageGroup array: %s", err)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if bytype[0].Key != "sect1" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. First group key should be '%s', got '%s'", "sect1", bytype[0].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if bytype[1].Key != "sect2" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Second group key should be '%s', got '%s'", "sect2", bytype[1].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if bytype[2].Key != "sect3" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Third group key should be '%s', got '%s'", "sect3", bytype[2].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if bytype[2].Pages[0].Title != "Four" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has an unexpected page. Third group's data should have '%s', got '%s'", "Four", bytype[0].Pages[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if len(bytype[0].Pages) != 2 {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has unexpected number of pages. First group should have '%d' pages, got '%d' pages", 2, len(bytype[2].Pages))
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	bydate, err := s.RegularPages.GroupByDate("2006-01", "asc")
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		t.Fatalf("Unable to make PageGroup array: %s", err)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-09-06 08:03:03 -04:00
										 |  |  | 	if bydate[0].Key != "0001-01" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. First group key should be '%s', got '%s'", "0001-01", bydate[0].Key)
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 	if bydate[1].Key != "2012-01" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Second group key should be '%s', got '%s'", "2012-01", bydate[1].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if bydate[2].Key != "2012-04" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Third group key should be '%s', got '%s'", "2012-04", bydate[2].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-08-29 23:48:24 -04:00
										 |  |  | 	if bydate[2].Pages[0].Title != "Three" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has an unexpected page. Third group's pages should have '%s', got '%s'", "Three", bydate[2].Pages[0].Title)
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-08-29 23:48:24 -04:00
										 |  |  | 	if len(bydate[0].Pages) != 2 {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has unexpected number of pages. First group should have '%d' pages, got '%d' pages", 2, len(bydate[2].Pages))
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	bypubdate, err := s.RegularPages.GroupByPublishDate("2006")
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		t.Fatalf("Unable to make PageGroup array: %s", err)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if bypubdate[0].Key != "2012" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. First group key should be '%s', got '%s'", "2012", bypubdate[0].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if bypubdate[1].Key != "0001" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Second group key should be '%s', got '%s'", "0001", bypubdate[1].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if bypubdate[0].Pages[0].Title != "Three" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has an unexpected page. Third group's pages should have '%s', got '%s'", "Three", bypubdate[0].Pages[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if len(bypubdate[0].Pages) != 3 {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has unexpected number of pages. First group should have '%d' pages, got '%d' pages", 3, len(bypubdate[0].Pages))
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	byparam, err := s.RegularPages.GroupByParam("my_param", "desc")
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		t.Fatalf("Unable to make PageGroup array: %s", err)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if byparam[0].Key != "foo" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. First group key should be '%s', got '%s'", "foo", byparam[0].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if byparam[1].Key != "baz" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Second group key should be '%s', got '%s'", "baz", byparam[1].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if byparam[2].Key != "bar" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Third group key should be '%s', got '%s'", "bar", byparam[2].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if byparam[2].Pages[0].Title != "Three" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has an unexpected page. Third group's pages should have '%s', got '%s'", "Three", byparam[2].Pages[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if len(byparam[0].Pages) != 2 {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has unexpected number of pages. First group should have '%d' pages, got '%d' pages", 2, len(byparam[0].Pages))
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	_, err = s.RegularPages.GroupByParam("not_exist")
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | 	if err == nil {
 | 
					
						
							|  |  |  | 		t.Errorf("GroupByParam didn't return an expected error")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	byOnlyOneParam, err := s.RegularPages.GroupByParam("only_one")
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		t.Fatalf("Unable to make PageGroup array: %s", err)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if len(byOnlyOneParam) != 1 {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array has unexpected elements. Group length should be '%d', got '%d'", 1, len(byOnlyOneParam))
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if byOnlyOneParam[0].Key != "yes" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. First group key should be '%s', got '%s'", "yes", byOnlyOneParam[0].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 14:27:10 +01:00
										 |  |  | 	byParamDate, err := s.RegularPages.GroupByParamDate("my_date", "2006-01")
 | 
					
						
							| 
									
										
										
										
											2014-10-18 00:10:19 +09:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		t.Fatalf("Unable to make PageGroup array: %s", err)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if byParamDate[0].Key != "2010-05" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. First group key should be '%s', got '%s'", "2010-05", byParamDate[0].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if byParamDate[1].Key != "1979-05" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup array in unexpected order. Second group key should be '%s', got '%s'", "1979-05", byParamDate[1].Key)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if byParamDate[1].Pages[0].Title != "One" {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has an unexpected page. Second group's pages should have '%s', got '%s'", "One", byParamDate[1].Pages[0].Title)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	if len(byParamDate[0].Pages) != 2 {
 | 
					
						
							|  |  |  | 		t.Errorf("PageGroup has unexpected number of pages. First group should have '%d' pages, got '%d' pages", 2, len(byParamDate[2].Pages))
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-08-20 22:12:17 +09:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var pageWithWeightedTaxonomies1 = []byte(`+++
 | 
					
						
							| 
									
										
										
										
											2013-10-24 15:24:47 -07:00
										 |  |  | tags = [ "a", "b", "c" ]
 | 
					
						
							|  |  |  | tags_weight = 22
 | 
					
						
							|  |  |  | categories = ["d"]
 | 
					
						
							|  |  |  | title = "foo"
 | 
					
						
							|  |  |  | categories_weight = 44
 | 
					
						
							|  |  |  | +++
 | 
					
						
							|  |  |  | Front Matter with weighted tags and categories`)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var pageWithWeightedTaxonomies2 = []byte(`+++
 | 
					
						
							| 
									
										
										
										
											2014-09-05 09:29:01 -04:00
										 |  |  | tags = "a"
 | 
					
						
							| 
									
										
										
										
											2013-10-24 15:24:47 -07:00
										 |  |  | tags_weight = 33
 | 
					
						
							|  |  |  | title = "bar"
 | 
					
						
							|  |  |  | categories = [ "d", "e" ]
 | 
					
						
							|  |  |  | categories_weight = 11
 | 
					
						
							|  |  |  | alias = "spf13"
 | 
					
						
							|  |  |  | date = 1979-05-27T07:32:00Z
 | 
					
						
							|  |  |  | +++
 | 
					
						
							|  |  |  | Front Matter with weighted tags and categories`)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-07 16:10:41 +02:00
										 |  |  | var pageWithWeightedTaxonomies3 = []byte(`+++
 | 
					
						
							| 
									
										
										
										
											2013-10-24 15:24:47 -07:00
										 |  |  | title = "bza"
 | 
					
						
							|  |  |  | categories = [ "e" ]
 | 
					
						
							|  |  |  | categories_weight = 11
 | 
					
						
							|  |  |  | alias = "spf13"
 | 
					
						
							|  |  |  | date = 2010-05-27T07:32:00Z
 | 
					
						
							|  |  |  | +++
 | 
					
						
							|  |  |  | Front Matter with weighted tags and categories`)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-08 23:15:57 -04:00
										 |  |  | func TestWeightedTaxonomies(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("sect/doc1.md"), Content: pageWithWeightedTaxonomies2},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc2.md"), Content: pageWithWeightedTaxonomies1},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("sect/doc3.md"), Content: pageWithWeightedTaxonomies3},
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2015-06-21 15:01:06 +02:00
										 |  |  | 	taxonomies := make(map[string]string)
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-21 15:01:06 +02:00
										 |  |  | 	taxonomies["tag"] = "tags"
 | 
					
						
							|  |  |  | 	taxonomies["category"] = "categories"
 | 
					
						
							| 
									
										
										
										
											2014-04-07 11:44:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cfg.Set("baseURL", "http://auth/bub")
 | 
					
						
							|  |  |  | 	cfg.Set("taxonomies", taxonomies)
 | 
					
						
							| 
									
										
										
										
											2015-06-21 15:01:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	writeSourcesToSource(t, "content", fs, sources...)
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-08 23:15:57 -04:00
										 |  |  | 	if s.Taxonomies["tags"]["a"][0].Page.Title != "foo" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order, 'foo' expected first, got '%v'", s.Taxonomies["tags"]["a"][0].Page.Title)
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-08 23:15:57 -04:00
										 |  |  | 	if s.Taxonomies["categories"]["d"][0].Page.Title != "bar" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order, 'bar' expected first, got '%v'", s.Taxonomies["categories"]["d"][0].Page.Title)
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-08 23:15:57 -04:00
										 |  |  | 	if s.Taxonomies["categories"]["e"][0].Page.Title != "bza" {
 | 
					
						
							|  |  |  | 		t.Errorf("Pages in unexpected order, 'bza' expected first, got '%v'", s.Taxonomies["categories"]["e"][0].Page.Title)
 | 
					
						
							| 
									
										
										
										
											2014-01-29 14:50:31 -08:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2013-10-24 15:24:47 -07:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2015-09-03 12:27:57 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | func findPage(site *Site, f string) *Page {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	sp := source.NewSourceSpec(site.Cfg, site.Fs)
 | 
					
						
							|  |  |  | 	currentPath := sp.NewFile(filepath.FromSlash(f))
 | 
					
						
							| 
									
										
										
										
											2015-09-03 12:27:57 +10:00
										 |  |  | 	//t.Logf("looking for currentPath: %s", currentPath.Path())
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, page := range site.Pages {
 | 
					
						
							|  |  |  | 		//t.Logf("page: %s", page.Source.Path())
 | 
					
						
							|  |  |  | 		if page.Source.Path() == currentPath.Path() {
 | 
					
						
							|  |  |  | 			return page
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return nil
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | func setupLinkingMockSite(t *testing.T) *Site {
 | 
					
						
							| 
									
										
										
										
											2015-09-03 12:27:57 +10:00
										 |  |  | 	sources := []source.ByteSource{
 | 
					
						
							| 
									
										
										
										
											2016-08-19 06:22:19 -05:00
										 |  |  | 		{Name: filepath.FromSlash("index.md"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("rootfile.md"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("root-image.png"), Content: []byte("")},
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/2-root.md"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/index.md"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/common.md"), Content: []byte("")},
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/2-image.png"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/common.png"), Content: []byte("")},
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/level3/3-root.md"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/level3/index.md"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/level3/common.md"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/level3/3-image.png"), Content: []byte("")},
 | 
					
						
							|  |  |  | 		{Name: filepath.FromSlash("level2/level3/common.png"), Content: []byte("")},
 | 
					
						
							| 
									
										
										
										
											2015-09-03 12:27:57 +10:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg, fs := newTestCfg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cfg.Set("baseURL", "http://auth/")
 | 
					
						
							|  |  |  | 	cfg.Set("uglyURLs", false)
 | 
					
						
							| 
									
										
										
										
											2017-04-04 18:14:41 +02:00
										 |  |  | 	cfg.Set("outputs", map[string]interface{}{
 | 
					
						
							|  |  |  | 		"page": []string{"HTML", "AMP"},
 | 
					
						
							|  |  |  | 	})
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	cfg.Set("pluralizeListTitles", false)
 | 
					
						
							|  |  |  | 	cfg.Set("canonifyURLs", false)
 | 
					
						
							|  |  |  | 	cfg.Set("blackfriday",
 | 
					
						
							| 
									
										
										
										
											2016-03-15 16:00:36 +10:00
										 |  |  | 		map[string]interface{}{
 | 
					
						
							| 
									
										
										
										
											2016-10-24 21:33:11 +02:00
										 |  |  | 			"sourceRelativeLinksProjectFolder": "/docs"})
 | 
					
						
							| 
									
										
										
										
											2017-01-10 10:55:03 +01:00
										 |  |  | 	writeSourcesToSource(t, "content", fs, sources...)
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	return buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
 | 
					
						
							| 
									
										
										
										
											2015-09-03 12:27:57 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestRefLinking(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 	site := setupLinkingMockSite(t)
 | 
					
						
							| 
									
										
										
										
											2015-09-03 12:27:57 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	currentPage := findPage(site, "level2/level3/index.md")
 | 
					
						
							|  |  |  | 	if currentPage == nil {
 | 
					
						
							|  |  |  | 		t.Fatalf("failed to find current page in site")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-04 18:14:41 +02:00
										 |  |  | 	for i, test := range []struct {
 | 
					
						
							|  |  |  | 		link         string
 | 
					
						
							|  |  |  | 		outputFormat string
 | 
					
						
							|  |  |  | 		relative     bool
 | 
					
						
							|  |  |  | 		expected     string
 | 
					
						
							|  |  |  | 	}{
 | 
					
						
							| 
									
										
										
										
											2017-03-09 19:19:29 +01:00
										 |  |  | 		// Note: There are no magic in the index.md name. This was fixed in Hugo 0.20.
 | 
					
						
							|  |  |  | 		// Before that, index.md would wrongly resolve to "/".
 | 
					
						
							| 
									
										
										
										
											2017-04-04 18:14:41 +02:00
										 |  |  | 		{"index.md", "", true, "/index/"},
 | 
					
						
							|  |  |  | 		{"common.md", "", true, "/level2/common/"},
 | 
					
						
							|  |  |  | 		{"3-root.md", "", true, "/level2/level3/3-root/"},
 | 
					
						
							|  |  |  | 		{"index.md", "amp", true, "/amp/index/"},
 | 
					
						
							|  |  |  | 		{"index.md", "amp", false, "http://auth/amp/index/"},
 | 
					
						
							|  |  |  | 	} {
 | 
					
						
							|  |  |  | 		if out, err := site.Info.refLink(test.link, currentPage, test.relative, test.outputFormat); err != nil || out != test.expected {
 | 
					
						
							|  |  |  | 			t.Errorf("[%d] Expected %s to resolve to (%s), got (%s) - error: %s", i, test.link, test.expected, out, err)
 | 
					
						
							| 
									
										
										
										
											2015-09-03 12:27:57 +10:00
										 |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2017-04-04 18:14:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-03 12:27:57 +10:00
										 |  |  | 	// TODO: and then the failure cases.
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | func TestSourceRelativeLinksing(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 	site := setupLinkingMockSite(t)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	type resultMap map[string]string
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	okresults := map[string]resultMap{
 | 
					
						
							|  |  |  | 		"index.md": map[string]string{
 | 
					
						
							|  |  |  | 			"/docs/rootfile.md":             "/rootfile/",
 | 
					
						
							|  |  |  | 			"rootfile.md":                   "/rootfile/",
 | 
					
						
							| 
									
										
										
										
											2017-03-09 19:19:29 +01:00
										 |  |  | 			"index.md":                      "/index/",
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 			"level2/2-root.md":              "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/2-root.md":        "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"level2/level3/3-root.md":       "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/2-root/":          "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/2-root":           "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/level2/2-root/":               "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/level2/2-root":                "/level2/2-root/",
 | 
					
						
							|  |  |  | 		}, "rootfile.md": map[string]string{
 | 
					
						
							|  |  |  | 			"/docs/rootfile.md":             "/rootfile/",
 | 
					
						
							|  |  |  | 			"rootfile.md":                   "/rootfile/",
 | 
					
						
							|  |  |  | 			"level2/2-root.md":              "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/2-root.md":        "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"level2/level3/3-root.md":       "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 		}, "level2/2-root.md": map[string]string{
 | 
					
						
							|  |  |  | 			"../rootfile.md":                "/rootfile/",
 | 
					
						
							|  |  |  | 			"/docs/rootfile.md":             "/rootfile/",
 | 
					
						
							|  |  |  | 			"2-root.md":                     "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"../level2/2-root.md":           "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"./2-root.md":                   "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/2-root.md":        "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"level3/3-root.md":              "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"../level2/level3/3-root.md":    "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 		}, "level2/index.md": map[string]string{
 | 
					
						
							|  |  |  | 			"../rootfile.md":                "/rootfile/",
 | 
					
						
							|  |  |  | 			"/docs/rootfile.md":             "/rootfile/",
 | 
					
						
							|  |  |  | 			"2-root.md":                     "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"../level2/2-root.md":           "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"./2-root.md":                   "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/2-root.md":        "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"level3/3-root.md":              "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"../level2/level3/3-root.md":    "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 		}, "level2/level3/3-root.md": map[string]string{
 | 
					
						
							| 
									
										
										
										
											2017-03-09 19:19:29 +01:00
										 |  |  | 			"../../rootfile.md":             "/rootfile/",
 | 
					
						
							|  |  |  | 			"/docs/rootfile.md":             "/rootfile/",
 | 
					
						
							|  |  |  | 			"../2-root.md":                  "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/2-root.md":        "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"3-root.md":                     "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"./3-root.md":                   "/level2/level3/3-root/",
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 			"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 		}, "level2/level3/index.md": map[string]string{
 | 
					
						
							| 
									
										
										
										
											2017-03-09 19:19:29 +01:00
										 |  |  | 			"../../rootfile.md":             "/rootfile/",
 | 
					
						
							|  |  |  | 			"/docs/rootfile.md":             "/rootfile/",
 | 
					
						
							|  |  |  | 			"../2-root.md":                  "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"/docs/level2/2-root.md":        "/level2/2-root/",
 | 
					
						
							|  |  |  | 			"3-root.md":                     "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 			"./3-root.md":                   "/level2/level3/3-root/",
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 			"/docs/level2/level3/3-root.md": "/level2/level3/3-root/",
 | 
					
						
							|  |  |  | 		},
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for currentFile, results := range okresults {
 | 
					
						
							|  |  |  | 		currentPage := findPage(site, currentFile)
 | 
					
						
							|  |  |  | 		if currentPage == nil {
 | 
					
						
							|  |  |  | 			t.Fatalf("failed to find current page in site")
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		for link, url := range results {
 | 
					
						
							| 
									
										
										
										
											2016-03-15 16:00:36 +10:00
										 |  |  | 			if out, err := site.Info.SourceRelativeLink(link, currentPage); err != nil || out != url {
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 				t.Errorf("Expected %s to resolve to (%s), got (%s) - error: %s", link, url, out, err)
 | 
					
						
							|  |  |  | 			} else {
 | 
					
						
							|  |  |  | 				//t.Logf("tested ok %s maps to %s", link, out)
 | 
					
						
							|  |  |  | 			}
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	// TODO: and then the failure cases.
 | 
					
						
							|  |  |  | 	// 			"https://docker.com":           "",
 | 
					
						
							|  |  |  | 	// site_test.go:1094: Expected https://docker.com to resolve to (), got () - error: Not a plain filepath link (https://docker.com)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-15 16:00:36 +10:00
										 |  |  | func TestSourceRelativeLinkFileing(t *testing.T) {
 | 
					
						
							| 
									
										
										
										
											2017-02-05 10:20:06 +07:00
										 |  |  | 	t.Parallel()
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 	site := setupLinkingMockSite(t)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	type resultMap map[string]string
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	okresults := map[string]resultMap{
 | 
					
						
							|  |  |  | 		"index.md": map[string]string{
 | 
					
						
							|  |  |  | 			"/root-image.png": "/root-image.png",
 | 
					
						
							|  |  |  | 			"root-image.png":  "/root-image.png",
 | 
					
						
							|  |  |  | 		}, "rootfile.md": map[string]string{
 | 
					
						
							|  |  |  | 			"/root-image.png": "/root-image.png",
 | 
					
						
							|  |  |  | 		}, "level2/2-root.md": map[string]string{
 | 
					
						
							|  |  |  | 			"/root-image.png": "/root-image.png",
 | 
					
						
							|  |  |  | 			"common.png":      "/level2/common.png",
 | 
					
						
							|  |  |  | 		}, "level2/index.md": map[string]string{
 | 
					
						
							|  |  |  | 			"/root-image.png": "/root-image.png",
 | 
					
						
							|  |  |  | 			"common.png":      "/level2/common.png",
 | 
					
						
							|  |  |  | 			"./common.png":    "/level2/common.png",
 | 
					
						
							|  |  |  | 		}, "level2/level3/3-root.md": map[string]string{
 | 
					
						
							|  |  |  | 			"/root-image.png": "/root-image.png",
 | 
					
						
							|  |  |  | 			"common.png":      "/level2/level3/common.png",
 | 
					
						
							|  |  |  | 			"../common.png":   "/level2/common.png",
 | 
					
						
							|  |  |  | 		}, "level2/level3/index.md": map[string]string{
 | 
					
						
							|  |  |  | 			"/root-image.png": "/root-image.png",
 | 
					
						
							|  |  |  | 			"common.png":      "/level2/level3/common.png",
 | 
					
						
							|  |  |  | 			"../common.png":   "/level2/common.png",
 | 
					
						
							|  |  |  | 		},
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for currentFile, results := range okresults {
 | 
					
						
							|  |  |  | 		currentPage := findPage(site, currentFile)
 | 
					
						
							|  |  |  | 		if currentPage == nil {
 | 
					
						
							|  |  |  | 			t.Fatalf("failed to find current page in site")
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		for link, url := range results {
 | 
					
						
							| 
									
										
										
										
											2016-03-15 16:00:36 +10:00
										 |  |  | 			if out, err := site.Info.SourceRelativeLinkFile(link, currentPage); err != nil || out != url {
 | 
					
						
							| 
									
										
										
										
											2015-09-09 10:03:38 +10:00
										 |  |  | 				t.Errorf("Expected %s to resolve to (%s), got (%s) - error: %s", link, url, out, err)
 | 
					
						
							|  |  |  | 			} else {
 | 
					
						
							|  |  |  | 				//t.Logf("tested ok %s maps to %s", link, out)
 | 
					
						
							|  |  |  | 			}
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 |