Skip to content

Commit

Permalink
feat: update sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
HereEast committed Feb 16, 2025
1 parent b332315 commit 65eb2cc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import type { MetadataRoute } from "next";
import { BASE_URL } from "~/utils/constants";
import { connectDB } from "./lib/connectDB";
import { IPerson, Person } from "~/models/Person";
import { IQuestion, Question } from "~/models/Question";

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
await connectDB();

const people: IPerson[] = await Person.find({ isActive: true }).exec();
const questions: IQuestion[] = await Question.find({ isActive: true }).exec();

const peopleSitemapData =
people?.map((person) => {
Expand All @@ -17,6 +19,14 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
};
}) || [];

const questionsSitemapData =
questions?.map((question) => {
return {
url: `${BASE_URL}/${question.slug}`,
lastModified: new Date(),
};
}) || [];

return [
{
url: BASE_URL,
Expand All @@ -26,6 +36,11 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
url: "/backlog",
lastModified: new Date(),
},
{
url: "/questions",
lastModified: new Date(),
},
...peopleSitemapData,
...questionsSitemapData,
];
}

0 comments on commit 65eb2cc

Please sign in to comment.