tpl/tplimpl: Copy embedded HTML table render hook to each output format

Closes #13351
This commit is contained in:
Joe Mooring
2025-06-20 10:42:56 -07:00
committed by Bjørn Erik Pedersen
parent b6c8dfa9dc
commit 18a9ca7d7a
2 changed files with 56 additions and 3 deletions

View File

@@ -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
}