mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-26 21:51:02 +03:00
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
This commit is contained in:
parent
44f5c1c14c
commit
597e418cb0
206 changed files with 14442 additions and 9679 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2017-present 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.
|
||||
|
@ -17,6 +17,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gohugoio/hugo/resources/page"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -148,15 +150,15 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P
|
|||
require.NoError(t, err)
|
||||
|
||||
s := h.Sites[0]
|
||||
require.Equal(t, "en", s.Language.Lang)
|
||||
require.Equal(t, "en", s.language.Lang)
|
||||
|
||||
home := s.getPage(KindHome)
|
||||
home := s.getPage(page.KindHome)
|
||||
|
||||
require.NotNil(t, home)
|
||||
|
||||
lenOut := len(outputs)
|
||||
|
||||
require.Len(t, home.outputFormats, lenOut)
|
||||
require.Len(t, home.OutputFormats(), lenOut)
|
||||
|
||||
// There is currently always a JSON output to make it simpler ...
|
||||
altFormats := lenOut - 1
|
||||
|
@ -207,12 +209,8 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P
|
|||
}
|
||||
|
||||
of := home.OutputFormats()
|
||||
require.Len(t, of, lenOut)
|
||||
require.Nil(t, of.Get("Hugo"))
|
||||
require.NotNil(t, of.Get("json"))
|
||||
|
||||
json := of.Get("JSON")
|
||||
_, err = home.AlternativeOutputFormats()
|
||||
require.Error(t, err)
|
||||
require.NotNil(t, json)
|
||||
require.Equal(t, "/blog/index.json", json.RelPermalink())
|
||||
require.Equal(t, "http://example.com/blog/index.json", json.Permalink())
|
||||
|
@ -323,7 +321,7 @@ baseName = "customdelimbase"
|
|||
th.assertFileContent("public/customdelimbase_del", "custom delim")
|
||||
|
||||
s := h.Sites[0]
|
||||
home := s.getPage(KindHome)
|
||||
home := s.getPage(page.KindHome)
|
||||
require.NotNil(t, home)
|
||||
|
||||
outputs := home.OutputFormats()
|
||||
|
@ -339,8 +337,8 @@ func TestCreateSiteOutputFormats(t *testing.T) {
|
|||
assert := require.New(t)
|
||||
|
||||
outputsConfig := map[string]interface{}{
|
||||
KindHome: []string{"HTML", "JSON"},
|
||||
KindSection: []string{"JSON"},
|
||||
page.KindHome: []string{"HTML", "JSON"},
|
||||
page.KindSection: []string{"JSON"},
|
||||
}
|
||||
|
||||
cfg := viper.New()
|
||||
|
@ -348,13 +346,13 @@ func TestCreateSiteOutputFormats(t *testing.T) {
|
|||
|
||||
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg)
|
||||
assert.NoError(err)
|
||||
assert.Equal(output.Formats{output.JSONFormat}, outputs[KindSection])
|
||||
assert.Equal(output.Formats{output.HTMLFormat, output.JSONFormat}, outputs[KindHome])
|
||||
assert.Equal(output.Formats{output.JSONFormat}, outputs[page.KindSection])
|
||||
assert.Equal(output.Formats{output.HTMLFormat, output.JSONFormat}, outputs[page.KindHome])
|
||||
|
||||
// Defaults
|
||||
assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[KindTaxonomy])
|
||||
assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[KindTaxonomyTerm])
|
||||
assert.Equal(output.Formats{output.HTMLFormat}, outputs[KindPage])
|
||||
assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindTaxonomy])
|
||||
assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindTaxonomyTerm])
|
||||
assert.Equal(output.Formats{output.HTMLFormat}, outputs[page.KindPage])
|
||||
|
||||
// These aren't (currently) in use when rendering in Hugo,
|
||||
// but the pages needs to be assigned an output format,
|
||||
|
@ -370,7 +368,7 @@ func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) {
|
|||
assert := require.New(t)
|
||||
|
||||
outputsConfig := map[string]interface{}{
|
||||
KindHome: []string{"FOO", "JSON"},
|
||||
page.KindHome: []string{"FOO", "JSON"},
|
||||
}
|
||||
|
||||
cfg := viper.New()
|
||||
|
@ -384,7 +382,7 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
|
|||
assert := require.New(t)
|
||||
|
||||
outputsConfig := map[string]interface{}{
|
||||
KindHome: []string{},
|
||||
page.KindHome: []string{},
|
||||
}
|
||||
|
||||
cfg := viper.New()
|
||||
|
@ -392,14 +390,14 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
|
|||
|
||||
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg)
|
||||
assert.NoError(err)
|
||||
assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[KindHome])
|
||||
assert.Equal(output.Formats{output.HTMLFormat, output.RSSFormat}, outputs[page.KindHome])
|
||||
}
|
||||
|
||||
func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) {
|
||||
assert := require.New(t)
|
||||
|
||||
outputsConfig := map[string]interface{}{
|
||||
KindHome: []string{},
|
||||
page.KindHome: []string{},
|
||||
}
|
||||
|
||||
cfg := viper.New()
|
||||
|
@ -412,5 +410,5 @@ func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) {
|
|||
|
||||
outputs, err := createSiteOutputFormats(output.Formats{customRSS, customHTML}, cfg)
|
||||
assert.NoError(err)
|
||||
assert.Equal(output.Formats{customHTML, customRSS}, outputs[KindHome])
|
||||
assert.Equal(output.Formats{customHTML, customRSS}, outputs[page.KindHome])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue