feat: add SEO configuration with dynamic robots.txt and sitemap.xml generation
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { headers } from 'next/headers';
|
||||
|
||||
// Get current domain from headers
|
||||
function getCurrentDomain() {
|
||||
const headersList = headers();
|
||||
const host = headersList.get('host');
|
||||
return host || 'nobat724.com';
|
||||
}
|
||||
|
||||
// Get base URL based on current domain
|
||||
function getBaseUrl(domain) {
|
||||
// Remove port number if present (for development)
|
||||
const cleanDomain = domain.replace(/:\d+$/, '');
|
||||
|
||||
// For localhost domains, use http, otherwise https
|
||||
const protocol = cleanDomain.includes('localhost') ? 'http' : 'https';
|
||||
|
||||
return `${protocol}://${domain}`;
|
||||
}
|
||||
|
||||
export default function robots() {
|
||||
const domain = getCurrentDomain();
|
||||
const baseUrl = getBaseUrl(domain);
|
||||
|
||||
return {
|
||||
rules: {
|
||||
userAgent: '*',
|
||||
allow: '/',
|
||||
disallow: '/admin',
|
||||
},
|
||||
sitemap: `${baseUrl}/sitemap.xml`,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user