// Copyright 2016 The Hugo Authors. All rights reserved.
//
// 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.
package hugolib
import (
"fmt"
"path/filepath"
"strings"
"testing"
"time"
"github.com/spf13/afero"
"github.com/spf13/hugo/deps"
"github.com/spf13/hugo/hugofs"
"github.com/stretchr/testify/require"
)
/*
This file will test the "making everything a page" transition.
See https://github.com/spf13/hugo/issues/2297
*/
func TestNodesAsPage(t *testing.T) {
t.Parallel()
for _, preserveTaxonomyNames := range []bool{false, true} {
for _, ugly := range []bool{true, false} {
doTestNodeAsPage(t, ugly, preserveTaxonomyNames)
}
}
}
func doTestNodeAsPage(t *testing.T, ugly, preserveTaxonomyNames bool) {
/* Will have to decide what to name the node content files, but:
Home page should have:
Content, shortcode support
Metadata (title, dates etc.)
Params
Taxonomies (categories, tags)
*/
var (
cfg, fs = newTestCfg()
th = testHelper{cfg, fs, t}
)
cfg.Set("uglyURLs", ugly)
cfg.Set("preserveTaxonomyNames", preserveTaxonomyNames)
cfg.Set("paginate", 1)
cfg.Set("title", "Hugo Rocks")
cfg.Set("rssURI", "customrss.xml")
writeLayoutsForNodeAsPageTests(t, fs)
writeNodePagesForNodeAsPageTests(t, fs, "")
writeRegularPagesForNodeAsPageTests(t, fs)
sites, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg})
require.NoError(t, err)
require.NoError(t, sites.Build(BuildCfg{}))
// date order: home, sect1, sect2, cat/hugo, cat/web, categories
th.assertFileContent(filepath.Join("public", "index.html"),
"Index Title: Home Sweet Home!",
"Home <strong>Content!</strong>",
"# Pages: 4",
"Date: 2009-01-02",
"Lastmod: 2009-01-03",
"GetPage: Section1 ",
)
th.assertFileContent(expectedFilePath(ugly, "public", "sect1", "regular1"), "Single Title: Page 01", "Content Page 01")
nodes := sites.findAllPagesByKindNotIn(KindPage)
require.Len(t, nodes, 8)
home := nodes[7] // oldest
require.True(t, home.IsHome())
require.True(t, home.IsNode())
require.False(t, home.IsPage())
require.True(t, home.Path() != "")
section2 := nodes[5]
require.Equal(t, "Section2", section2.Title)
pages := sites.findAllPagesByKind(KindPage)
require.Len(t, pages, 4)
first := pages[0]
require.False(t, first.IsHome())
require.False(t, first.IsNode())
require.True(t, first.IsPage())
// Check Home paginator
th.assertFileContent(expectedFilePath(ugly, "public", "page", "2"),
"Pag: Page 02")
// Check Sections
th.assertFileContent(expectedFilePath(ugly, "public", "sect1"),
"Section Title: Section", "Section1 <strong>Content!</strong>"