@@ -605,33 +605,7 @@ func initMediaStore() media.Store {
605
605
// initNotifTemplates compiles and returns e-mail notification templates that are
606
606
// used for sending ad-hoc notifications to admins and subscribers.
607
607
func initNotifTemplates (path string , fs stuffbin.FileSystem , i * i18n.I18n , cs * constants ) * notifTpls {
608
- // Register utility functions that the e-mail templates can use.
609
- funcs := template.FuncMap {
610
- "RootURL" : func () string {
611
- return cs .RootURL
612
- },
613
- "LogoURL" : func () string {
614
- return cs .LogoURL
615
- },
616
- "Date" : func (layout string ) string {
617
- if layout == "" {
618
- layout = time .ANSIC
619
- }
620
- return time .Now ().Format (layout )
621
- },
622
- "L" : func () * i18n.I18n {
623
- return i
624
- },
625
- "Safe" : func (safeHTML string ) template.HTML {
626
- return template .HTML (safeHTML )
627
- },
628
- }
629
-
630
- for k , v := range sprig .GenericFuncMap () {
631
- funcs [k ] = v
632
- }
633
-
634
- tpls , err := stuffbin .ParseTemplatesGlob (funcs , fs , "/static/email-templates/*.html" )
608
+ tpls , err := stuffbin .ParseTemplatesGlob (initTplFuncs (i , cs ), fs , "/static/email-templates/*.html" )
635
609
if err != nil {
636
610
lo .Fatalf ("error parsing e-mail notif templates: %v" , err )
637
611
}
@@ -760,11 +734,7 @@ func initHTTPServer(app *App) *echo.Echo {
760
734
}
761
735
})
762
736
763
- // Parse and load user facing templates.
764
- tpl , err := stuffbin .ParseTemplatesGlob (template.FuncMap {
765
- "L" : func () * i18n.I18n {
766
- return app .i18n
767
- }}, app .fs , "/public/templates/*.html" )
737
+ tpl , err := stuffbin .ParseTemplatesGlob (initTplFuncs (app .i18n , app .constants ), app .fs , "/public/templates/*.html" )
768
738
if err != nil {
769
739
lo .Fatalf ("error parsing public templates: %v" , err )
770
740
}
@@ -858,3 +828,32 @@ func joinFSPaths(root string, paths []string) []string {
858
828
859
829
return out
860
830
}
831
+
832
+ func initTplFuncs (i * i18n.I18n , cs * constants ) template.FuncMap {
833
+ funcs := template.FuncMap {
834
+ "RootURL" : func () string {
835
+ return cs .RootURL
836
+ },
837
+ "LogoURL" : func () string {
838
+ return cs .LogoURL
839
+ },
840
+ "Date" : func (layout string ) string {
841
+ if layout == "" {
842
+ layout = time .ANSIC
843
+ }
844
+ return time .Now ().Format (layout )
845
+ },
846
+ "L" : func () * i18n.I18n {
847
+ return i
848
+ },
849
+ "Safe" : func (safeHTML string ) template.HTML {
850
+ return template .HTML (safeHTML )
851
+ },
852
+ }
853
+
854
+ for k , v := range sprig .GenericFuncMap () {
855
+ funcs [k ] = v
856
+ }
857
+
858
+ return funcs
859
+ }
0 commit comments