perf: Reduce initial bundle size / async bundle loading (#1456)
* feat: Move to React.lazy * perf: Remove duplicate babel/runtime * fix: Run yarn-deduplicate * Further attempts to remove rich-markdown-editor from initial chunk * perf: Lazy loading of authenticated routes * perf: Move color picker to async loading fix: Display placeholder when loading rich editor * fix: Cache bust on auto reload
This commit is contained in:
39
server/utils/parseDocumentIds.js
Normal file
39
server/utils/parseDocumentIds.js
Normal file
@ -0,0 +1,39 @@
|
||||
// @flow
|
||||
import { parser } from "rich-markdown-editor";
|
||||
|
||||
export default function parseDocumentIds(text: string): string[] {
|
||||
const value = parser.parse(text);
|
||||
let links = [];
|
||||
|
||||
function findLinks(node) {
|
||||
// get text nodes
|
||||
if (node.type.name === "text") {
|
||||
// get marks for text nodes
|
||||
node.marks.forEach((mark) => {
|
||||
// any of the marks links?
|
||||
if (mark.type.name === "link") {
|
||||
const { href } = mark.attrs;
|
||||
// any of the links to other docs?
|
||||
if (href.startsWith("/doc")) {
|
||||
const tokens = href.replace(/\/$/, "").split("/");
|
||||
const lastToken = tokens[tokens.length - 1];
|
||||
|
||||
// don't return the same link more than once
|
||||
if (!links.includes(lastToken)) {
|
||||
links.push(lastToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!node.content.size) {
|
||||
return;
|
||||
}
|
||||
|
||||
node.content.descendants(findLinks);
|
||||
}
|
||||
|
||||
findLinks(value);
|
||||
return links;
|
||||
}
|
Reference in New Issue
Block a user