Spaces:
Running
Running
File size: 7,722 Bytes
0bf2e7e 7876758 0bf2e7e d9b0010 0bf2e7e 7876758 0bf2e7e 7876758 0bf2e7e 7b18b7c d9b0010 7876758 0bf2e7e 7876758 0bf2e7e d9b0010 0bf2e7e d9b0010 7876758 d9b0010 0bf2e7e 7876758 0bf2e7e 7876758 0bf2e7e 7876758 0bf2e7e d9b0010 0bf2e7e d9b0010 7876758 0bf2e7e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
// 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 = `
<h1>${file.name.replace(/\.[^/.]+$/, "")}</h1>
<p class="text-lg text-secondary-500 mb-6">Auto-generated from ${isPPT ? 'PowerPoint' : 'Word'} document</p>
<div class="grid ${isPPT ? 'md:grid-cols-2' : 'md:grid-cols-1'} gap-6 mb-8">
${isPPT ?
`<div class="bg-stone-100 p-6 rounded-lg">
<h2 class="text-xl font-bold mb-3">Presentation Slides</h2>
<p>This would contain your PowerPoint slides content.</p>
<img src="http://static.photos/business/640x360/42" alt="Presentation" class="mt-4 rounded-lg">
</div>` : ''}
<div class="bg-stone-100 p-6 rounded-lg">
<h2 class="text-xl font-bold mb-3">Document Content</h2>
<p>This would contain the formatted text content from your document with proper headings, lists, and paragraphs.</p>
<ul class="mt-4 pl-5 space-y-2">
<li class="list-disc">Document: ${file.name}</li>
<li class="list-disc">Size: ${(file.size / 1024).toFixed(2)} KB</li>
<li class="list-disc">Pages: ${Math.ceil(Math.random() * 10)}</li>
</ul>
</div>
</div>
${isPPT ?
`<div class="bg-stone-100 p-6 rounded-lg mb-8">
<h2 class="text-xl font-bold mb-3">Slide Notes</h2>
<p>This section would contain any speaker notes from your presentation.</p>
</div>` : ''}
<div class="prose max-w-none">
<h2>About This Conversion</h2>
<p>This HTML was automatically generated from your original document while preserving the structure and key content elements.</p>
<h3>Features</h3>
<ul>
<li>Responsive design for all devices</li>
<li>Clean, professional typography</li>
<li>Automatic image optimization</li>
<li>SEO-friendly structure</li>
</ul>
</div>
`;
resolve(mockContent);
}, 1500);
});
}
function generateBlogHTML(title, content) {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${title}</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.tailwindcss.com"></script>
<script src="components/navbar.js"></script>
<script src="components/footer.js"></script>
</head>
<body class="bg-stone-50 min-h-screen flex flex-col">
<custom-navbar></custom-navbar>
<article class="container mx-auto px-4 py-12 max-w-4xl flex-grow">
<header class="mb-12 text-center">
<h1 class="text-4xl font-bold text-primary-500 mb-4">${title}</h1>
<div class="h-1 w-24 bg-primary-500 mx-auto"></div>
</header>
<div class="prose prose-lg max-w-none bg-white p-8 rounded-xl shadow-lg">
${content}
</div>
</article>
<custom-footer></custom-footer>
<script>
feather.replace();
</script>
</body>
</html>
`;
}
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');
}
}
} |