@ -1,9 +1,12 @@
|
||||
import { getAbsoluteUrl } from '~/utils/url/getAbsoluteUrl';
|
||||
|
||||
export const getUrlHostname = (url: string) => {
|
||||
export const getUrlHostname = (
|
||||
url: string,
|
||||
options?: { keepPath?: boolean },
|
||||
) => {
|
||||
try {
|
||||
const absoluteUrl = getAbsoluteUrl(url);
|
||||
return new URL(absoluteUrl).hostname.replace(/^www\./i, '');
|
||||
const parsedUrl = new URL(getAbsoluteUrl(url));
|
||||
return `${parsedUrl.hostname.replace(/^www\./i, '')}${options?.keepPath && parsedUrl.pathname !== '/' ? parsedUrl.pathname : ''}`;
|
||||
} catch {
|
||||
return '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user