Skip to content

Commit

Permalink
fix: href property issue in gatsby build
Browse files Browse the repository at this point in the history
  • Loading branch information
Syed-Ali-Abbas-Zaidi committed Oct 13, 2023
1 parent a5917c2 commit 3ae7d49
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ export function convertKeyNames(object, nameMap) {
* @returns {Object}
*/
export function parseURL(url) {
const parser = document?.createElement('a');
parser.href = url;
return parser;
if (typeof document !== 'undefined') {
const parser = document?.createElement('a');
parser.href = url;
return parser;
}

return {};
}

/**
Expand All @@ -151,7 +155,8 @@ export function parseURL(url) {
* @returns {string}
*/
export function getPath(url) {
return parseURL(url).pathname;
const urlData = parseURL(url);
return Object.keys(urlData).length === 0 ? '' : urlData?.pathname;
}

/**
Expand Down

0 comments on commit 3ae7d49

Please sign in to comment.