Exclude domains from link previews

This commit is contained in:
trevor-signal 2023-05-04 10:07:48 -04:00 committed by Josh Perez
parent d42aec4dac
commit ff4ea76005
2 changed files with 44 additions and 10 deletions

View file

@ -48,11 +48,35 @@ export function shouldPreviewHref(href: string): boolean {
return Boolean(
url &&
url.protocol === 'https:' &&
url.hostname !== 'debuglogs.org' &&
!isDomainExcluded(url) &&
!isLinkSneaky(href)
);
}
const EXCLUDED_DOMAINS = [
'debuglogs.org',
'example',
'example.com',
'example.net',
'example.org',
'invalid',
'localhost',
'onion',
'test',
];
function isDomainExcluded(url: URL): boolean {
for (const excludedDomain of EXCLUDED_DOMAINS) {
if (
url.hostname.endsWith(`.${excludedDomain}`) ||
url.hostname === excludedDomain
) {
return true;
}
}
return false;
}
const DIRECTIONAL_OVERRIDES = /[\u202c\u202d\u202e]/;
const UNICODE_DRAWING = /[\u2500-\u25FF]/;