From bde012b309486d4969f273747c8f593250dac7ec Mon Sep 17 00:00:00 2001
From: bb1950328 <bb1950328@gmail.com>
Date: Sat, 30 Jan 2021 12:47:47 +0000
Subject: [PATCH] small optimizations to satisfy Google Lighthouse a bit more
---
assets/js/index.js | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/assets/js/index.js b/assets/js/index.js
index 65cc1a9..b585603 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -131,8 +131,9 @@
if(links) {
Array.from(links).forEach(function(link, index){
let target, rel, blank, noopener, attr1, attr2, url, isExternal;
- url = elemAttribute(link, 'href');
- isExternal = (url && typeof url == 'string' && url.startsWith('http')) && !url.startsWith(rootURL) && link.closest(contentWrapperClass);
+ url = new URL(elemAttribute(link, 'href'));
+ // definition of same origin: RFC 6454, section 4 (https://tools.ietf.org/html/rfc6454#section-4)
+ isExternal = url.host !== location.host || url.protocol !== location.protocol || url.port !== location.port;
if(isExternal) {
target = 'target';
rel = 'rel';
--
Gitblit v1.10.0