UNPKG

techveda-react-seo

Version:

Complete React SEO automation library with meta tags, robots.txt and sitemap generation

69 lines (61 loc) 1.73 kB
// import { useState } from 'react'; // import { writeFileSyncSafe } from '../utils/fileUtils'; // import path from 'path'; // import { GenerateSitemapOptions } from '../types'; // interface SitemapGeneratorState { // loading: boolean; // error: Error | null; // success: boolean; // filePath: string | null; // } // export function useSitemapGenerator() { // const [state, setState] = useState<SitemapGeneratorState>({ // loading: false, // error: null, // success: false, // filePath: null, // }); // const generateSitemap = (options: GenerateSitemapOptions) => { // setState({ // loading: true, // error: null, // success: false, // filePath: null, // }); // try { // const { // domain, // routes = ['/'], // outputPath = path.join(process.cwd(), 'public', 'sitemap.xml'), // } = options; // const sitemapContent = `<?xml version="1.0" encoding="UTF-8"?> // <urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"> // ${routes // .map( // (route) => ` // <url> // <loc>https://${domain}${route}</loc> // <changefreq>weekly</changefreq> // <priority>${route === '/' ? '1.0' : '0.8'}</priority> // </url>` // ) // .join('\n')} // </urlset>`; // writeFileSyncSafe(outputPath, sitemapContent); // setState({ // loading: false, // error: null, // success: true, // filePath: outputPath, // }); // } catch (error) { // setState({ // loading: false, // error: error as Error, // success: false, // filePath: null, // }); // } // }; // return { generateSitemap, ...state }; // }