diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-04-23 13:40:05 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-04-23 15:04:35 +0200 |
commit | 0d86a32d8f3031e2124c8005b680b597f3c0e558 (patch) | |
tree | ebf2d60b31c3389480b8c2b87f0e06e9b1b734cd /tpl | |
parent | 65c502cc8110e49540cbe2b49ecd5a8ede9e67a1 (diff) |
Make the shortcode template lookup for output formats stable
Fixes #7774
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/tplimpl/template.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go index 60e3b7df9..75f25edac 100644 --- a/tpl/tplimpl/template.go +++ b/tpl/tplimpl/template.go @@ -19,6 +19,7 @@ import ( "path/filepath" "reflect" "regexp" + "sort" "strings" "sync" "time" @@ -814,6 +815,24 @@ func (t *templateHandler) postTransform() error { } } + for _, v := range t.shortcodes { + sort.Slice(v.variants, func(i, j int) bool { + v1, v2 := v.variants[i], v.variants[j] + name1, name2 := v1.ts.Name(), v2.ts.Name() + isHTMl1, isHTML2 := strings.HasSuffix(name1, "html"), strings.HasSuffix(name2, "html") + + // There will be a weighted selection later, but make + // sure these are sorted to get a stable selection for + // output formats missing specific templates. + // Prefer HTML. + if isHTMl1 || isHTML2 && !(isHTMl1 && isHTML2) { + return isHTMl1 + } + + return name1 < name2 + }) + } + return nil } |