mirror of
https://github.com/1f349/lavender.git
synced 2025-01-21 06:06:30 +00:00
Move email hide to utils
This commit is contained in:
parent
a0b3570aab
commit
60890d766c
@ -36,7 +36,7 @@ func LoadPages(wd string) error {
|
|||||||
o = overlapfs.OverlapFS{A: wwwPages, B: wdFs}
|
o = overlapfs.OverlapFS{A: wwwPages, B: wdFs}
|
||||||
}
|
}
|
||||||
wwwTemplates, err = template.New("pages").Funcs(template.FuncMap{
|
wwwTemplates, err = template.New("pages").Funcs(template.FuncMap{
|
||||||
"emailHide": EmailHide,
|
"emailHide": utils.EmailHide,
|
||||||
}).ParseFS(o, "*.go.html")
|
}).ParseFS(o, "*.go.html")
|
||||||
|
|
||||||
glob, err := fs.Glob(o, "assets/*")
|
glob, err := fs.Glob(o, "assets/*")
|
||||||
@ -67,13 +67,3 @@ func RenderCss(name string) io.ReadSeeker {
|
|||||||
}
|
}
|
||||||
return bytes.NewReader(b)
|
return bytes.NewReader(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func EmailHide(a string) string {
|
|
||||||
b := []byte(a)
|
|
||||||
for i := range b {
|
|
||||||
if b[i] != '@' && b[i] != '.' {
|
|
||||||
b[i] = 'x'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
package pages
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestEmailHide(t *testing.T) {
|
|
||||||
assert.Equal(t, "xx", EmailHide("hi"))
|
|
||||||
assert.Equal(t, "xxxxxxx@xxxxxxx.xxx", EmailHide("example@example.com"))
|
|
||||||
}
|
|
12
utils/email-hide.go
Normal file
12
utils/email-hide.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func EmailHide(email string) string {
|
||||||
|
return strings.Map(func(r rune) rune {
|
||||||
|
if r != '@' && r != '.' {
|
||||||
|
return 'x'
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}, email)
|
||||||
|
}
|
11
utils/email-hide_test.go
Normal file
11
utils/email-hide_test.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEmailHide(t *testing.T) {
|
||||||
|
require.Equal(t, "xx", EmailHide("hi"))
|
||||||
|
require.Equal(t, "xxxxxxx@xxxxxxx.xxx", EmailHide("example@example.com"))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user