Skip to content

Commit 46d18a1

Browse files
committed
Refactor link handling logic in all.js.
1 parent 1d29ef3 commit 46d18a1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

js/all.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ if (typeof($) != 'undefined') {
3434
}
3535
$('article a[href]').each(function () {
3636
const href = $(this).attr('href');
37-
if (href.startsWith('http') && !href.includes(location.hostname)) {
38-
$(this).addClass('external');
39-
$(this).append('<img src="/images/icons/link.svg" class="link" alt="external"/>');
37+
if (!href.startsWith('http') || href.includes(location.hostname)) {
38+
return;
4039
}
40+
if ($(this).find('img').length > 0) {
41+
return;
42+
}
43+
$(this).addClass('external');
44+
$(this).append('<img src="/images/icons/link.svg" class="link" alt="external"/>');
4145
});
4246
if ($('.buttons').css('display') !== 'none') {
4347
$(".button[href!='#']").click(

0 commit comments

Comments
 (0)