diff --git a/docker/resume/generate-pdfs.js b/docker/resume/generate-pdfs.js index b3acf67..0d7aa82 100644 --- a/docker/resume/generate-pdfs.js +++ b/docker/resume/generate-pdfs.js @@ -122,8 +122,25 @@ async function generatePdf(browser, htmlFile) { timeout: 30000 }); - // Wait a bit for any JavaScript to finish - await page.waitForTimeout(1000); + // Wait for includes to load - check if header-include exists and has content + try { + await page.waitForFunction(() => { + const headerInclude = document.getElementById('header-include'); + // If header-include exists, wait for it to have content (includes loaded) + // If it doesn't exist, that's fine too (page doesn't use includes) + if (headerInclude) { + return headerInclude.innerHTML.trim().length > 0 || + document.querySelector('.main-nav') !== null; + } + return true; // No header-include, page is ready + }, { timeout: 10000 }); + } catch (waitError) { + // If waiting for includes times out, continue anyway + console.warn(`Warning: Includes may not have loaded for ${htmlFile}, continuing...`); + } + + // Wait a bit more for any remaining JavaScript to finish + await page.waitForTimeout(500); // Generate PDF await page.pdf({ @@ -141,8 +158,13 @@ async function generatePdf(browser, htmlFile) { console.log(`āœ“ Generated: ${pdfRelativePath}`); } catch (error) { console.error(`āœ— Failed: ${htmlFile} - ${error.message}`); + // Don't re-throw - let the caller handle it } finally { - await page.close(); + try { + await page.close(); + } catch (closeError) { + // Page might already be closed, ignore + } } } @@ -190,13 +212,25 @@ async function main() { ] }); + let successCount = 0; + let failCount = 0; + try { // Generate PDFs for each HTML file for (const htmlFile of htmlFiles) { - await generatePdf(browser, htmlFile); + try { + await generatePdf(browser, htmlFile); + successCount++; + } catch (error) { + failCount++; + console.error(`Failed to generate PDF for ${htmlFile}:`, error.message); + // Continue with next file instead of stopping + } } - console.log(`\nāœ“ PDF generation complete! Files saved to: ${PDF_DIR}`); + console.log(`\nāœ“ PDF generation complete!`); + console.log(` Success: ${successCount}, Failed: ${failCount}`); + console.log(` Files saved to: ${PDF_DIR}`); } finally { await browser.close(); server.close();