diff --git a/app/(main)/courses/sitemap.ts b/app/(main)/courses/sitemap.ts index 9ead9d1..5351cdb 100644 --- a/app/(main)/courses/sitemap.ts +++ b/app/(main)/courses/sitemap.ts @@ -2,6 +2,8 @@ import { CoursesSearchResponse } from '@/types'; import fetcher from '@/utils/fetcher'; import { MetadataRoute } from 'next'; +export const dynamic = 'force-dynamic'; + const sitemapLinksLimit = 50000; export async function generateSitemaps() { diff --git a/app/(main)/privacy/page.tsx b/app/(main)/privacy/page.tsx index 541c239..68f5907 100644 --- a/app/(main)/privacy/page.tsx +++ b/app/(main)/privacy/page.tsx @@ -1,11 +1,8 @@ import { MDXRemote } from 'next-mdx-remote/rsc'; -import React from 'react'; +import fs from 'fs'; export default async function Page() { - const res = await fetch( - process.env.NEXT_PUBLIC_BASE_URL + '/privacy-policy.md', - ); - const markdown = await res.text(); + const markdown = fs.readFileSync('app/privacy-policy.md', 'utf8'); return (
diff --git a/app/(main)/professors/sitemap.ts b/app/(main)/professors/sitemap.ts index b3c33c4..868e986 100644 --- a/app/(main)/professors/sitemap.ts +++ b/app/(main)/professors/sitemap.ts @@ -2,6 +2,8 @@ import { ProfessorsSearchResponse } from '@/types'; import fetcher from '@/utils/fetcher'; import { MetadataRoute } from 'next'; +export const dynamic = 'force-dynamic'; + const sitemapLinksLimit = 50000; export async function generateSitemaps() { diff --git a/app/(main)/terms/page.tsx b/app/(main)/terms/page.tsx index 68a643a..ee08edc 100644 --- a/app/(main)/terms/page.tsx +++ b/app/(main)/terms/page.tsx @@ -1,11 +1,8 @@ import { MDXRemote } from 'next-mdx-remote/rsc'; -import React from 'react'; +import fs from 'fs'; export default async function Page() { - const res = await fetch( - process.env.NEXT_PUBLIC_BASE_URL + '/terms-of-service.md', - ); - const markdown = await res.text(); + const markdown = fs.readFileSync('app/terms-of-service.md', 'utf8'); return (
diff --git a/public/privacy-policy.md b/app/privacy-policy.md similarity index 100% rename from public/privacy-policy.md rename to app/privacy-policy.md diff --git a/app/sitemap.ts b/app/sitemap.ts index 9369d81..888a2e8 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -1,6 +1,22 @@ +import { CoursesSearchResponse, ProfessorsSearchResponse } from '@/types'; +import fetcher from '@/utils/fetcher'; import { MetadataRoute } from 'next'; -export default function sitemap(): MetadataRoute.Sitemap { +export const dynamic = 'force-dynamic'; + +const sitemapLinksLimit = 50000; + +export default async function sitemap(): Promise { + const { total_results: totalCourses } = (await fetcher( + process.env.BASE_API_URL + `/core/courses/search?`, + )) as CoursesSearchResponse; + const { total_results: totalProfessors } = (await fetcher( + process.env.BASE_API_URL + `/core/professors/search?`, + )) as ProfessorsSearchResponse; + const numberOfCourseSitemaps = Math.ceil(totalCourses / sitemapLinksLimit); + const numberOfProfessorSitemaps = Math.ceil( + totalProfessors / sitemapLinksLimit, + ); return [ { url: `${process.env.NEXT_PUBLIC_BASE_URL}`, @@ -38,5 +54,17 @@ export default function sitemap(): MetadataRoute.Sitemap { // changeFrequency: 'monthly', priority: 0.8, }, + ...Array.from({ length: numberOfCourseSitemaps }, (_, i) => ({ + url: `${process.env.NEXT_PUBLIC_BASE_URL}/courses/sitemap/${i}.xml`, + lastModified: new Date().toISOString(), + // changeFrequency: 'monthly', + priority: 0.6, + })), + ...Array.from({ length: numberOfProfessorSitemaps }, (_, i) => ({ + url: `${process.env.NEXT_PUBLIC_BASE_URL}/professors/sitemap/${i}.xml`, + lastModified: new Date().toISOString(), + // changeFrequency: 'monthly', + priority: 0.6, + })), ]; } diff --git a/public/terms-of-service.md b/app/terms-of-service.md similarity index 100% rename from public/terms-of-service.md rename to app/terms-of-service.md