Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve] fixed sitemap issue, fixed privacy/tos md build issue #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/(main)/courses/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 2 additions & 5 deletions app/(main)/privacy/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<main>
<section className="mx-auto flex w-full max-w-content-width items-stretch px-md">
Expand Down
2 changes: 2 additions & 0 deletions app/(main)/professors/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 2 additions & 5 deletions app/(main)/terms/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<main>
<section className="mx-auto flex w-full max-w-content-width items-stretch px-md">
Expand Down
File renamed without changes.
30 changes: 29 additions & 1 deletion app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -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<MetadataRoute.Sitemap> {
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}`,
Expand Down Expand Up @@ -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,
})),
];
}
File renamed without changes.
Loading