techveda-react-seo
Version:
Complete React SEO automation library with meta tags, robots.txt and sitemap generation
63 lines (55 loc) • 1.69 kB
text/typescript
// import { useState } from 'react';
// import { writeFileSyncSafe } from '../utils/fileUtils';
// import path from 'path';
// import { GenerateRobotsOptions } from '../types';
// interface RobotsGeneratorState {
// loading: boolean;
// error: Error | null;
// success: boolean;
// filePath: string | null;
// }
// export function useRobotsGenerator() {
// const [state, setState] = useState<RobotsGeneratorState>({
// loading: false,
// error: null,
// success: false,
// filePath: null,
// });
// const generateRobots = (options: GenerateRobotsOptions) => {
// setState({
// loading: true,
// error: null,
// success: false,
// filePath: null,
// });
// try {
// const {
// domain,
// allowAll = true,
// sitemapPath = '/sitemap.xml',
// disallowPaths = [],
// outputPath = path.join(process.cwd(), 'public', 'robots.txt'),
// } = options;
// const robotsContent = allowAll
// ? `User-agent: *\nAllow: /\n\nSitemap: https://${domain}${sitemapPath}\n`
// : `User-agent: *\n${disallowPaths
// .map((p) => `Disallow: ${p}`)
// .join('\n')}\n\nSitemap: https://${domain}${sitemapPath}\n`;
// writeFileSyncSafe(outputPath, robotsContent);
// setState({
// loading: false,
// error: null,
// success: true,
// filePath: outputPath,
// });
// } catch (error) {
// setState({
// loading: false,
// error: error as Error,
// success: false,
// filePath: null,
// });
// }
// };
// return { generateRobots, ...state };
// }