fix(rusty-image): preserve animated GIFs through markdown image processing
RustyCMS /api/transform decodes only the first frame of animated formats, which silently kills GIF animation when markdown HTML images get rewritten to /api/transform URLs. Skip the transform for `.gif` URLs so the original asset URL flows through and animation survives. Also picks up an arrow-right entry in the iconify mdi subset generated during a UI build.
This commit is contained in:
@@ -153,6 +153,10 @@ const MARKDOWN_IMAGE_PARAMS: RustyImageTransformParams = {
|
||||
|
||||
const IMG_SRC_REGEX = /<img\s+([^>]*?)src\s*=\s*["']([^"']+)["']([^>]*)>/gi;
|
||||
|
||||
// Animated formats — skip transform, keep original URL so animation survives.
|
||||
// RustyCMS /api/transform decodes only the first frame.
|
||||
const ANIMATED_EXT_REGEX = /\.gif(\?|$)/i;
|
||||
|
||||
export async function processMarkdownHtmlImages(html: string, _baseUrl?: string, transformParams: RustyImageTransformParams = MARKDOWN_IMAGE_PARAMS): Promise<string> {
|
||||
const matches = [...html.matchAll(IMG_SRC_REGEX)];
|
||||
const replacements: { index: number; length: number; newBlock: string }[] = [];
|
||||
@@ -160,7 +164,8 @@ export async function processMarkdownHtmlImages(html: string, _baseUrl?: string,
|
||||
const rawSrc = m[2];
|
||||
const url = rawSrc.startsWith('//') ? `https:${rawSrc}` : rawSrc;
|
||||
if (!url.startsWith('http')) continue;
|
||||
const transformedPath = getCmsImageUrl(url, transformParams);
|
||||
const isAnimated = ANIMATED_EXT_REGEX.test(url);
|
||||
const transformedPath = isAnimated ? url : getCmsImageUrl(url, transformParams);
|
||||
const href = transformedPath;
|
||||
const newImg = m[0].replace(rawSrc, transformedPath);
|
||||
const newBlock = `<a href="${href}" target="_blank" rel="noopener noreferrer" class="markdown-image-link">${newImg}</a>`;
|
||||
|
||||
Reference in New Issue
Block a user