mirror of
				https://github.com/bartvdbraak/hellob.art.git
				synced 2025-10-30 19:59:10 +00:00 
			
		
		
		
	feat: create dynamic sitemap
This commit is contained in:
		
							parent
							
								
									3482028cee
								
							
						
					
					
						commit
						fc74ca4f3e
					
				
					 1 changed files with 41 additions and 0 deletions
				
			
		
							
								
								
									
										41
									
								
								src/routes/sitemap.xml/+server.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/routes/sitemap.xml/+server.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| import { SITE_URL } from '$lib/site-config'; | ||||
| 
 | ||||
| /** @type {import('@sveltejs/kit').RequestHandler} */ | ||||
| export async function GET() { | ||||
| 	const pages = ['projects', 'toolbox']; | ||||
| 	const body = sitemap(pages); | ||||
| 
 | ||||
| 	return new Response(body, { | ||||
| 		headers: { | ||||
| 			'Cache-Control': `public, max-age=${86400}`, // 24 hours
 | ||||
| 			'Content-Type': 'application/xml' | ||||
| 		} | ||||
| 	}); | ||||
| } | ||||
| 
 | ||||
| const sitemap = (pages: string[]) => `<?xml version="1.0" encoding="UTF-8" ?>
 | ||||
|   <urlset | ||||
|     xmlns="https://www.sitemaps.org/schemas/sitemap/0.9" | ||||
|     xmlns:news="https://www.google.com/schemas/sitemap-news/0.9" | ||||
|     xmlns:xhtml="https://www.w3.org/1999/xhtml" | ||||
|     xmlns:mobile="https://www.google.com/schemas/sitemap-mobile/1.0" | ||||
|     xmlns:image="https://www.google.com/schemas/sitemap-image/1.1" | ||||
|     xmlns:video="https://www.google.com/schemas/sitemap-video/1.1" | ||||
|   > | ||||
|     <url> | ||||
|       <loc>${SITE_URL}</loc> | ||||
|       <changefreq>daily</changefreq> | ||||
|       <priority>0.7</priority> | ||||
|     </url> | ||||
|     ${pages | ||||
| 			.map( | ||||
| 				(page) => ` | ||||
|     <url> | ||||
|       <loc>${SITE_URL}/${page}</loc> | ||||
|       <changefreq>daily</changefreq> | ||||
|       <priority>0.7</priority> | ||||
|     </url> | ||||
|     ` | ||||
| 			) | ||||
| 			.join('')} | ||||
|   </urlset>`;
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue