mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
@@ -14,6 +14,7 @@
|
||||
package hugolib
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -169,3 +170,74 @@ Self Fragments: [d e f]
|
||||
P1 Fragments: [b c z]
|
||||
`)
|
||||
}
|
||||
|
||||
func TestDefaultRenderHooksMultilingual(t *testing.T) {
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = "https://example.org"
|
||||
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"]
|
||||
defaultContentLanguage = "nn"
|
||||
defaultContentLanguageInSubdir = true
|
||||
[markup]
|
||||
[markup.goldmark]
|
||||
duplicateResourceFiles = false
|
||||
[markup.goldmark.renderhooks]
|
||||
[markup.goldmark.renderhooks.link]
|
||||
#enableDefault = false
|
||||
[markup.goldmark.renderhooks.image]
|
||||
#enableDefault = false
|
||||
[languages]
|
||||
[languages.en]
|
||||
weight = 1
|
||||
[languages.nn]
|
||||
weight = 2
|
||||
-- content/p1/index.md --
|
||||
---
|
||||
title: "p1"
|
||||
---
|
||||
[P2](p2)
|
||||

|
||||
-- content/p2/index.md --
|
||||
---
|
||||
title: "p2"
|
||||
---
|
||||
[P1](p1)
|
||||

|
||||
-- content/p1/index.en.md --
|
||||
---
|
||||
title: "p1 en"
|
||||
---
|
||||
[P2](p2)
|
||||

|
||||
-- content/p2/index.en.md --
|
||||
---
|
||||
title: "p2 en"
|
||||
---
|
||||
[P1](p1)
|
||||

|
||||
|
||||
-- content/p1/pixel.nn.png --
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
|
||||
-- content/p2/pixel.png --
|
||||
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
|
||||
-- layouts/_default/single.html --
|
||||
{{ .Title }}|{{ .Content }}|$
|
||||
|
||||
`
|
||||
|
||||
t.Run("Default multilingual", func(t *testing.T) {
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/nn/p1/index.html",
|
||||
"p1|<p><a href=\"/nn/p2/\">P2</a\n></p>", "<img alt=\"Pixel\" src=\"/nn/p1/pixel.nn.png\">")
|
||||
b.AssertFileContent("public/en/p1/index.html",
|
||||
"p1 en|<p><a href=\"/en/p2/\">P2</a\n></p>", "<img alt=\"Pixel\" src=\"/nn/p1/pixel.nn.png\">")
|
||||
})
|
||||
|
||||
t.Run("Disabled", func(t *testing.T) {
|
||||
b := Test(t, strings.ReplaceAll(files, "#enableDefault = false", "enableDefault = false"))
|
||||
|
||||
b.AssertFileContent("public/nn/p1/index.html",
|
||||
"p1|<p><a href=\"p2\">P2</a>", "<img src=\"pixel.png\" alt=\"Pixel\">")
|
||||
})
|
||||
}
|
||||
|
@@ -470,6 +470,21 @@ func (pco *pageContentOutput) initRenderHooks() error {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if found {
|
||||
if isitp, ok := templ.(tpl.IsInternalTemplateProvider); ok && isitp.IsInternalTemplate() {
|
||||
renderHookConfig := pco.po.p.s.conf.Markup.Goldmark.RenderHooks
|
||||
switch templ.Name() {
|
||||
case "_default/_markup/render-link.html":
|
||||
if !renderHookConfig.Link.IsEnableDefault() {
|
||||
return nil, false
|
||||
}
|
||||
case "_default/_markup/render-image.html":
|
||||
if !renderHookConfig.Image.IsEnableDefault() {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return templ, found
|
||||
}
|
||||
|
||||
|
@@ -56,7 +56,7 @@ func (c *pageFinder) getPageRef(context page.Page, ref string) (page.Page, error
|
||||
}
|
||||
|
||||
func (c *pageFinder) getPage(context page.Page, ref string) (page.Page, error) {
|
||||
n, err := c.getContentNode(context, false, filepath.ToSlash(ref))
|
||||
n, err := c.getContentNode(context, false, paths.ToSlashTrimTrailing(ref))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -413,6 +413,10 @@ title: p2
|
||||
func TestPageGetPageVariations(t *testing.T) {
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
-- content/s1/_index.md --
|
||||
---
|
||||
title: s1 section
|
||||
---
|
||||
-- content/s1/p1/index.md --
|
||||
---
|
||||
title: p1
|
||||
@@ -430,6 +434,8 @@ title: p3
|
||||
title: p2_root
|
||||
---
|
||||
-- layouts/index.html --
|
||||
/s1: {{ with .GetPage "/s1" }}{{ .Title }}{{ end }}|
|
||||
/s1/: {{ with .GetPage "/s1/" }}{{ .Title }}{{ end }}|
|
||||
/s1/p2.md: {{ with .GetPage "/s1/p2.md" }}{{ .Title }}{{ end }}|
|
||||
/s1/p2: {{ with .GetPage "/s1/p2" }}{{ .Title }}{{ end }}|
|
||||
/s1/p1/index.md: {{ with .GetPage "/s1/p1/index.md" }}{{ .Title }}{{ end }}|
|
||||
@@ -444,6 +450,8 @@ p1/index.md: {{ with .GetPage "p1/index.md" }}{{ .Title }}{{ end }}|
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html", `
|
||||
/s1: s1 section|
|
||||
/s1/: s1 section|
|
||||
/s1/p2.md: p2|
|
||||
/s1/p2: p2|
|
||||
/s1/p1/index.md: p1|
|
||||
|
Reference in New Issue
Block a user