My personal site. theclashfruit.me
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add sitemap

+77
+77
app/sitemap.ts
··· 1 + import { spawn } from 'node:child_process'; 2 + 3 + import type { MetadataRoute } from 'next'; 4 + 5 + export default async function sitemap(): Promise<MetadataRoute.Sitemap> { 6 + // TODO: Get the dates for the stuff that is stored in the db. 7 + 8 + return [ 9 + { 10 + url: 'https://theclashfruit.me', 11 + lastModified: await getGitCommitDate('app/(main)/page.mdx'), 12 + changeFrequency: 'yearly', 13 + priority: 1 14 + }, 15 + { 16 + url: 'https://theclashfruit.me/blog', 17 + lastModified: new Date(), 18 + changeFrequency: 'monthly', 19 + priority: 0.8 20 + }, 21 + { 22 + url: 'https://theclashfruit.me/art', 23 + lastModified: new Date(), 24 + changeFrequency: 'monthly', 25 + priority: 0.8 26 + }, 27 + { 28 + url: 'https://theclashfruit.me/photos', 29 + lastModified: new Date(), 30 + changeFrequency: 'monthly', 31 + priority: 0.8 32 + }, 33 + { 34 + url: 'https://theclashfruit.me/projects', 35 + lastModified: await getGitCommitDate('app/(main)/projects/page.tsx'), 36 + changeFrequency: 'monthly', 37 + priority: 0.8 38 + }, 39 + { 40 + url: 'https://theclashfruit.me/links', 41 + lastModified: await getGitCommitDate('app/(main)/links/page.tsx'), 42 + changeFrequency: 'monthly', 43 + priority: 0.8 44 + } 45 + ]; 46 + } 47 + 48 + const getGitCommitDate = (filePath: string): Promise<Date> => { 49 + return new Promise((resolve, reject) => { 50 + const log = spawn('git', ['log', '-1', '--pretty=format:%cI', filePath]); 51 + 52 + let stdout = ''; 53 + let stderr = ''; 54 + 55 + log.stdout.on('data', (data) => { 56 + stdout += data.toString(); 57 + }); 58 + 59 + log.stderr.on('data', (data) => { 60 + stderr += data.toString(); 61 + }); 62 + 63 + log.on('close', (code) => { 64 + if (code !== 0) { 65 + reject(new Error(`${code}: ${stderr}`)); 66 + } else if (!stdout.trim()) { 67 + reject(new Error(`No history for ${filePath} :(`)); 68 + } else { 69 + resolve(new Date(stdout.trim())); 70 + } 71 + }); 72 + 73 + log.on('error', (error) => { 74 + reject(error); 75 + }); 76 + }); 77 + };