Skip to content

Commit 0dea70e

Browse files
committed
feat: handle encode issue for images inside post
1 parent 43d2a77 commit 0dea70e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/post/PostContent.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ function optimizeImagesFromPost(markdown: string) {
2929
/(?:!\[(.*?)\]\(https:\/\/images.velog.io\/(.*?)\))/g,
3030
);
3131
if (!matches) return markdown;
32-
const replacers = matches.map((match) => [
33-
match,
34-
match.replace('https://images.velog.io', 'https://velog.velcdn.com'),
35-
]);
32+
console.log(matches);
33+
const replacers = matches.map((match) => {
34+
const filename =
35+
match.match(/https:\/\/images.velog.io\/(.*?)\)/)?.[1] ?? '';
36+
console.log(filename);
37+
const proeperlyEncoded = encodeURIComponent(decodeURI(filename));
38+
return [
39+
match,
40+
match
41+
.replace('https://images.velog.io', 'https://velog.velcdn.com')
42+
.replace(filename, proeperlyEncoded),
43+
];
44+
});
3645
return replacers.reduce((acc, [original, optimized]) => {
3746
return acc.replace(original, optimized);
3847
}, markdown);

0 commit comments

Comments
 (0)