Files
outline/shared/utils/parseCollectionSlug.ts
YouLL d551a1a10b feat: collection mentions (#8529)
* feat: init collection mention

* refactor: dedicated search helper function for collection mentions

* feat: add test for collection search function helper

* feat: parseCollectionSlug

* feat: isCollectionUrl

* feat: add collection mention to paste handler

* fix: update translation of mention keyboard shortcut

* fix: keyboard shortcut mention label

* fix: missing teamId in search helper functioN

* chore: update translations

---------

Co-authored-by: Tom Moor <tom@getoutline.com>
2025-03-03 19:03:27 -08:00

26 lines
563 B
TypeScript

import sharedEnv from "../env";
/**
* Parse the likely collection identifier from a given url.
*
* @param url The url to parse.
* @returns A collection identifier or undefined if not found.
*/
export default function parseCollectionSlug(url: string) {
let parsed;
if (url[0] === "/") {
url = `${sharedEnv.URL}${url}`;
}
try {
parsed = new URL(url).pathname;
} catch (err) {
return;
}
const split = parsed.split("/");
const indexOfCollection = split.indexOf("collection");
return split[indexOfCollection + 1] ?? undefined;
}