@@ -86,6 +86,53 @@ export async function generateOGImage(
8686) : Promise < void > {
8787 const opts = { ...defaultOptions , ...options } ;
8888
89+ // Layout speciale per la default image (id === 0)
90+ if ( initiative . id === 0 ) {
91+ // Titolo e sottotitolo centrati
92+ const title = 'Referendum e Iniziative Popolari' ;
93+ const subtitle = 'Scopri e partecipa alle iniziative democratiche' ;
94+ const titleFontSize = 60 ;
95+ const subtitleFontSize = 36 ;
96+ const titleY = opts . height / 2 - 30 ;
97+ const subtitleY = opts . height / 2 + 40 ;
98+ const brandText = "Un'idea di onData" ;
99+
100+ const svgTemplate = `
101+ <svg width="${ opts . width } " height="${ opts . height } " xmlns="http://www.w3.org/2000/svg">
102+ <defs>
103+ <linearGradient id="bg" x1="0%" y1="0%" x2="100%" y2="100%">
104+ <stop offset="0%" style="stop-color:${ opts . backgroundColor } ;stop-opacity:1" />
105+ <stop offset="100%" style="stop-color:#1e3a8a;stop-opacity:1" />
106+ </linearGradient>
107+ <pattern id="dots" x="0" y="0" width="40" height="40" patternUnits="userSpaceOnUse">
108+ <circle cx="20" cy="20" r="2" fill="rgba(255,255,255,0.1)" />
109+ </pattern>
110+ </defs>
111+ <rect width="100%" height="100%" fill="url(#bg)" />
112+ <rect width="100%" height="100%" fill="url(#dots)" />
113+ <text x="50%" y="${ titleY } " text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="${ titleFontSize } " font-weight="700" fill="${ opts . textColor } ">${ title } </text>
114+ <text x="50%" y="${ subtitleY } " text-anchor="middle" font-family="system-ui, -apple-system, sans-serif" font-size="${ subtitleFontSize } " font-weight="400" fill="rgba(255,255,255,0.85)">${ subtitle } </text>
115+ <text x="${ opts . width - 60 } " y="${ opts . height - 40 } " text-anchor="end" font-family="system-ui, -apple-system, sans-serif" font-size="20" font-weight="500" fill="rgba(255,255,255,0.7)">${ brandText } </text>
116+ <circle cx="${ opts . width - 100 } " cy="100" r="80" fill="rgba(255,255,255,0.05)" />
117+ <circle cx="${ opts . width - 100 } " cy="100" r="50" fill="rgba(255,255,255,0.1)" />
118+ </svg>
119+ ` ;
120+
121+ try {
122+ const pngBuffer = await sharp ( Buffer . from ( svgTemplate ) )
123+ . png ( { quality : 90 , compressionLevel : 6 } )
124+ . toBuffer ( ) ;
125+ const dir = outputPath . substring ( 0 , outputPath . lastIndexOf ( '/' ) ) ;
126+ mkdirSync ( dir , { recursive : true } ) ;
127+ writeFileSync ( outputPath , pngBuffer ) ;
128+ console . log ( `✅ Immagine OG generata: ${ outputPath } ` ) ;
129+ } catch ( error ) {
130+ console . error ( `❌ Errore nella generazione dell'immagine di default:` , error ) ;
131+ throw error ;
132+ }
133+ return ;
134+ }
135+
89136 const title = initiative . titolo || 'Iniziativa Popolare' ;
90137 const category = initiative . idDecCatIniziativa ?. nome || 'GENERALE' ;
91138 const status = initiative . idDecStatoIniziativa ?. nome || 'IN RACCOLTA FIRME' ;
0 commit comments