diff --git a/frontend/src/components/SeoProxyRoutes.jsx b/frontend/src/components/SeoProxyRoutes.jsx index 62f71f7..76c92c6 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,79 +32,46 @@ const SeoFile = ({ filePath }) => { }); }, [filePath]); + // Set the content type and return the raw content useEffect(() => { if (content && contentType) { + // Clear existing document document.open(); if (contentType.includes('xml')) { - // XML styling - document.write(` - - -
- - - - -${escapeHtml(content)}
-
-
- `);
+ // For XML sitemaps, just write the raw content directly
+ // This is critical - no HTML tags or wrappers for XML files
+ document.write(content);
} else {
- document.write(`
-
-
-
-
-
-
-
- ${escapeHtml(content)}
-
-
- `);
+ // For robots.txt, use the pre tag to preserve formatting
+ document.write(`${content}`);
}
document.close();
+
+ // Set the correct content type meta tag
+ const meta = document.createElement('meta');
+ meta.httpEquiv = 'Content-Type';
+ meta.content = `${contentType}; charset=utf-8`;
+ document.head.appendChild(meta);
+
+ // Add minimal styling for robots.txt only
+ if (!contentType.includes('xml')) {
+ const style = document.createElement('style');
+ style.textContent = `
+ pre {
+ font-family: monospace;
+ font-size: 14px;
+ line-height: 1.5;
+ margin: 0;
+ padding: 15px;
+ }
+ `;
+ document.head.appendChild(style);
+ }
}
}, [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