@@ -89,21 +89,33 @@ function extractExcerpt(article) {
8989 return striptags ( content . slice ( 0 , content . indexOf ( "\n" ) ) ) ;
9090}
9191
92- async function contentImgUrlShortcode ( src ) {
92+ async function contentImgUrlShortcode ( src , options = { } ) {
9393 const inputDir = path . dirname ( this . page . inputPath ) ;
9494 const imagePath = path . resolve ( inputDir , src ) ;
9595 const outputDir = path . dirname ( this . page . outputPath ) ;
9696 const urlPath = this . page . url ;
9797
98- const stats = await Image ( imagePath , {
99- widths : [ 1200 ] , // Width for Open Graph image
100- formats : [ "png" ] ,
98+ const imageOptions = {
99+ widths : [ options . width || null ] ,
100+ formats : [ options . format || "png" ] ,
101101 outputDir : outputDir , // Output directory
102102 urlPath : urlPath , // Public URL path
103103 filenameFormat : function ( hash , src , width , format ) {
104104 return `${ hash } -${ width } .${ format } ` ;
105+ } ,
106+ cacheOptions : {
107+ duration : "1w"
105108 }
106- } ) ;
109+ } ;
110+
111+ const img = await Image ( imagePath , imageOptions ) ;
112+
113+ // Get the generated image URL
114+ const formatData = img [ imageOptions . formats [ 0 ] ] ;
115+ if ( ! formatData || ! formatData [ 0 ] ) {
116+ throw new Error ( `Image processing failed for ${ src } ` ) ;
117+ }
118+ const absoluteUrl = formatData [ 0 ] . url ;
107119
108- return stats . png [ 0 ] . url ; // Return the URL of the processed image
120+ return absoluteUrl ; // Return the URL of the processed image
109121}
0 commit comments