From 9c09d34a5f0294303bbbd6f7381649e070bd22e7 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Wed, 7 May 2025 21:27:31 -0500 Subject: [PATCH] fixed sitemap rendering --- frontend/src/components/SeoProxyRoutes.jsx | 111 +++++++++++++-------- 1 file changed, 67 insertions(+), 44 deletions(-) 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
{error}
;