master
Evan Chen 2021-12-24 13:31:33 +08:00
parent 6ccf516c58
commit 4fb43d081c
4 changed files with 86 additions and 0 deletions

View File

@ -294,6 +294,39 @@
{{ end }}
{{ end }}
{{/* actions */}}
{{with .Actions}}
{{if gt (len .) 0}}
{{range $action := .}}
<p>{{ $action.Instructions }}</p>
{{/* count width */}}
{{ $length := len $action.Button.Text }}
{{ $width := add (mul $length 9) 20 }}
{{if (lt $width 200)}}{{$width = 200}}{{else if (gt $width 570)}}{{$width = 570}}{{else}}{{end}}
{{/* button */}}
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<div>
{{ if $action.Button.Text }}
<a href="{{ $action.Button.Link }}" class="button"
style="{{ with $action.Button.Color }}background-color: {{ . }};{{ end }} {{ with $action.Button.TextColor }}color: {{ . }};{{ end }} width: {{$width}}px;"
target="_blank">
{{ $action.Button.Text }}
</a>
{{end}}
{{ if $action.InviteCode }}
<span class="invite-code">{{ $action.InviteCode }}</span>
{{end}}
</div>
</td>
</tr>
</table>
{{end}}
{{end}}
{{end}}
{{/* Main Body */}}
{{ if (ne .Content "") }}
{{ .Content | ToHTML }}
@ -314,6 +347,7 @@
<br />
{{ if .Sender }}{{.Sender}}{{else}}{{.App.Name}}{{end}}
</p>
</td>
</tr>
</table>

View File

@ -21,6 +21,25 @@ type App struct {
Copyright string
}
type Button struct {
Text string
Link string
// Color of the button, default blue(#3869D4)
Color string
// TextColor of the button, default blue(#ffffff)
TextColor string
}
type Action struct {
// Instructions text show before button
Instructions string
// InviteCode should not be used with button
InviteCode string
Button Button
}
type Body struct {
// App replaced with global config
App App
@ -29,6 +48,8 @@ type Body struct {
Content string
Outros []string
Actions []Action
// Greeting ignored if empty
Greeting string
// Receiver ignored if Greeting or Receiver empty

View File

@ -10,6 +10,31 @@ func TestSendSimple(t *testing.T) {
[]string{"test@kumoly.io"}, "TestSendSimple",
&Body{
Content: `Testing`,
Actions: []Action{
{Instructions: "click",
Button: Button{
Text: "click me", Link: "kumoly.io",
},
},
{Instructions: "long button",
Button: Button{
Text: `long long
longlonglonglonglonglonglonglonglonglong
longlonglonglonglonglonglonglonglonglong
longlonglonglonglonglonglonglonglonglong
text`,
Link: "kumoly.io",
Color: "#90CAF9",
TextColor: "#000000",
},
},
{Instructions: "None",
Button: Button{},
},
{Instructions: "click",
InviteCode: "12354",
},
},
},
)
if err != nil {

View File

@ -23,6 +23,12 @@ var mdParser = goldmark.New(
func init() {
engine = template.Must(template.New("email").Funcs(template.FuncMap{
"ToHTML": ToHTML,
"add": func(a, b int) int {
return a + b
},
"mul": func(a, b int) int {
return a * b
},
}).Parse(mailTmpl))
}