summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-30 11:43:20 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-30 20:12:19 +0100
commit5b7cb258ec26d7de690099f5dc39935b8d728155 (patch)
tree53544c8ab46e3fffda4a1e33c5d6e705183e2652 /hugolib
parent80595bbe3e7901ecd6200e59d43af142c3c85b6b (diff)
Create default link and image render hooks
Fixes #11933
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/content_render_hooks_test.go72
-rw-r--r--hugolib/page__per_output.go15
-rw-r--r--hugolib/pagecollections.go2
-rw-r--r--hugolib/pagecollections_test.go8
4 files changed, 96 insertions, 1 deletions
diff --git a/hugolib/content_render_hooks_test.go b/hugolib/content_render_hooks_test.go
index 93b0e1621..36d1e626f 100644
--- a/hugolib/content_render_hooks_test.go
+++ b/hugolib/content_render_hooks_test.go
@@ -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)
+![Pixel](pixel.png)
+-- content/p2/index.md --
+---
+title: "p2"
+---
+[P1](p1)
+![Pixel](pixel.jpg)
+-- content/p1/index.en.md --
+---
+title: "p1 en"
+---
+[P2](p2)
+![Pixel](pixel.png)
+-- content/p2/index.en.md --
+---
+title: "p2 en"
+---
+[P1](p1)
+![Pixel](pixel.png)
+
+-- 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\">")
+ })
+}
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index e0026ed1f..7220c86fe 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -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
}
diff --git a/hugolib/pagecollections.go b/hugolib/pagecollections.go
index 8e05ad7e6..505b10bd7 100644
--- a/hugolib/pagecollections.go
+++ b/hugolib/pagecollections.go
@@ -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
}
diff --git a/hugolib/pagecollections_test.go b/hugolib/pagecollections_test.go
index 8fd4f0739..eaa80a109 100644
--- a/hugolib/pagecollections_test.go
+++ b/hugolib/pagecollections_test.go
@@ -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|