From 1a0e42147ec04f7160f667ed264d02c5cf1fcf85 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Sun, 5 Jun 2022 00:34:24 +0300 Subject: [PATCH 1/2] feat: cleanText improvements --- src/web/utils.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/web/utils.ts b/src/web/utils.ts index 70f8945..a55d34f 100644 --- a/src/web/utils.ts +++ b/src/web/utils.ts @@ -14,8 +14,8 @@ export const getBasePath = () => { }; export const cleanText = (text: string): string => { - // Note: should no longer be necessary? - // Still needed for e.g. /questions/rootclaim-what-caused-the-disappearance-of-malaysia-airlines-flight-370 + // TODO - move to GraphQL: + // { description(clean: true, truncate: 250) } let textString = !!text ? text : ""; textString = textString .replaceAll("] (", "](") @@ -23,12 +23,13 @@ export const cleanText = (text: string): string => { .replaceAll("( [", "([") .replaceAll(") ,", "),") .replaceAll("==", "") // Denotes a title in markdown - .replaceAll("Background\n", "") - .replaceAll("Context\n", "") + .replaceAll(/^#+ /gm, "") + .replaceAll(/^Background\n/gm, "") + .replaceAll(/^Context\n/gm, "") .replaceAll("--- \n", "- ") .replaceAll(/\[(.*?)\]\(.*?\)/g, "$1"); textString = textString.slice(0, 1) == "=" ? textString.slice(1) : textString; - //console.log(textString) + return textString; }; From 7a5b7837f5d72fe7d58d150edf2600388248a7a9 Mon Sep 17 00:00:00 2001 From: Vyacheslav Matyukhin Date: Sun, 5 Jun 2022 00:38:16 +0300 Subject: [PATCH 2/2] fix: better heading cleanups --- src/web/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/utils.ts b/src/web/utils.ts index a55d34f..42f57bb 100644 --- a/src/web/utils.ts +++ b/src/web/utils.ts @@ -23,7 +23,7 @@ export const cleanText = (text: string): string => { .replaceAll("( [", "([") .replaceAll(") ,", "),") .replaceAll("==", "") // Denotes a title in markdown - .replaceAll(/^#+ /gm, "") + .replaceAll(/^#+\s+/gm, "") .replaceAll(/^Background\n/gm, "") .replaceAll(/^Context\n/gm, "") .replaceAll("--- \n", "- ")