Add parameter to display a text instead of the e-mail address
- See issue #1. - Credits goes to @chris-79 for the idea.
This commit is contained in:
parent
7cfc7f3688
commit
ad5c047cd5
14
README.md
14
README.md
|
@ -25,10 +25,20 @@ This is not a standalone theme. It is a [Hugo](https://gohugo.io) theme componen
|
|||
```go
|
||||
{{< cloakemail address="john.doe@example.com" >}}
|
||||
```
|
||||
or, if you want to specify a protocol and/or a class,
|
||||
4. You may specify a protocol, this way:
|
||||
```go
|
||||
{{< cloakemail address="john.doe@example.com" protocol="xmpp" class="vip" >}}
|
||||
{{< cloakemail address="john.doe@example.com" protocol="xmpp" >}}
|
||||
```
|
||||
5. or a class, this way:
|
||||
```go
|
||||
{{< cloakemail address="john.doe@example.com" class="vip" >}}
|
||||
```
|
||||
6. or a text to be display instead of the e-mail address, this way:
|
||||
```go
|
||||
{{< cloakemail address="john.doe@example.com" display="Send us a mail!" >}}
|
||||
```
|
||||
|
||||
All parameters can be combined.
|
||||
|
||||
### Credits
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
{{- $address := .Get "address" | default (.Get 0) -}}
|
||||
{{- $protocol := .Get "protocol" | default "mailto" -}}
|
||||
{{- $class := .Get "class" -}}
|
||||
{{- $displaytext := .Get "display" -}}
|
||||
{{- $parts := split $address "@" -}}
|
||||
{{- $user := (index $parts 0) -}}
|
||||
{{- $domain := (index $parts 1) -}}
|
||||
|
@ -20,7 +21,11 @@
|
|||
var link = document.createElement("a");
|
||||
var address = "{{ range $index := seq (sub (len $user) 1) 0}}{{ substr $user $index 1}}{{ end }}".split('').reverse().join('') + "@" + "{{ range $index := seq (sub (len $domain) 1) 0}}{{ substr $domain $index 1}}{{ end }}".split('').reverse().join('');
|
||||
link.href = {{ $protocol }} + ":" + address;
|
||||
{{ with $displaytext }}
|
||||
link.innerText = {{ $displaytext }};
|
||||
{{ else }}
|
||||
link.innerText = address;
|
||||
{{ end }}
|
||||
{{ with $class }}
|
||||
link.className = "{{ $class }}";
|
||||
{{ end }}
|
||||
|
|
Loading…
Reference in New Issue