Insert document title when pasting internal doc url (#6352)

* refactor

* DRY
This commit is contained in:
Tom Moor
2024-01-06 13:44:11 -08:00
committed by GitHub
parent 08b1755f8e
commit 92cbceb6c7
14 changed files with 123 additions and 51 deletions

View File

@@ -38,10 +38,28 @@ export function isInternalUrl(href: string) {
return (
outline.host === domain.host ||
(domain.host.endsWith(getBaseDomain()) &&
!RESERVED_SUBDOMAINS.includes(domain.teamSubdomain))
!RESERVED_SUBDOMAINS.find((reserved) => domain.host.startsWith(reserved)))
);
}
/**
* Returns true if the given string is a link to a documement.
*
* @param options Parsing options.
* @returns True if a document, false otherwise.
*/
export function isDocumentUrl(url: string) {
try {
const parsed = new URL(url);
return (
isInternalUrl(url) &&
(parsed.pathname.startsWith("/doc/") || parsed.pathname.startsWith("/d/"))
);
} catch (err) {
return false;
}
}
/**
* Returns true if the given string is a url.
*