diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-01-02 12:33:26 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-03-23 18:51:22 +0100 |
commit | 597e418cb02883418f2cebb41400e8e61413f651 (patch) | |
tree | 177ad9c540b2583b6dab138c9f0490d28989c7f7 /hugolib/pagecollections_test.go | |
parent | 44f5c1c14cb1f42cc5f01739c289e9cfc83602af (diff) |
Make Page an interface
The main motivation of this commit is to add a `page.Page` interface to replace the very file-oriented `hugolib.Page` struct.
This is all a preparation step for issue #5074, "pages from other data sources".
But this also fixes a set of annoying limitations, especially related to custom output formats, and shortcodes.
Most notable changes:
* The inner content of shortcodes using the `{{%` as the outer-most delimiter will now be sent to the content renderer, e.g. Blackfriday.
This means that any markdown will partake in the global ToC and footnote context etc.
* The Custom Output formats are now "fully virtualized". This removes many of the current limitations.
* The taxonomy list type now has a reference to the `Page` object.
This improves the taxonomy template `.Title` situation and make common template constructs much simpler.
See #5074
Fixes #5763
Fixes #5758
Fixes #5090
Fixes #5204
Fixes #4695
Fixes #5607
Fixes #5707
Fixes #5719
Fixes #3113
Fixes #5706
Fixes #5767
Fixes #5723
Fixes #5769
Fixes #5770
Fixes #5771
Fixes #5759
Fixes #5776
Fixes #5777
Fixes #5778
Diffstat (limited to 'hugolib/pagecollections_test.go')
-rw-r--r-- | hugolib/pagecollections_test.go | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go index 2f8b31490..a5a347f83 100644 --- a/hugolib/pagecollections_test.go +++ b/hugolib/pagecollections_test.go @@ -1,4 +1,4 @@ -// Copyright 2017 The Hugo Authors. All rights reserved. +// Copyright 2019 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. @@ -21,6 +21,8 @@ import ( "testing" "time" + "github.com/gohugoio/hugo/resources/page" + "github.com/gohugoio/hugo/deps" "github.com/stretchr/testify/require" ) @@ -98,12 +100,12 @@ func BenchmarkGetPageRegular(b *testing.B) { type testCase struct { kind string - context *Page + context page.Page path []string expectedTitle string } -func (t *testCase) check(p *Page, err error, errorMsg string, assert *require.Assertions) { +func (t *testCase) check(p page.Page, err error, errorMsg string, assert *require.Assertions) { switch t.kind { case "Ambiguous": assert.Error(err) @@ -114,8 +116,8 @@ func (t *testCase) check(p *Page, err error, errorMsg string, assert *require.As default: assert.NoError(err, errorMsg) assert.NotNil(p, errorMsg) - assert.Equal(t.kind, p.Kind, errorMsg) - assert.Equal(t.expectedTitle, p.title, errorMsg) + assert.Equal(t.kind, p.Kind(), errorMsg) + assert.Equal(t.expectedTitle, p.Title(), errorMsg) } } @@ -159,62 +161,62 @@ func TestGetPage(t *testing.T) { tests := []testCase{ // legacy content root relative paths - {KindHome, nil, []string{}, "home page"}, - {KindPage, nil, []string{"about.md"}, "about page"}, - {KindSection, nil, []string{"sect3"}, "section 3"}, - {KindPage, nil, []string{"sect3/page1.md"}, "Title3_1"}, - {KindPage, nil, []string{"sect4/page2.md"}, "Title4_2"}, - {KindSection, nil, []string{"sect3/sect7"}, "another sect7"}, - {KindPage, nil, []string{"sect3/subsect/deep.md"}, "deep page"}, - {KindPage, nil, []string{filepath.FromSlash("sect5/page3.md")}, "Title5_3"}, //test OS-specific path + {page.KindHome, nil, []string{}, "home page"}, + {page.KindPage, nil, []string{"about.md"}, "about page"}, + {page.KindSection, nil, []string{"sect3"}, "section 3"}, + {page.KindPage, nil, []string{"sect3/page1.md"}, "Title3_1"}, + {page.KindPage, nil, []string{"sect4/page2.md"}, "Title4_2"}, + {page.KindSection, nil, []string{"sect3/sect7"}, "another sect7"}, + {page.KindPage, nil, []string{"sect3/subsect/deep.md"}, "deep page"}, + {page.KindPage, nil, []string{filepath.FromSlash("sect5/page3.md")}, "Title5_3"}, //test OS-specific path // shorthand refs (potentially ambiguous) - {KindPage, nil, []string{"unique.md"}, "UniqueBase"}, + {page.KindPage, nil, []string{"unique.md"}, "UniqueBase"}, {"Ambiguous", nil, []string{"page1.md"}, ""}, // ISSUE: This is an ambiguous ref, but because we have to support the legacy // content root relative paths without a leading slash, the lookup // returns /sect7. This undermines ambiguity detection, but we have no choice. //{"Ambiguous", nil, []string{"sect7"}, ""}, - {KindSection, nil, []string{"sect7"}, "Sect7s"}, + {page.KindSection, nil, []string{"sect7"}, "Sect7s"}, // absolute paths - {KindHome, nil, []string{"/"}, "home page"}, - {KindPage, nil, []string{"/about.md"}, "about page"}, - {KindSection, nil, []string{"/sect3"}, "section 3"}, - {KindPage, nil, []string{"/sect3/page1.md"}, "Title3_1"}, - {KindPage, nil, []string{"/sect4/page2.md"}, "Title4_2"}, - {KindSection, nil, []string{"/sect3/sect7"}, "another sect7"}, - {KindPage, nil, []string{"/sect3/subsect/deep.md"}, "deep page"}, - {KindPage, nil, []string{filepath.FromSlash("/sect5/page3.md")}, "Title5_3"}, //test OS-specific path - {KindPage, nil, []string{"/sect3/unique.md"}, "UniqueBase"}, //next test depends on this page existing + {page.KindHome, nil, []string{"/"}, "home page"}, + {page.KindPage, nil, []string{"/about.md"}, "about page"}, + {page.KindSection, nil, []string{"/sect3"}, "section 3"}, + {page.KindPage, nil, []string{"/sect3/page1.md"}, "Title3_1"}, + {page.KindPage, nil, []string{"/sect4/page2.md"}, "Title4_2"}, + {page.KindSection, nil, []string{"/sect3/sect7"}, "another sect7"}, + {page.KindPage, nil, []string{"/sect3/subsect/deep.md"}, "deep page"}, + {page.KindPage, nil, []string{filepath.FromSlash("/sect5/page3.md")}, "Title5_3"}, //test OS-specific path + {page.KindPage, nil, []string{"/sect3/unique.md"}, "UniqueBase"}, //next test depends on this page existing // {"NoPage", nil, []string{"/unique.md"}, ""}, // ISSUE #4969: this is resolving to /sect3/unique.md {"NoPage", nil, []string{"/missing-page.md"}, ""}, {"NoPage", nil, []string{"/missing-section"}, ""}, // relative paths - {KindHome, sec3, []string{".."}, "home page"}, - {KindHome, sec3, []string{"../"}, "home page"}, - {KindPage, sec3, []string{"../about.md"}, "about page"}, - {KindSection, sec3, []string{"."}, "section 3"}, - {KindSection, sec3, []string{"./"}, "section 3"}, - {KindPage, sec3, []string{"page1.md"}, "Title3_1"}, - {KindPage, sec3, []string{"./page1.md"}, "Title3_1"}, - {KindPage, sec3, []string{"../sect4/page2.md"}, "Title4_2"}, - {KindSection, sec3, []string{"sect7"}, "another sect7"}, - {KindSection, sec3, []string{"./sect7"}, "another sect7"}, - {KindPage, sec3, []string{"./subsect/deep.md"}, "deep page"}, - {KindPage, sec3, []string{"./subsect/../../sect7/page9.md"}, "Title7_9"}, - {KindPage, sec3, []string{filepath.FromSlash("../sect5/page3.md")}, "Title5_3"}, //test OS-specific path - {KindPage, sec3, []string{"./unique.md"}, "UniqueBase"}, + {page.KindHome, sec3, []string{".."}, "home page"}, + {page.KindHome, sec3, []string{"../"}, "home page"}, + {page.KindPage, sec3, []string{"../about.md"}, "about page"}, + {page.KindSection, sec3, []string{"."}, "section 3"}, + {page.KindSection, sec3, []string{"./"}, "section 3"}, + {page.KindPage, sec3, []string{"page1.md"}, "Title3_1"}, + {page.KindPage, sec3, []string{"./page1.md"}, "Title3_1"}, + {page.KindPage, sec3, []string{"../sect4/page2.md"}, "Title4_2"}, + {page.KindSection, sec3, []string{"sect7"}, "another sect7"}, + {page.KindSection, sec3, []string{"./sect7"}, "another sect7"}, + {page.KindPage, sec3, []string{"./subsect/deep.md"}, "deep page"}, + {page.KindPage, sec3, []string{"./subsect/../../sect7/page9.md"}, "Title7_9"}, + {page.KindPage, sec3, []string{filepath.FromSlash("../sect5/page3.md")}, "Title5_3"}, //test OS-specific path + {page.KindPage, sec3, []string{"./unique.md"}, "UniqueBase"}, {"NoPage", sec3, []string{"./sect2"}, ""}, //{"NoPage", sec3, []string{"sect2"}, ""}, // ISSUE: /sect3 page relative query is resolving to /sect2 // absolute paths ignore context - {KindHome, sec3, []string{"/"}, "home page"}, - {KindPage, sec3, []string{"/about.md"}, "about page"}, - {KindPage, sec3, []string{"/sect4/page2.md"}, "Title4_2"}, - {KindPage, sec3, []string{"/sect3/subsect/deep.md"}, "deep page"}, //next test depends on this page existing + {page.KindHome, sec3, []string{"/"}, "home page"}, + {page.KindPage, sec3, []string{"/about.md"}, "about page"}, + {page.KindPage, sec3, []string{"/sect4/page2.md"}, "Title4_2"}, + {page.KindPage, sec3, []string{"/sect3/subsect/deep.md"}, "deep page"}, //next test depends on this page existing {"NoPage", sec3, []string{"/subsect/deep.md"}, ""}, } |