the home site for me: also iteration 3 or 4 of my site
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add new multi img format

dunkirk.sh 7da2b000 401cc3e4

verified
+53 -11
+53 -11
scripts/preprocess.ts
··· 48 48 } 49 49 50 50 function transformImages(content: string): string { 51 - return content.replace( 52 - /!\[([^\]]*)\]\(([^)]+)\)\{([^}]+)\}/g, 51 + // Transform multiple images: !![alt1](url1)[alt2](url2){attrs} 52 + content = content.replace( 53 + /!!(\[([^\]]*)\]\(([^)]+)\))+(?:\{([^}]+)\})?/g, 54 + (match) => { 55 + // Extract all [alt](url) pairs 56 + const pairs = [...match.matchAll(/\[([^\]]*)\]\(([^)]+)\)/g)]; 57 + const urls = pairs.map(p => p[2]).join(', '); 58 + const alts = pairs.map(p => p[1]).join(', '); 59 + 60 + // Extract attrs if present 61 + const attrsMatch = match.match(/\{([^}]+)\}$/); 62 + const attrs = attrsMatch ? attrsMatch[1] : ''; 63 + 64 + const params: string[] = [`id="${urls}"`]; 65 + 66 + if (alts.trim()) { 67 + params.push(`alt="${alts}"`); 68 + } 69 + 70 + if (attrs) { 71 + const classes = attrs.match(/\.([a-zA-Z0-9_-]+)/g)?.map(c => c.slice(1)) || []; 72 + if (classes.length) { 73 + params.push(`class="${classes.join(' ')}"`); 74 + } 75 + 76 + const keyValueMatches = attrs.matchAll(/([a-zA-Z]+)=["']?([^"'\s}]+)["']?/g); 77 + for (const [, key, value] of keyValueMatches) { 78 + if (key !== 'class') { 79 + params.push(`${key}="${value.replace(/["']/g, '')}"`); 80 + } 81 + } 82 + } 83 + 84 + return `{{ imgs(${params.join(', ')}) }}`; 85 + } 86 + ); 87 + 88 + // Transform single images: ![alt](url){attrs} 89 + content = content.replace( 90 + /!\[([^\]]*)\]\(([^)]+)\)(?:\{([^}]+)\})?/g, 53 91 (match, alt, url, attrs) => { 54 92 const params: string[] = [`id="${url}"`]; 55 93 ··· 57 95 params.push(`alt="${alt}"`); 58 96 } 59 97 60 - const classes = attrs.match(/\.([a-zA-Z0-9_-]+)/g)?.map(c => c.slice(1)) || []; 61 - if (classes.length) { 62 - params.push(`class="${classes.join(' ')}"`); 63 - } 64 - 65 - const keyValueMatches = attrs.matchAll(/([a-zA-Z]+)=["']?([^"'\s}]+)["']?/g); 66 - for (const [, key, value] of keyValueMatches) { 67 - if (key !== 'class') { 68 - params.push(`${key}="${value.replace(/["']/g, '')}"`); 98 + if (attrs) { 99 + const classes = attrs.match(/\.([a-zA-Z0-9_-]+)/g)?.map(c => c.slice(1)) || []; 100 + if (classes.length) { 101 + params.push(`class="${classes.join(' ')}"`); 102 + } 103 + 104 + const keyValueMatches = attrs.matchAll(/([a-zA-Z]+)=["']?([^"'\s}]+)["']?/g); 105 + for (const [, key, value] of keyValueMatches) { 106 + if (key !== 'class') { 107 + params.push(`${key}="${value.replace(/["']/g, '')}"`); 108 + } 69 109 } 70 110 } 71 111 72 112 return `{{ img(${params.join(', ')}) }}`; 73 113 } 74 114 ); 115 + 116 + return content; 75 117 } 76 118 77 119 function processFile(filePath: string): void {