mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-29 02:13:34 +00:00
parent
166483fe12
commit
ff16c42ed0
2 changed files with 8 additions and 0 deletions
|
@ -53,6 +53,9 @@ func (p1 Pages) MergeByLanguage(p2 Pages) Pages {
|
||||||
// MergeByLanguageInterface is the generic version of MergeByLanguage. It
|
// MergeByLanguageInterface is the generic version of MergeByLanguage. It
|
||||||
// is here just so it can be called from the tpl package.
|
// is here just so it can be called from the tpl package.
|
||||||
func (p1 Pages) MergeByLanguageInterface(in interface{}) (interface{}, error) {
|
func (p1 Pages) MergeByLanguageInterface(in interface{}) (interface{}, error) {
|
||||||
|
if in == nil {
|
||||||
|
return p1, nil
|
||||||
|
}
|
||||||
p2, ok := in.(Pages)
|
p2, ok := in.(Pages)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("%T cannot be merged by language", in)
|
return nil, fmt.Errorf("%T cannot be merged by language", in)
|
||||||
|
|
|
@ -79,6 +79,11 @@ func TestMergeLanguages(t *testing.T) {
|
||||||
// This looks less ugly in the templates ...
|
// This looks less ugly in the templates ...
|
||||||
mergedNNResources := ri.(resource.ResourcesLanguageMerger).MergeByLanguage(enBundle.Resources)
|
mergedNNResources := ri.(resource.ResourcesLanguageMerger).MergeByLanguage(enBundle.Resources)
|
||||||
assert.Equal(6, len(mergedNNResources))
|
assert.Equal(6, len(mergedNNResources))
|
||||||
|
|
||||||
|
unchanged, err := nnSite.RegularPages.MergeByLanguageInterface(nil)
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Equal(nnSite.RegularPages, unchanged)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMergeLanguagesTemplate(t *testing.T) {
|
func TestMergeLanguagesTemplate(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue