// File processing logic document.addEventListener('DOMContentLoaded', () => { console.log('BlogVista initialized'); // Handle file uploads and generation const handleFileUpload = async (files) => { if (!files || files.length === 0) return; // Convert FileList to array const filesArray = Array.from(files); // Process each file for (const file of filesArray) { try { const content = await extractFileContent(file); const html = generateBlogHTML(file.name.replace(/\.[^/.]+$/, ""), content); downloadHTMLFile(file.name.replace(/\.[^/.]+$/, ".html"), html); // Initialize Feather Icons when DOM is loaded document.addEventListener('DOMContentLoaded', () => { feather.replace(); // Handle file uploads and generation const handleFileUpload = async (files) => { if (!files || files.length === 0) return; // Convert FileList to array const filesArray = Array.from(files); // Process each file for (const file of filesArray) { try { const content = await extractFileContent(file); const html = generateBlogHTML(file.name.replace(/\.[^/.]+$/, ""), content); downloadHTMLFile(file.name.replace(/\.[^/.]+$/, ".html"), html); } catch (error) { console.error(`Error processing ${file.name}:`, error); showErrorNotification(`Failed to process ${file.name}`); } } }; // Listen for custom event from file-upload component document.addEventListener('files-uploaded', (e) => { if (e.detail && e.detail.files) { handleFileUpload(e.detail.files); } }); }); catch (error) { console.error(`Error processing ${file.name}:`, error); showErrorNotification(`Failed to process ${file.name}`); } } }; // Listen for custom event from file-upload component document.addEventListener('files-uploaded', (e) => { if (e.detail && e.detail.files) { handleFileUpload(e.detail.files); } }); }); function showErrorNotification(message) { const notification = document.createElement('div'); notification.style.position = 'fixed'; notification.style.bottom = '20px'; notification.style.right = '20px'; notification.style.backgroundColor = '#ef4444'; notification.style.color = 'white'; notification.style.padding = '12px 24px'; notification.style.borderRadius = '8px'; notification.style.boxShadow = '0 4px 6px rgba(0,0,0,0.1)'; notification.style.zIndex = '1000'; notification.textContent = message; document.body.appendChild(notification); setTimeout(() => { notification.style.transition = 'opacity 0.5s'; notification.style.opacity = '0'; setTimeout(() => notification.remove(), 500); }, 3000); } // Simulate file content extraction with improved mock content async function extractFileContent(file) { return new Promise((resolve) => { // Simulate processing delay setTimeout(() => { const isPPT = file.type.includes('powerpoint'); const mockContent = `

${file.name.replace(/\.[^/.]+$/, "")}

Auto-generated from ${isPPT ? 'PowerPoint' : 'Word'} document

${isPPT ? `

Presentation Slides

This would contain your PowerPoint slides content.

Presentation
` : ''}

Document Content

This would contain the formatted text content from your document with proper headings, lists, and paragraphs.

${isPPT ? `

Slide Notes

This section would contain any speaker notes from your presentation.

` : ''}

About This Conversion

This HTML was automatically generated from your original document while preserving the structure and key content elements.

Features

`; resolve(mockContent); }, 1500); }); } function generateBlogHTML(title, content) { return ` ${title}

${title}

${content}
`; } function downloadHTMLFile(filename, content) { try { const blob = new Blob([content], { type: 'text/html' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = filename; document.body.appendChild(a); a.click(); document.body.removeChild(a); // Revoke the object URL after a delay to ensure download completes setTimeout(() => { URL.revokeObjectURL(url); }, 100); } catch (error) { console.error('Error downloading file:', error); showErrorNotification('Failed to download file'); } } }