feat: enhance external link rendering
This commit is contained in:
parent
46e4048de2
commit
f2e20a1499
7
layouts/_default/_markup/render_link.html
Normal file
7
layouts/_default/_markup/render_link.html
Normal 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>
|
12
layouts/partials/extend_head.html
Normal file
12
layouts/partials/extend_head.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user