@dijitrak/react-nextjs-seo-plugin
Version:
A modern, user-friendly SEO plugin for React and Next.js with multilingual support and comprehensive optimization tools
64 lines (55 loc) • 1.48 kB
text/typescript
/**
* Robots.txt oluşturma işlemleri
*/
/**
* Robots.txt oluşturur
* @param allowIndexing İndekslemeye izin verilecek mi
* @param customRules Özel kurallar
* @param siteUrl Sitemap URL'si için site adresi
* @returns Robots.txt içeriği
*/
export function generateRobotsTxt(
allowIndexing: boolean = true,
customRules: string = '',
siteUrl: string = ''
): string {
let content = '';
// Varsayılan User-agent kuralı
content += 'User-agent: *\n';
// İndeksleme durumuna göre Disallow kuralı
if (!allowIndexing) {
content += 'Disallow: /\n';
} else {
content += 'Disallow:\n';
// Varsayılan olarak hariç tutulan yollar
const defaultExcludePaths = [
'/wp-admin/',
'/wp-includes/',
'/wp-content/plugins/',
'/wp-json/',
'/admin/',
'/login/',
'/account/',
'/cart/',
'/checkout/',
'/search/',
'/?s=',
'/*?' // Soru işareti içeren tüm URL'ler (query string)
];
defaultExcludePaths.forEach(path => {
content += `Disallow: ${path}\n`;
});
}
// Sitemap.xml URL'si ekle
if (siteUrl) {
let sitemapUrl = siteUrl;
// URL sonunda / varsa kaldır
sitemapUrl = sitemapUrl.replace(/\/$/, '');
content += `\nSitemap: ${sitemapUrl}/sitemap.xml\n`;
}
// Özel kurallar varsa ekle
if (customRules && customRules.trim() !== '') {
content += '\n' + customRules.trim() + '\n';
}
return content;
}