Преглед изворни кода

email: fix unable to override templates in custom directory (#7905)

Co-authored-by: Joe Chen <jc@unknwon.io>
SongZihuan пре 2 месеци
родитељ
комит
46a84fdad5
3 измењених фајлова са 7 додато и 4 уклоњено
  1. 1 0
      CHANGELOG.md
  2. 3 2
      internal/cmd/web.go
  3. 3 2
      internal/email/email.go

+ 1 - 0
CHANGELOG.md

@@ -17,6 +17,7 @@ All notable changes to Gogs are documented in this file.
 
 - Submodules using `ssh://` protocol and a port number are not rendered correctly. [#4941](https://github.com/gogs/gogs/issues/4941)
 - Missing link to user profile on the first commit in commits history page. [#7404](https://github.com/gogs/gogs/issues/7404)
+- Unable to override email templates in custom directory. [#7905](https://github.com/gogs/gogs/pull/7905)
 
 ## 0.13.2
 

+ 3 - 2
internal/cmd/web.go

@@ -112,14 +112,15 @@ func newMacaron() *macaron.Macaron {
 		},
 	))
 
+	customDir := filepath.Join(conf.CustomDir(), "templates")
 	renderOpt := macaron.RenderOptions{
 		Directory:         filepath.Join(conf.WorkDir(), "templates"),
-		AppendDirectories: []string{filepath.Join(conf.CustomDir(), "templates")},
+		AppendDirectories: []string{customDir},
 		Funcs:             template.FuncMap(),
 		IndentJSON:        macaron.Env != macaron.PROD,
 	}
 	if !conf.Server.LoadAssetsFromDisk {
-		renderOpt.TemplateFileSystem = templates.NewTemplateFileSystem("", renderOpt.AppendDirectories[0])
+		renderOpt.TemplateFileSystem = templates.NewTemplateFileSystem("", customDir)
 	}
 	m.Use(macaron.Renderer(renderOpt))
 

+ 3 - 2
internal/email/email.go

@@ -40,9 +40,10 @@ var (
 // render renders a mail template with given data.
 func render(tpl string, data map[string]any) (string, error) {
 	tplRenderOnce.Do(func() {
+		customDir := filepath.Join(conf.CustomDir(), "templates")
 		opt := &macaron.RenderOptions{
 			Directory:         filepath.Join(conf.WorkDir(), "templates", "mail"),
-			AppendDirectories: []string{filepath.Join(conf.CustomDir(), "templates", "mail")},
+			AppendDirectories: []string{filepath.Join(customDir, "mail")},
 			Extensions:        []string{".tmpl", ".html"},
 			Funcs: []template.FuncMap{map[string]any{
 				"AppName": func() string {
@@ -60,7 +61,7 @@ func render(tpl string, data map[string]any) (string, error) {
 			}},
 		}
 		if !conf.Server.LoadAssetsFromDisk {
-			opt.TemplateFileSystem = templates.NewTemplateFileSystem("mail", opt.AppendDirectories[0])
+			opt.TemplateFileSystem = templates.NewTemplateFileSystem("mail", customDir)
 		}
 
 		ts := macaron.NewTemplateSet()