Blog Post Expansion Tool

Blog Post Expansion Tool

Transform your brief ideas into a structured, expanded draft.

${expandedContent.conclusion}

`; postPreviewOutput.innerHTML = html; downloadPdfBtn.classList.remove('hidden'); }; const downloadPDF = () => { if (!expandedContent) return; const { jsPDF } = window; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const PAGE_WIDTH = pdf.internal.pageSize.getWidth(); const MARGIN = 60; const MAX_WIDTH = PAGE_WIDTH - MARGIN * 2; let y = MARGIN; const checkPageBreak = (spaceNeeded) => { if (y + spaceNeeded > pdf.internal.pageSize.getHeight() - MARGIN) { pdf.addPage(); y = MARGIN; } }; // Title pdf.setFontSize(26); pdf.setFont('helvetica', 'bold'); pdf.setTextColor(28, 25, 23); // stone-900 const titleLines = pdf.splitTextToSize(expandedContent.title, MAX_WIDTH); checkPageBreak(titleLines.length * 28); pdf.text(titleLines, PAGE_WIDTH / 2, y, { align: 'center' }); y += titleLines.length * 28 + 20; // Helper function for sections const addSectionToPdf = (title, body) => { pdf.setFontSize(16); pdf.setFont('helvetica', 'bold'); pdf.setTextColor(63, 63, 70); // zinc-700 checkPageBreak(40); pdf.text(title, MARGIN, y); y += 10; pdf.setDrawColor(228, 228, 231); // zinc-200 pdf.line(MARGIN, y, PAGE_WIDTH - MARGIN, y); y += 25; pdf.setFontSize(11); pdf.setFont('helvetica', 'normal'); pdf.setTextColor(82, 82, 91); // zinc-600 const bodyLines = pdf.splitTextToSize(body, MAX_WIDTH); checkPageBreak(bodyLines.length * 14); pdf.text(bodyLines, MARGIN, y); y += bodyLines.length * 14 + 30; }; addSectionToPdf('Introduction', expandedContent.introduction); expandedContent.sections.forEach(sec => addSectionToPdf(sec.title, sec.body)); addSectionToPdf('Conclusion', expandedContent.conclusion); pdf.save(`BlogPost_${expandedContent.title.replace(/ /g, '_')}.pdf`); }; // --- EVENT LISTENERS --- tabButtons.forEach((button, index) => button.addEventListener('click', () => showTab(index))); prevBtn.addEventListener('click', () => { if (currentTab > 0) showTab(currentTab - 1); }); nextBtn.addEventListener('click', () => { if (currentTab < tabButtons.length - 1) showTab(currentTab + 1); }); addSectionBtn.addEventListener('click', addSection); expandContentBtn.addEventListener('click', expandAllContent); downloadPdfBtn.addEventListener('click', downloadPDF); // --- INITIALIZATION --- addSection(); // Start with one section updateTabs(); });
Scroll to Top