Become a Pro / website · becomeapro.ai / src / app / sitemap.ts
| 1 | import type { MetadataRoute } from "next"; |
| 2 | import { SITE_URL } from "@/lib/seo"; |
| 3 | import { TRACKS } from "@/lib/tracks"; |
| 4 | import { getPublishedTutorials, getVideoTutorials, lastModified, type TutorialMeta } from "@/lib/tutorials"; |
| 5 | |
| 6 | // Newest publish or update date in a list, so listing pages change when a tutorial is added or revised |
| 7 | const newest = (tutorials: TutorialMeta[]) => |
| 8 | tutorials.map(lastModified).reduce<string | undefined>((max, day) => (day && (!max || day > max) ? day : max), undefined); |
| 9 | |
| 10 | export default function sitemap(): MetadataRoute.Sitemap { |
| 11 | // Drafts and noindexed pages (sign-in, account, an empty videos page) stay out |
| 12 | const tutorials = getPublishedTutorials(); |
| 13 | const latest = newest(tutorials); |
| 14 | const listing = (path: string, list: TutorialMeta[] = tutorials) => ({ url: `${SITE_URL}${path}`, lastModified: newest(list) }); |
| 15 | |
| 16 | return [ |
| 17 | { url: SITE_URL, lastModified: latest }, |
| 18 | listing("/tutorials"), |
| 19 | ...TRACKS.map((t) => listing(`/${t.slug}`, tutorials.filter((x) => x.track === t.slug))), |
| 20 | ...(getVideoTutorials().length > 0 ? [listing("/videos", getVideoTutorials())] : []), |
| 21 | ...["/getting-started", "/about", "/privacy", "/research", "/content-rights"].map((p) => ({ url: `${SITE_URL}${p}` })), |
| 22 | ...tutorials.map((t) => ({ |
| 23 | url: `${SITE_URL}/${t.track}/${t.slug}`, |
| 24 | lastModified: lastModified(t) || undefined, |
| 25 | })), |
| 26 | ]; |
| 27 | } |