summaryrefslogtreecommitdiffstats
path: root/tpl/tplimpl/template.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-17 13:04:00 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-02-24 18:59:50 +0100
commit08fdca9d9365eaf1e496a12e2af5e18617bd0e66 (patch)
tree6c6942d1b74a4160d93a997860bafd52b92025f5 /tpl/tplimpl/template.go
parent2c20f5bc00b604e72b3b7e401fbdbf9447fe3470 (diff)
Add Markdown diagrams and render hooks for code blocks
You can now create custom hook templates for code blocks, either one for all (`render-codeblock.html`) or for a given code language (e.g. `render-codeblock-go.html`). We also used this new hook to add support for diagrams in Hugo: * Goat (Go ASCII Tool) is built-in and enabled by default; just create a fenced code block with the language `goat` and start draw your Ascii diagrams. * Another popular alternative for diagrams in Markdown, Mermaid (supported by GitHub), can also be implemented with a simple template. See the Hugo documentation for more information. Updates #7765 Closes #9538 Fixes #9553 Fixes #8520 Fixes #6702 Fixes #9558
Diffstat (limited to 'tpl/tplimpl/template.go')
-rw-r--r--tpl/tplimpl/template.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go
index 44b486404..706719278 100644
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -281,15 +281,10 @@ func (t *templateExec) UnusedTemplates() []tpl.FileInfo {
for _, ts := range t.main.templates {
ti := ts.info
- if strings.HasPrefix(ti.name, "_internal/") {
- continue
- }
- if strings.HasPrefix(ti.name, "partials/inline/pagination") {
- // TODO(bep) we need to fix this. These are internal partials, but
- // they may also be defined in the project, which currently could
- // lead to some false negatives.
+ if strings.HasPrefix(ti.name, "_internal/") || ti.realFilename == "" {
continue
}
+
if _, found := t.templateUsageTracker[ti.name]; !found {
unused = append(unused, ti)
}
@@ -740,6 +735,7 @@ func (t *templateHandler) extractIdentifiers(line string) []string {
}
//go:embed embedded/templates/*
+//go:embed embedded/templates/_default/*
var embededTemplatesFs embed.FS
func (t *templateHandler) loadEmbedded() error {
@@ -757,9 +753,19 @@ func (t *templateHandler) loadEmbedded() error {
// 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/")
+ templateName := name
- if err := t.AddTemplate(internalPathPrefix+name, templ); err != nil {
- return err
+ // For the render hooks it does not make sense to preseve the
+ // double _indternal double book-keeping,
+ // just add it if its now provided by the user.
+ if !strings.Contains(path, "_default/_markup") {
+ templateName = internalPathPrefix + name
+ }
+
+ if _, found := t.Lookup(templateName); !found {
+ if err := t.AddTemplate(templateName, templ); err != nil {
+ return err
+ }
}
if aliases, found := embeddedTemplatesAliases[name]; found {