Skip to content

Commit

Permalink
Merge pull request #142 from SJSUCSClub/141-improve-sitemapxml-should…
Browse files Browse the repository at this point in the history
…-include-index-of-generated-sitemaps-use-fs-to-get-tos-and-privacy-mds

[Improve] fixed sitemap issue, fixed privacy/tos md build issue
  • Loading branch information
chrehall68 authored Oct 15, 2024
2 parents 3935de8 + fae220f commit e3178d2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 deletions.
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.

0 comments on commit e3178d2

Please sign in to comment.