Add template helper isEmail()
This commit is contained in:
parent
39b03cc393
commit
29c5d82016
3 changed files with 12 additions and 4 deletions
server/template
|
@ -15,7 +15,7 @@
|
|||
</span>
|
||||
{{ if .entry.Author }}
|
||||
<span class="entry-author">
|
||||
{{ if contains .entry.Author "@" }}
|
||||
{{ if isEmail .entry.Author }}
|
||||
- <a href="mailto:{{ .entry.Author }}">{{ .entry.Author }}</a>
|
||||
{{ else }}
|
||||
– <em>{{ .entry.Author }}</em>
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"net/mail"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -64,6 +65,13 @@ func (e *Engine) parseAll() {
|
|||
|
||||
return parsedURL.Host
|
||||
},
|
||||
"isEmail": func(str string) bool {
|
||||
_, err := mail.ParseAddress(str)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
"hasPrefix": func(str, prefix string) bool {
|
||||
return strings.HasPrefix(str, prefix)
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// 2017-11-25 10:47:30.359140331 -0800 PST m=+0.015268437
|
||||
// 2017-11-25 17:05:58.40092186 -0800 PST m=+0.019242510
|
||||
|
||||
package template
|
||||
|
||||
|
@ -463,7 +463,7 @@ var templateViewsMap = map[string]string{
|
|||
</span>
|
||||
{{ if .entry.Author }}
|
||||
<span class="entry-author">
|
||||
{{ if contains .entry.Author "@" }}
|
||||
{{ if isEmail .entry.Author }}
|
||||
- <a href="mailto:{{ .entry.Author }}">{{ .entry.Author }}</a>
|
||||
{{ else }}
|
||||
– <em>{{ .entry.Author }}</em>
|
||||
|
@ -1054,7 +1054,7 @@ var templateViewsMapChecksums = map[string]string{
|
|||
"edit_category": "cee720faadcec58289b707ad30af623d2ee66c1ce23a732965463250d7ff41c5",
|
||||
"edit_feed": "c5bc4c22bf7e8348d880395250545595d21fb8c8e723fc5d7cca68e25d250884",
|
||||
"edit_user": "c835d78f7cf36c11533db9cef253457a9003987d704070d59446cb2b0e84dcb9",
|
||||
"entry": "32e605edd6d43773ac31329d247ebd81d38d974cd43689d91de79fffec7fe04b",
|
||||
"entry": "2d7524cfd743f8a74fcf6bf7f4631fe4a61bb595173545d49793c845a450ff03",
|
||||
"feed_entries": "9aff923b6c7452dec1514feada7e0d2bbc1ec21c6f5e9f48b2de41d1b731ffe4",
|
||||
"feeds": "c22af39b42ba9ca69ea0914ca789303ec2c5b484abcd4eaa49016e365381257c",
|
||||
"history": "947603cbde888516e62925f5d08fb0b13d930623d3ee4c690dbc22612fdda75e",
|
||||
|
|
Loading…
Add table
Reference in a new issue