diff --git a/src/components/post/PostContent.tsx b/src/components/post/PostContent.tsx index 6ce128e2..9e62c495 100644 --- a/src/components/post/PostContent.tsx +++ b/src/components/post/PostContent.tsx @@ -31,7 +31,7 @@ function optimizeImagesFromPost(markdown: string) { if (!matches) return markdown; const replacers = matches.map(match => [ match, - match.replace('https://images.', 'https://img.').replace(/\)$/, '?w=1024)'), + match.replace('https://images.velog.io', 'https://media.vlpt.us'), ]); return replacers.reduce((acc, [original, optimized]) => { return acc.replace(original, optimized); diff --git a/src/lib/optimizeImage.ts b/src/lib/optimizeImage.ts index d5d9118f..6350a17a 100644 --- a/src/lib/optimizeImage.ts +++ b/src/lib/optimizeImage.ts @@ -1,4 +1,9 @@ -export default function optimizeImage(url: string, width: number) { +export default function optimizeImage(url: string, width?: number) { if (!url.includes('https://images.velog.io')) return url; - return url.replace('://images', '://img').concat(`?w=${width}`); + + let replaced = url.replace('://images.velog.io', '://media.vlpt.us'); + if (!width) { + return replaced; + } + return replaced.concat(`?w=${width}`); }