mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
Add Translations and AllTranslations to Node
This commit also consolidates URLs on Node vs Page, so now .Permalink should be interoperable. Note that this implementations should be fairly short-livded, waiting for #2297, but the API should be stable.
This commit is contained in:
@@ -64,8 +64,6 @@ type Page struct {
|
||||
translations Pages
|
||||
extension string
|
||||
contentType string
|
||||
lang string
|
||||
language *Language
|
||||
renderable bool
|
||||
Layout string
|
||||
layoutsCalculated []string
|
||||
@@ -431,7 +429,7 @@ func (p *Page) permalink() (*url.URL, error) {
|
||||
baseURL := string(p.Site.BaseURL)
|
||||
dir := strings.TrimSpace(helpers.MakePath(filepath.ToSlash(strings.ToLower(p.Source.Dir()))))
|
||||
pSlug := strings.TrimSpace(helpers.URLize(p.Slug))
|
||||
pURL := strings.TrimSpace(helpers.URLize(p.URL))
|
||||
pURL := strings.TrimSpace(helpers.URLize(p.URLPath.URL))
|
||||
var permalink string
|
||||
var err error
|
||||
|
||||
@@ -467,14 +465,6 @@ func (p *Page) Extension() string {
|
||||
return viper.GetString("DefaultExtension")
|
||||
}
|
||||
|
||||
// TODO(bep) multilingo consolidate
|
||||
func (p *Page) Language() *Language {
|
||||
return p.language
|
||||
}
|
||||
func (p *Page) Lang() string {
|
||||
return p.lang
|
||||
}
|
||||
|
||||
// AllTranslations returns all translations, including the current Page.
|
||||
func (p *Page) AllTranslations() Pages {
|
||||
return p.translations
|
||||
@@ -591,7 +581,7 @@ func (p *Page) update(f interface{}) error {
|
||||
if url := cast.ToString(v); strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") {
|
||||
return fmt.Errorf("Only relative URLs are supported, %v provided", url)
|
||||
}
|
||||
p.URL = cast.ToString(v)
|
||||
p.URLPath.URL = cast.ToString(v)
|
||||
case "type":
|
||||
p.contentType = cast.ToString(v)
|
||||
case "extension", "ext":
|
||||
@@ -1008,8 +998,8 @@ func (p *Page) FullFilePath() string {
|
||||
|
||||
func (p *Page) TargetPath() (outfile string) {
|
||||
// Always use URL if it's specified
|
||||
if len(strings.TrimSpace(p.URL)) > 2 {
|
||||
outfile = strings.TrimSpace(p.URL)
|
||||
if len(strings.TrimSpace(p.URLPath.URL)) > 2 {
|
||||
outfile = strings.TrimSpace(p.URLPath.URL)
|
||||
|
||||
if strings.HasSuffix(outfile, "/") {
|
||||
outfile = outfile + "index.html"
|
||||
@@ -1042,17 +1032,3 @@ func (p *Page) TargetPath() (outfile string) {
|
||||
|
||||
return p.addMultilingualFilesystemPrefix(filepath.Join(strings.ToLower(helpers.MakePath(p.Source.Dir())), strings.TrimSpace(outfile)))
|
||||
}
|
||||
|
||||
func (p *Page) addMultilingualWebPrefix(outfile string) string {
|
||||
if p.Lang() == "" {
|
||||
return outfile
|
||||
}
|
||||
return "/" + path.Join(p.Lang(), outfile)
|
||||
}
|
||||
|
||||
func (p *Page) addMultilingualFilesystemPrefix(outfile string) string {
|
||||
if p.Lang() == "" {
|
||||
return outfile
|
||||
}
|
||||
return string(filepath.Separator) + filepath.Join(p.Lang(), outfile)
|
||||
}
|
||||
|
Reference in New Issue
Block a user