Skip to content

Commit e740e79

Browse files
committed
Fixes removeMd crashing bug
1 parent f494898 commit e740e79

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

velog-backend/src/lib/common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export const extractKeys = (object: any, params: Array<string>): any => {
7575

7676
export function formatShortDescription(markdown: string): string {
7777
const replaced = markdown
78+
.replace(/ +/g, '')
79+
.replace(/--/g, '')
80+
.replace(/\|/g, '')
7881
.replace(/\n/g, ' ')
7982
.replace(/```(.*)```/g, '')
8083
.replace(/[<>]/g, '');

velog-frontend/src/lib/common.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,19 @@ export const fromNow = (date: string) => {
9494
};
9595

9696
export function convertToPlainText(markdown: string): string {
97-
if (!markdown) return '';
98-
const replaced = markdown.replace(/\n/g, ' ').replace(/```(.*)```/g, '');
99-
return removeMd(replaced)
100-
.slice(0, 150)
101-
.replace(/#/g, '');
97+
const replaced = markdown
98+
.replace(/ +/g, '')
99+
.replace(/--/g, '')
100+
.replace(/\|/g, '')
101+
.replace(/\n/g, ' ')
102+
.replace(/```(.*)```/g, '')
103+
.replace(/[<>]/g, '');
104+
105+
return (
106+
removeMd(replaced.slice(0, 500))
107+
.slice(0, 200)
108+
.replace(/#/g, '') + (replaced.length > 200 ? '...' : '')
109+
);
102110
}
103111

104112
export function resizeImage(url: string, width?: number = 256) {

0 commit comments

Comments
 (0)