diff --git a/src/routes/robots.txt/+server.ts b/src/routes/robots.txt/+server.ts new file mode 100644 index 0000000..3ca0037 --- /dev/null +++ b/src/routes/robots.txt/+server.ts @@ -0,0 +1,25 @@ +import type { RequestHandler } from './$types'; + +const SITE_URL = 'https://cs2.wtf'; // Update with actual production URL + +/** + * Generate robots.txt for search engine crawlers + */ +export const GET: RequestHandler = async () => { + const robots = `User-agent: * +Allow: / + +# Sitemaps +Sitemap: ${SITE_URL}/sitemap.xml + +# Crawl-delay +Crawl-delay: 1 +`; + + return new Response(robots, { + headers: { + 'Content-Type': 'text/plain', + 'Cache-Control': 'public, max-age=86400' // Cache for 1 day + } + }); +}; diff --git a/src/routes/sitemap.xml/+server.ts b/src/routes/sitemap.xml/+server.ts new file mode 100644 index 0000000..3024251 --- /dev/null +++ b/src/routes/sitemap.xml/+server.ts @@ -0,0 +1,65 @@ +import type { RequestHandler } from './$types'; +import { matchesAPI } from '$lib/api/matches'; + +const SITE_URL = 'https://cs2.wtf'; // Update with actual production URL + +/** + * Generate XML sitemap for SEO + * Includes static pages and dynamic match pages + */ +export const GET: RequestHandler = async () => { + try { + // Static pages + const staticPages = [ + { url: '', priority: 1.0, changefreq: 'daily' }, // Home + { url: '/matches', priority: 0.9, changefreq: 'hourly' } // Matches listing + ]; + + // Fetch recent matches for dynamic URLs + let matchUrls: { url: string; lastmod: string }[] = []; + try { + const matchesResponse = await matchesAPI.getMatches({ limit: 100 }); + matchUrls = matchesResponse.matches.map((match) => ({ + url: `/match/${match.match_id}`, + lastmod: match.date || new Date().toISOString() + })); + } catch (error) { + console.error('Failed to fetch matches for sitemap:', error); + } + + // Build XML sitemap + const sitemap = ` + +${staticPages + .map( + (page) => ` + ${SITE_URL}${page.url} + ${new Date().toISOString()} + ${page.changefreq} + ${page.priority} + ` + ) + .join('\n')} +${matchUrls + .map( + (match) => ` + ${SITE_URL}${match.url} + ${match.lastmod} + weekly + 0.7 + ` + ) + .join('\n')} +`.trim(); + + return new Response(sitemap, { + headers: { + 'Content-Type': 'application/xml', + 'Cache-Control': 'public, max-age=3600' // Cache for 1 hour + } + }); + } catch (error) { + console.error('Error generating sitemap:', error); + return new Response('Error generating sitemap', { status: 500 }); + } +};