mirror of
https://github.com/gohugoio/hugo.git
synced 2025-06-28 11:49:52 +00:00
tpl/tplimpl: Copy embedded HTML table render hook to each output format
Closes #13351
This commit is contained in:
parent
b6c8dfa9dc
commit
18a9ca7d7a
2 changed files with 56 additions and 3 deletions
|
@ -1018,7 +1018,7 @@ func (s *TemplateStore) allRawTemplates() iter.Seq[tpl.Template] {
|
|||
}
|
||||
|
||||
func (s *TemplateStore) insertEmbedded() error {
|
||||
return fs.WalkDir(embeddedTemplatesFs, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
return fs.WalkDir(embeddedTemplatesFs, ".", func(tpath string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1026,7 +1026,7 @@ func (s *TemplateStore) insertEmbedded() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
templb, err := embeddedTemplatesFs.ReadFile(path)
|
||||
templb, err := embeddedTemplatesFs.ReadFile(tpath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1034,7 +1034,7 @@ func (s *TemplateStore) insertEmbedded() error {
|
|||
// Get the newlines on Windows in line with how we had it back when we used Go Generate
|
||||
// to write the templates to Go files.
|
||||
templ := string(bytes.ReplaceAll(templb, []byte("\r\n"), []byte("\n")))
|
||||
name := strings.TrimPrefix(filepath.ToSlash(path), "embedded/templates/")
|
||||
name := strings.TrimPrefix(filepath.ToSlash(tpath), "embedded/templates/")
|
||||
|
||||
insertOne := func(name, content string) error {
|
||||
pi := s.opts.PathParser.Parse(files.ComponentFolderLayouts, name)
|
||||
|
@ -1064,6 +1064,19 @@ func (s *TemplateStore) insertEmbedded() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Copy the embedded HTML table render hook to each output format.
|
||||
// See https://github.com/gohugoio/hugo/issues/13351.
|
||||
if name == path.Join(containerMarkup, "render-table.html") {
|
||||
for _, of := range s.opts.OutputFormats {
|
||||
path := paths.TrimExt(name) + "." + of.Name + of.MediaType.FirstSuffix.FullSuffix
|
||||
if err := insertOne(path, templ); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := insertOne(name, templ); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1508,3 +1508,43 @@ mytexts|safeHTML: {{ partial "mytext.txt" . | safeHTML }}
|
|||
"mytexts|safeHTML: <div>mytext</div>",
|
||||
)
|
||||
}
|
||||
|
||||
func TestIssue13351(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
[outputs]
|
||||
home = ['html','json']
|
||||
[outputFormats.html]
|
||||
weight = 1
|
||||
[outputFormats.json]
|
||||
weight = 2
|
||||
-- content/_index.md --
|
||||
---
|
||||
title: home
|
||||
---
|
||||
a|b
|
||||
:--|:--
|
||||
1|2
|
||||
-- layouts/index.html --
|
||||
{{ .Content }}
|
||||
-- layouts/index.json --
|
||||
{{ .Content }}
|
||||
`
|
||||
|
||||
b := hugolib.Test(t, files)
|
||||
b.AssertFileContent("public/index.html", "<table>")
|
||||
b.AssertFileContent("public/index.json", "<table>")
|
||||
|
||||
f := strings.ReplaceAll(files, "weight = 1", "weight = 0")
|
||||
b = hugolib.Test(t, f)
|
||||
b.AssertFileContent("public/index.html", "<table>")
|
||||
b.AssertFileContent("public/index.json", "<table>")
|
||||
|
||||
f = strings.ReplaceAll(files, "weight = 1", "")
|
||||
b = hugolib.Test(t, f)
|
||||
b.AssertFileContent("public/index.html", "<table>")
|
||||
b.AssertFileContent("public/index.json", "<table>")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue