mirror of
https://github.com/outline/outline.git
synced 2026-12-06 11:12:32 +03:00
* fix: Correct logic errors in shared utilities * fix: Restore per-column cells in getCellsInRow and convert every attachment url The g flag made the attachment regex skip every second match, and removing duplicate cells broke callers that index getCellsInRow by column. * test: Cover uppercase attachment URLs * revert: Remove uncertain fixes
30 lines
617 B
TypeScript
30 lines
617 B
TypeScript
import sharedEnv from "../env";
|
|
|
|
/**
|
|
* Parse the likely document identifier from a given url.
|
|
*
|
|
* @param url The url to parse.
|
|
* @returns A document identifier or undefined if not found.
|
|
*/
|
|
export default function parseDocumentSlug(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 indexOfDoc = split.indexOf("doc");
|
|
if (indexOfDoc === -1) {
|
|
return undefined;
|
|
}
|
|
const slug = split[indexOfDoc + 1];
|
|
return slug ? slug : undefined;
|
|
}
|