test
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
|
import sharedEnv from "@shared/env";
|
||||||
import parseDocumentSlug from "./parseDocumentSlug";
|
import parseDocumentSlug from "./parseDocumentSlug";
|
||||||
|
|
||||||
|
sharedEnv.URL = "https://app.outline.dev";
|
||||||
|
|
||||||
describe("#parseDocumentSlug", () => {
|
describe("#parseDocumentSlug", () => {
|
||||||
it("should work with fully qualified url", () => {
|
it("should work with fully qualified url", () => {
|
||||||
expect(
|
expect(
|
||||||
@@ -34,4 +37,10 @@ describe("#parseDocumentSlug", () => {
|
|||||||
"my-doc-y4j4tR4UuV"
|
"my-doc-y4j4tR4UuV"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should work with path and hash", () => {
|
||||||
|
expect(parseDocumentSlug("/doc/my-doc-y4j4tR4UuV#my-heading-hash")).toEqual(
|
||||||
|
"my-doc-y4j4tR4UuV"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import sharedEnv from "@shared/env";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the likely document identifier from a given url.
|
* Parse the likely document identifier from a given url.
|
||||||
*
|
*
|
||||||
@@ -8,14 +10,14 @@ export default function parseDocumentSlug(url: string) {
|
|||||||
let parsed;
|
let parsed;
|
||||||
|
|
||||||
if (url[0] === "/") {
|
if (url[0] === "/") {
|
||||||
parsed = url;
|
url = `${sharedEnv.URL}${url}`;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parsed = new URL(url).pathname;
|
parsed = new URL(url).pathname;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const split = parsed.split("/");
|
const split = parsed.split("/");
|
||||||
const indexOfDoc = split.indexOf("doc");
|
const indexOfDoc = split.indexOf("doc");
|
||||||
|
|||||||
Reference in New Issue
Block a user