mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
Add a way to merge pages by language
As an example: ```html {{ $pages := .Site.RegularPages | lang.Merge $frSite.RegularPages | lang.Merge $enSite.RegularPages }} ``` Will "fill in the gaps" in the current site with, from left to right, content from the French site, and lastly the English. Fixes #4463
This commit is contained in:
@@ -15,6 +15,7 @@ package lang
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -134,3 +135,15 @@ func (ns *Namespace) NumFmt(precision, number interface{}, options ...interface{
|
||||
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
type pagesLanguageMerger interface {
|
||||
MergeByLanguageInterface(other interface{}) (interface{}, error)
|
||||
}
|
||||
|
||||
func (ns *Namespace) Merge(p2, p1 interface{}) (interface{}, error) {
|
||||
merger, ok := p1.(pagesLanguageMerger)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("language merge not supported for %T", p1)
|
||||
}
|
||||
return merger.MergeByLanguageInterface(p2)
|
||||
}
|
||||
|
Reference in New Issue
Block a user