Fitness Blog Post Generator

Fitness Blog Post Generator

Generate motivational and instructional fitness content.

1. Goal & Focus
2. Post Outline
3. Generated Post

Review and edit the proposed post structure.

Your generated blog post will appear here.

Remember to stay hydrated and breathe deeply throughout each movement. Consistency is the key to progress!

`; }); const conclusionTitle = outlineTitles[outlineTitles.length - 1]; postHtml += `

${conclusionTitle}

`; postHtml += `

Amazing work today! You've taken a huge step towards your fitness goals. Be proud of your effort and remember to refuel with a healthy meal. We'll see you at the next workout!

`; elements.generatedPostContainer.innerHTML = postHtml; }; // --- UTILITY FUNCTIONS --- const copyToClipboard = () => { const content = elements.generatedPostContainer.innerText; const button = elements.copyHtmlBtn; navigator.clipboard.writeText(content).then(() => { button.textContent = 'Copied!'; setTimeout(() => { button.textContent = 'Copy Post'; }, 2000); }).catch(err => { const textArea = document.createElement("textarea"); textArea.value = content; document.body.appendChild(textArea); textArea.select(); try { document.execCommand('copy'); button.textContent = 'Copied!'; setTimeout(() => { button.textContent = 'Copy Post'; }, 2000); } catch (err) { console.error('Failed to copy text: ', err); button.textContent = 'Error'; } document.body.removeChild(textArea); }); }; const downloadPDF = () => { const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const title = document.querySelector('#generatedPostContainer h1')?.innerText || "Fitness Workout Plan"; const contentElements = elements.generatedPostContainer.children; const PAGE_WIDTH = pdf.internal.pageSize.getWidth(); const MARGIN = 50; let y = 0; // PDF Header pdf.setFillColor(22, 163, 74); // green-600 pdf.rect(0, 0, PAGE_WIDTH, 80, 'F'); pdf.setFont('helvetica', 'bold'); pdf.setFontSize(24); pdf.setTextColor(255, 255, 255); const titleLines = pdf.splitTextToSize(title, PAGE_WIDTH - MARGIN*2); pdf.text(titleLines, MARGIN, 50); y = 120; // Starting Y for content // Content Array.from(contentElements).forEach(el => { const text = el.innerText; let fontSize = 11; let fontStyle = 'normal'; let color = [51, 65, 85]; // slate-700 let spacing = 15; if (el.tagName === 'H1') { return; } if (el.tagName === 'H2') { fontSize = 14; fontStyle = 'bold'; color = [22, 101, 52]; // green-800 spacing = 20; } pdf.setFont('helvetica', fontStyle); pdf.setFontSize(fontSize); pdf.setTextColor(color[0], color[1], color[2]); const lines = pdf.splitTextToSize(text, PAGE_WIDTH - MARGIN*2); const textHeight = lines.length * fontSize * 1.15; if (y + textHeight > pdf.internal.pageSize.getHeight() - MARGIN) { pdf.addPage(); y = MARGIN; } pdf.text(lines, MARGIN, y); y += textHeight + spacing; }); pdf.save(`${title.replace(/ /g, '_').substring(0, 30)}.pdf`); }; // --- EVENT LISTENERS --- elements.prevBtn.addEventListener('click', () => nextPrev(-1)); elements.nextBtn.addEventListener('click', () => nextPrev(1)); elements.tabs.forEach((tab, i) => { tab.addEventListener('click', () => { console.warn("Direct tab navigation is disabled. Please use Next/Previous buttons."); }); }); elements.copyHtmlBtn.addEventListener('click', copyToClipboard); elements.downloadPdfBtn.addEventListener('click', downloadPDF); // Initialize showTab(currentTab); });
Scroll to Top