From e9d4c127daf553f69cdf3d5acc5249a4378e34ac Mon Sep 17 00:00:00 2001 From: Hassaan Qaisar Date: Thu, 6 Feb 2025 20:54:48 +0500 Subject: [PATCH] sitemap completed --- academy-ui/src/app/sitemap.xml/route.ts | 193 +++++++++++++++--------- 1 file changed, 123 insertions(+), 70 deletions(-) diff --git a/academy-ui/src/app/sitemap.xml/route.ts b/academy-ui/src/app/sitemap.xml/route.ts index 21b7ea2cd..ecea1fb00 100644 --- a/academy-ui/src/app/sitemap.xml/route.ts +++ b/academy-ui/src/app/sitemap.xml/route.ts @@ -1,11 +1,4 @@ -import { - CourseDetailsFragment, - CourseFragment, - CourseTopicFragment, - GuideFragment, - GuideSummaryFragment, - ClickableDemo, -} from '@/graphql/generated/generated-types'; +import { CourseDetailsFragment, CourseFragment, GuideSummaryFragment, ClickableDemo, Timeline } from '@/graphql/generated/generated-types'; import { SpaceWithIntegrationsDto, SpaceTypes } from '@/types/space/SpaceDto'; import { getSpaceBasedOnHostHeader } from '@/utils/space/getSpaceServerSide'; import { PredefinedSpaces } from '@dodao/web-core/src/utils/constants/constants'; @@ -14,6 +7,8 @@ import { NextRequest, NextResponse } from 'next/server'; import { SitemapStream, streamToPromise } from 'sitemap'; import { ByteCollectionItemType } from '@/app/api/helpers/byteCollection/byteCollectionItemType'; import getBaseUrl from '@dodao/web-core/utils/api/getBaseURL'; +import { getFeaturesArray } from '@/utils/features'; +import { FeatureName } from '@dodao/web-core/types/features/spaceFeatures'; interface SiteMapUrl { url: string; @@ -58,19 +53,6 @@ async function getClickableDemoUrls(spaceId: string): Promise { return urls; } -async function getGuideUrlsForAcademy(spaceId: string): Promise { - const allGuides: GuideSummaryFragment[] = await getAllGuidesWithSteps(spaceId); - const urls: SiteMapUrl[] = []; - for (const guide of allGuides) { - urls.push({ - url: `/guides/view/${guide.id}/0`, - changefreq: 'monthly', - priority: 0.8, - }); - } - return urls; -} - async function getAllCourseKeys(spaceId: string) { const baseUrl = getBaseUrl(); const response = await axios.get(`${baseUrl}/api/courses`, { @@ -88,39 +70,6 @@ async function getCourseDetails(spaceId: string, courseKey: string) { return response.data.course as CourseDetailsFragment; } -async function getCourseUrlsForAcademy(spaceId: string): Promise { - const courses = await getAllCourseKeys(spaceId); - const urls: SiteMapUrl[] = []; - - for (const course of courses) { - urls.push({ - url: `/courses/view/${course.key}`, - changefreq: 'weekly', - priority: 0.8, - }); - - const detailedCourse = await getCourseDetails(spaceId, course.key); - - for (const topic of detailedCourse.topics || []) { - urls.push({ - url: `/courses/view/${detailedCourse.key}/${topic.key}`, - changefreq: 'weekly', - priority: 0.7, - }); - - for (const explanation of topic.explanations || []) { - urls.push({ - url: `/courses/view/${detailedCourse.key}/${topic.key}/explanations/${explanation.key}`, - changefreq: 'weekly', - priority: 0.6, - }); - } - } - } - - return urls; -} - async function getDoDAOSiteMapUrls(): Promise { const urls: SiteMapUrl[] = [ { url: '/', changefreq: 'daily', priority: 1.0 }, @@ -190,17 +139,7 @@ async function getTidbitCollectionUrlsForAcademy(spaceId: string): Promise> { const host = req.headers.get('host') as string; const space = (await getSpaceBasedOnHostHeader(req.headers))!; @@ -225,11 +258,31 @@ async function GET(req: NextRequest): Promise> { await writeTidbitsHubSiteMapToStream(smStream); } if (space.type === SpaceTypes.AcademySite) { - smStream.write({ url: '/', changefreq: 'daily', priority: 1.0 }), smStream.write({ url: '/guides', changefreq: 'weekly', priority: 0.9 }); - smStream.write({ url: '/tidbit-collections', changefreq: 'weekly', priority: 0.9 }); - smStream.write({ url: '/clickable-demos', changefreq: 'weekly', priority: 0.9 }); - smStream.write({ url: '/courses', changefreq: 'weekly', priority: 0.9 }); - await writeUrlsToStream(space, host, smStream); + smStream.write({ url: '/', changefreq: 'daily', priority: 1.0 }); + const features = getFeaturesArray(space.id); + for (const feature of features) { + if (!feature.enabled) continue; + switch (feature.featureName) { + case FeatureName.Guides: + await writeGuidesUrls(space.id, smStream); + break; + case FeatureName.Courses: + await writeCoursesUrls(space.id, smStream); + break; + case FeatureName.ByteCollections: + await writeTidbitUrls(space.id, smStream); + break; + case FeatureName.ClickableDemos: + await writeClickableDemoUrls(space.id, smStream); + break; + case FeatureName.Timelines: + await writeTimelinesUrls(space.id, smStream); + break; + } + } + } + if (space.type === SpaceTypes.TidbitsSite) { + smStream.write({ url: '/', changefreq: 'daily', priority: 1.0 }), await writeTidbitsSiteUrlsToStream(space, smStream); } smStream.end();