diff --git a/frontend/src/components/SeoProxyRoutes.jsx b/frontend/src/components/SeoProxyRoutes.jsx index 441ac0b..62f71f7 100644 --- a/frontend/src/components/SeoProxyRoutes.jsx +++ b/frontend/src/components/SeoProxyRoutes.jsx @@ -9,9 +9,9 @@ const SeoFile = ({ filePath }) => { const [content, setContent] = useState(''); const [contentType, setContentType] = useState(''); const [error, setError] = useState(null); - console.log(filePath) + console.log(filePath); + useEffect(() => { - // Determine the content type based on the file extension const fileExtension = filePath.split('.').pop(); const type = fileExtension === 'xml' ? 'application/xml' : 'text/plain'; setContentType(type); @@ -32,56 +32,79 @@ const SeoFile = ({ filePath }) => { }); }, [filePath]); - // Set the content type and return the raw content useEffect(() => { if (content && contentType) { - // For XML content, we need to handle it differently than document.write + document.open(); + if (contentType.includes('xml')) { - // Clear the existing document content - document.body.innerHTML = ''; - document.head.innerHTML = ''; - - // Set the XML MIME type - const meta = document.createElement('meta'); - meta.httpEquiv = 'Content-Type'; - meta.content = `${contentType}; charset=utf-8`; - document.head.appendChild(meta); - - // Create a pre element to display the XML with proper formatting - const pre = document.createElement('pre'); - pre.textContent = content; - document.body.appendChild(pre); - - // For XML styling - optional but makes it look nicer - const style = document.createElement('style'); - style.textContent = ` - body { - font-family: monospace; - background: #282c34; - color: #abb2bf; - padding: 20px; - } - pre { - white-space: pre-wrap; - word-wrap: break-word; - } - `; - document.head.appendChild(style); + // XML styling + document.write(` + + +
+ + + + +${escapeHtml(content)}
+
+
+ `);
} else {
- // For text content like robots.txt, use the standard approach
- document.open();
- document.write(content);
- document.close();
-
- // Set the correct content type
- const meta = document.createElement('meta');
- meta.httpEquiv = 'Content-Type';
- meta.content = `${contentType}; charset=utf-8`;
- document.head.appendChild(meta);
+ document.write(`
+
+
+
+
+
+
+
+ ${escapeHtml(content)}
+
+
+ `);
}
+
+ document.close();
}
}, [content, contentType]);
+ // Helper function to escape HTML entities
+ function escapeHtml(text) {
+ if (!text) return '';
+ return text
+ .replace(/&/g, '&')
+ .replace(//g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''');
+ }
+
// If there was an error, show a simple error message
if (error) {
return