feat: enhance external link rendering

This commit is contained in:
Hiiruki 2023-09-04 18:02:37 +07:00
parent 46e4048de2
commit f2e20a1499
No known key found for this signature in database
GPG Key ID: E40D7521AF5886C8
2 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,7 @@
<a href="{{ .Destination | safeURL }}"
{{ with .Title}} title="{{ . }}"{{ end }}
{{ if strings.HasPrefix .Destination "http" }}
target="_blank" rel="external nofollow noopener noreferrer"
{{ end }}>
{{ .Text | safeHTML }}
</a>

View File

@ -0,0 +1,12 @@
<script>
document.addEventListener('DOMContentLoaded', function () {
var links = document.getElementsByTagName("a");
var i;
for (i = 0; i < links.length; i++) {
if (location.hostname !== links[i].hostname) {
links[i].rel = "external nofollow noopener noreferrer";
links[i].target = "_blank";
}
}
});
</script>