diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-10-30 17:59:24 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2016-11-22 09:57:03 +0100 |
commit | e371ac0b6f56bdffe92b9e74dae571a003123912 (patch) | |
tree | 8b87693d10aac64c8798622609a127a80bacb629 /hugolib/node_as_page_test.go | |
parent | e7d0bc8a7433e39dc22fe5096a0eb663c16c0d6a (diff) |
node to page: Basic outline
Updates #2297
Diffstat (limited to 'hugolib/node_as_page_test.go')
-rw-r--r-- | hugolib/node_as_page_test.go | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/hugolib/node_as_page_test.go b/hugolib/node_as_page_test.go new file mode 100644 index 000000000..0bbc99fd8 --- /dev/null +++ b/hugolib/node_as_page_test.go @@ -0,0 +1,103 @@ +// 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" + "testing" + + "github.com/stretchr/testify/require" +) + +/* + This file will test the "making everything a page" transition. + + See https://github.com/spf13/hugo/issues/2297 + +*/ + +func TestHomeAsPage(t *testing.T) { + nodePageFeatureFlag = true + defer toggleNodePageFeatureFlag() + + /* 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) + + */ + + testCommonResetState() + + writeSource(t, filepath.Join("content", "_node.md"), `--- +title: Home Sweet Home! +--- +Home **Content!** +`) + + writeSource(t, filepath.Join("layouts", "index.html"), ` +Index Title: {{ .Title }} +Index Content: {{ .Content }} +# Pages: {{ len .Data.Pages }} +`) + + writeSource(t, filepath.Join("layouts", "_default", "single.html"), ` +Single Title: {{ .Title }} +Single Content: {{ .Content }} +`) + + // Add some regular pages + for i := 0; i < 10; i++ { + writeSource(t, filepath.Join("content", fmt.Sprintf("regular%d.md", i)), fmt.Sprintf(`--- +title: Page %d +--- +Content Page %d +`, i, i)) + } + + s := newSiteDefaultLang() + + if err := buildAndRenderSite(s); err != nil { + t.Fatalf("Failed to build site: %s", err) + } + + assertFileContent(t, filepath.Join("public", "index.html"), false, + "Index Title: Home Sweet Home!", + "Home <strong>Content!</strong>", + "# Pages: 10") + assertFileContent(t, filepath.Join("public", "regular1", "index.html"), false, "Single Title: Page 1", "Content Page 1") + + h := s.owner + nodes := h.findPagesByNodeType(NodeHome) + require.Len(t, nodes, 1) + + home := nodes[0] + + require.True(t, home.IsHome()) + require.True(t, home.IsNode()) + require.False(t, home.IsPage()) + + pages := h.findPagesByNodeType(NodePage) + require.Len(t, pages, 10) + + first := pages[0] + require.False(t, first.IsHome()) + require.False(t, first.IsNode()) + require.True(t, first.IsPage()) + +} |