@@ -16,6 +16,7 @@ package create
1616import (
1717 "bytes"
1818 "fmt"
19+ "strings"
1920 "time"
2021
2122 "github.com/gohugoio/hugo/helpers"
@@ -57,6 +58,20 @@ draft: true
5758`
5859)
5960
61+ var (
62+ archetypeShortcodeReplacementsPre = strings .NewReplacer (
63+ "{{<" , "{x{<" ,
64+ "{{%" , "{x{%" ,
65+ ">}}" , ">}x}" ,
66+ "%}}" , "%}x}" )
67+
68+ archetypeShortcodeReplacementsPost = strings .NewReplacer (
69+ "{x{<" , "{{<" ,
70+ "{x{%" , "{{%" ,
71+ ">}x}" , ">}}" ,
72+ "%}x}" , "%}}" )
73+ )
74+
6075func executeArcheTypeAsTemplate (s * hugolib.Site , kind , targetPath , archetypeFilename string ) ([]byte , error ) {
6176
6277 var (
@@ -86,6 +101,10 @@ func executeArcheTypeAsTemplate(s *hugolib.Site, kind, targetPath, archetypeFile
86101
87102 }
88103
104+ // The archetype template may contain shortcodes, and these does not play well
105+ // with the Go templates. Need to set some temporary delimiters.
106+ archetypeTemplate = []byte (archetypeShortcodeReplacementsPre .Replace (string (archetypeTemplate )))
107+
89108 // Reuse the Hugo template setup to get the template funcs properly set up.
90109 templateHandler := s .Deps .Tmpl .(tpl.TemplateHandler )
91110 templateName := "_text/" + helpers .Filename (archetypeFilename )
@@ -100,7 +119,7 @@ func executeArcheTypeAsTemplate(s *hugolib.Site, kind, targetPath, archetypeFile
100119 return nil , fmt .Errorf ("Failed to process archetype file %q: %s" , archetypeFilename , err )
101120 }
102121
103- archetypeContent = buff .Bytes ( )
122+ archetypeContent = [] byte ( archetypeShortcodeReplacementsPost . Replace ( buff .String ()) )
104123
105124 if ! bytes .Contains (archetypeContent , []byte ("date" )) || ! bytes .Contains (archetypeContent , []byte ("title" )) {
106125 // TODO(bep) remove some time in the future.
0 commit comments