Fixed include object. Fixed qu's undefined URL handling.

This commit is contained in:
DebaucheryLibrarian
2020-09-08 03:26:34 +02:00
parent 7c6243cf33
commit 03ba35d65a
8 changed files with 24 additions and 14 deletions

View File

@@ -40,6 +40,10 @@ function formatDate(dateValue, format, inputFormat) {
}
function prefixUrl(urlValue, origin, protocol = 'https') {
if (!urlValue) {
return null;
}
if (/^http/.test(urlValue)) {
return urlValue;
}
@@ -52,7 +56,11 @@ function prefixUrl(urlValue, origin, protocol = 'https') {
return `${origin}${urlValue}`;
}
return `${origin}/${urlValue}`;
if (origin) {
return `${origin}/${urlValue}`;
}
return urlValue;
}
function q(context, selector, attrArg, applyTrim = true) {
@@ -217,7 +225,7 @@ function images(context, selector = 'img', attr, { origin, protocol = 'https' }
function url(context, selector = 'a', attr = 'href', { origin, protocol = 'https' } = {}) {
const urlEl = q(context, selector, attr);
return attr ? prefixUrl(urlEl, origin, protocol) : urlEl;
return prefixUrl(urlEl, origin, protocol);
}
function urls(context, selector = 'a', attr = 'href', { origin, protocol = 'https' } = {}) {