chore: improve render-link
parent
4a4292c449
commit
890d8b7e23
|
@ -1,3 +1,13 @@
|
|||
document.querySelectorAll('a[href^="mailto:"]').forEach((element) => {
|
||||
element.href = atob(element.href.replace(/^mailto:/, ''));
|
||||
document.addEventListener('click', (event) => {
|
||||
const link = event.target.closest('a');
|
||||
if (link === null || link.tagName !== 'A') return;
|
||||
if (link.hostname === location.hostname) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
open(link.href);
|
||||
});
|
||||
|
||||
document.querySelectorAll('a[data-email]').forEach((element) => {
|
||||
element.href = atob(element.dataset.email);
|
||||
delete element.dataset.email;
|
||||
});
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
{{- if hasPrefix .Destination "mailto:" -}}
|
||||
{{- $text := replace (replace .Text "-" "--") "_" "__" -}}
|
||||
{{- $icon := resources.GetRemote (printf "https://img.shields.io/badge/email-%s-blue.svg?style=flat-square" $text) -}}
|
||||
<a href="mailto:{{ .Destination | base64Encode }}"><img class="shields-icon" src="{{ $icon.Permalink }}" /></a>
|
||||
<a data-email="{{ .Destination | base64Encode }}"><img class="shields-icon" src="{{ $icon.Permalink }}" /></a>
|
||||
{{- else -}}
|
||||
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if hasPrefix .Destination "http" }} target="_blank"{{ end }}>
|
||||
<a href="{{ .Destination }}"{{ with .Title}} title="{{ . }}"{{ end }}>
|
||||
{{- .Text | safeHTML -}}
|
||||
</a>
|
||||
{{- end -}}
|
Loading…
Reference in New Issue