chore: improve render-link

pull/225/head
Septs 2021-12-25 06:56:39 +08:00
parent 4a4292c449
commit 890d8b7e23
No known key found for this signature in database
GPG Key ID: 6EC3B9D7E6EE828F
2 changed files with 14 additions and 4 deletions

View File

@ -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;
});

View File

@ -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 -}}