diff --git a/pages/pages.go b/pages/pages.go index 7a296ee..7a7f900 100644 --- a/pages/pages.go +++ b/pages/pages.go @@ -36,7 +36,7 @@ func LoadPages(wd string) error { o = overlapfs.OverlapFS{A: wwwPages, B: wdFs} } wwwTemplates, err = template.New("pages").Funcs(template.FuncMap{ - "emailHide": EmailHide, + "emailHide": utils.EmailHide, }).ParseFS(o, "*.go.html") glob, err := fs.Glob(o, "assets/*") @@ -67,13 +67,3 @@ func RenderCss(name string) io.ReadSeeker { } 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) -} diff --git a/pages/pages_test.go b/pages/pages_test.go deleted file mode 100644 index 7d0c445..0000000 --- a/pages/pages_test.go +++ /dev/null @@ -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")) -} diff --git a/utils/email-hide.go b/utils/email-hide.go new file mode 100644 index 0000000..bcc71f1 --- /dev/null +++ b/utils/email-hide.go @@ -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) +} diff --git a/utils/email-hide_test.go b/utils/email-hide_test.go new file mode 100644 index 0000000..c9a4f76 --- /dev/null +++ b/utils/email-hide_test.go @@ -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")) +}