From 8b5e7933b475e961757ab33e593043313bc69d08 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Tue, 19 Aug 2025 08:36:04 +0600 Subject: [PATCH] fix: guides pages --- src/components/Questions/QuestionGuide.astro | 182 ------------------- src/lib/video.ts | 2 - src/pages/dashboard.astro | 1 - src/pages/pages.json.ts | 35 ++-- src/pages/questions/[questionGroupId].astro | 84 --------- src/pages/questions/index.astro | 37 ---- src/queries/official-guide.ts | 16 ++ 7 files changed, 38 insertions(+), 319 deletions(-) delete mode 100644 src/components/Questions/QuestionGuide.astro delete mode 100644 src/pages/questions/[questionGroupId].astro delete mode 100644 src/pages/questions/index.astro diff --git a/src/components/Questions/QuestionGuide.astro b/src/components/Questions/QuestionGuide.astro deleted file mode 100644 index ebb4e7f3a..000000000 --- a/src/components/Questions/QuestionGuide.astro +++ /dev/null @@ -1,182 +0,0 @@ ---- -import { getGuideTableOfContent, type HeadingGroupType } from '../../lib/guide'; -import { markdownToHtml } from '../../lib/markdown'; -import { - type QuestionGroupType, - type QuestionType, -} from '../../lib/question-group'; -import { slugify } from '../../lib/slugger'; -import { RelatedGuides } from '../Guide/RelatedGuides'; -import MarkdownFile from '../MarkdownFile.astro'; -import { TableOfContent } from '../TableOfContent/TableOfContent'; -import { QuestionsList } from './QuestionsList'; - -interface Props { - questionGroup: QuestionGroupType; -} - -const { questionGroup } = Astro.props; - -const { frontmatter: guideFrontmatter, author } = questionGroup; - -// Group questions by topics -const questionsGroupedByTopics = questionGroup.questions.reduce( - (acc, question) => { - question.topics?.forEach((topic) => { - acc[topic] = [...(acc[topic] || []), question]; - }); - return acc; - }, - {} as Record, -); - -// Get all unique topics in the order they appear in the questions array -const topicsInOrder: string[] = []; -questionGroup.questions.forEach((question) => { - question.topics?.forEach((topic) => { - if (!topicsInOrder.includes(topic)) { - topicsInOrder.push(topic); - } - }); -}); - -const allHeadings = questionGroup.getHeadings(); -let tableOfContent: HeadingGroupType[] = [ - ...getGuideTableOfContent(allHeadings), - { - depth: 2, - children: [], - slug: 'test-with-flashcards', - text: 'Test yourself with Flashcards', - }, - { - depth: 2, - children: topicsInOrder.map((topic) => { - let topicText = topic; - let topicSlug = slugify(topic); - if (topic.toLowerCase() === 'beginners') { - topicText = 'Beginner Level'; - topicSlug = 'beginner-level'; - } else if (topic.toLowerCase() === 'intermediate') { - topicText = 'Intermediate Level'; - topicSlug = 'intermediate-level'; - } else if (topic.toLowerCase() === 'advanced') { - topicText = 'Advanced Level'; - topicSlug = 'advanced-level'; - } - - return { - depth: 2, - children: [], - slug: topicSlug, - text: topicText, - }; - }), - slug: 'questions-list', - text: 'Questions List', - }, -]; - -const showTableOfContent = tableOfContent.length > 0; ---- - -
- - -
- -

- {guideFrontmatter.title} -

- { - author && ( -

- - {author.frontmatter.name} - {author.frontmatter.name} - - - -

- ) - } - - -

Test yourself with Flashcards

-

- You can either use these flashcards or jump to the questions list - section below to see them in a list format. -

- - -

Questions List

-

- If you prefer to see the questions in a list format, you can find them - below. -

- - { - topicsInOrder.map((questionLevel) => ( -
-

- {questionLevel.toLowerCase() === 'beginners' ? 'Beginner Level' : - questionLevel.toLowerCase() === 'intermediate' ? 'Intermediate Level' : - questionLevel.toLowerCase() === 'advanced' ? 'Advanced Level' : - questionLevel} -

- {questionsGroupedByTopics[questionLevel].map((q) => ( -
-

{q.question}

-
-
- ))} -
- )) - } - { - questionGroup.ending && ( -
-
-
- ) - } - -
-
diff --git a/src/lib/video.ts b/src/lib/video.ts index d34e27ab4..3e713cc3d 100644 --- a/src/lib/video.ts +++ b/src/lib/video.ts @@ -1,8 +1,6 @@ import type { MarkdownFileType } from './file'; import type { AuthorFileType } from './author.ts'; import { getAllAuthors } from './author.ts'; -import type { GuideFileType } from './guide.ts'; -import { getAllGuides } from './guide.ts'; export interface VideoFrontmatter { title: string; diff --git a/src/pages/dashboard.astro b/src/pages/dashboard.astro index b1049fa7c..fc2846126 100644 --- a/src/pages/dashboard.astro +++ b/src/pages/dashboard.astro @@ -4,7 +4,6 @@ import BaseLayout from '../layouts/BaseLayout.astro'; import { getAllBestPractices } from '../lib/best-practice'; import { getAllQuestionGroups } from '../lib/question-group'; import { getRoadmapsByTag } from '../lib/roadmap'; -import { getAllGuides } from '../lib/guide'; import { getAllVideos } from '../lib/video'; import { listOfficialGuides } from '../queries/official-guide'; diff --git a/src/pages/pages.json.ts b/src/pages/pages.json.ts index 57d566149..1819f45b5 100644 --- a/src/pages/pages.json.ts +++ b/src/pages/pages.json.ts @@ -1,9 +1,12 @@ import { getAllBestPractices } from '../lib/best-practice'; -import { getAllGuides } from '../lib/guide'; import { getRoadmapsByTag } from '../lib/roadmap'; import { getAllVideos } from '../lib/video'; import { getAllQuestionGroups } from '../lib/question-group'; import { getAllProjects } from '../lib/project'; +import { + listOfficialAuthors, + listOfficialGuides, +} from '../queries/official-guide'; // Add utility to fetch beginner roadmap file IDs function getBeginnerRoadmapIds() { @@ -18,7 +21,8 @@ function getBeginnerRoadmapIds() { } export async function GET() { - const guides = await getAllGuides(); + const guides = await listOfficialGuides(); + const authors = await listOfficialAuthors(); const videos = await getAllVideos(); const questionGroups = await getAllQuestionGroups(); const roadmaps = await getRoadmapsByTag('roadmap'); @@ -78,17 +82,22 @@ export async function GET() { shortTitle: questionGroup.frontmatter.briefTitle, group: 'Questions', })), - ...guides.map((guide) => ({ - id: guide.id, - url: guide.frontmatter.excludedBySlug - ? guide.frontmatter.excludedBySlug - : `/guides/${guide.id}`, - title: guide.frontmatter.title, - description: guide.frontmatter.description, - authorId: guide.frontmatter.authorId, - shortTitle: guide.frontmatter.title, - group: 'Guides', - })), + ...guides.map((guide) => { + const author = authors.find((author) => author._id === guide.authorId); + const authorSlug = author?.slug || guide?.authorId; + + return { + id: guide.slug, + url: guide?.roadmapId + ? `/${guide.roadmapId}/${guide.slug}` + : `/guides/${guide.slug}`, + title: guide.title, + description: guide.description, + authorId: authorSlug, + shortTitle: guide.title, + group: 'Guides', + }; + }), ...videos.map((video) => ({ id: video.id, url: `/videos/${video.id}`, diff --git a/src/pages/questions/[questionGroupId].astro b/src/pages/questions/[questionGroupId].astro deleted file mode 100644 index f862cba7f..000000000 --- a/src/pages/questions/[questionGroupId].astro +++ /dev/null @@ -1,84 +0,0 @@ ---- -import BaseLayout from '../../layouts/BaseLayout.astro'; -import Footer from '../../components/Footer.astro'; -import { QuestionsList } from '../../components/Questions/QuestionsList'; - -import { - getAllQuestionGroups, - type QuestionGroupType, -} from '../../lib/question-group'; -import QuestionGuide from '../../components/Questions/QuestionGuide.astro'; - -export const prerender = true; - -export interface Props { - questionGroup: QuestionGroupType; -} - -export async function getStaticPaths() { - const questionGroups = await getAllQuestionGroups(); - - return questionGroups.map((questionGroup) => { - return { - params: { questionGroupId: questionGroup.id }, - props: { questionGroup }, - }; - }); -} - -const { questionGroup } = Astro.props; -const { frontmatter } = questionGroup; ---- - - - { - !questionGroup.frontmatter.authorId && ( -
-
-
- -

- {frontmatter.title} -

- -
- - -
-
- ) - } - - { - questionGroup.frontmatter.authorId && ( - - ) - } - -
-
-
-
diff --git a/src/pages/questions/index.astro b/src/pages/questions/index.astro deleted file mode 100644 index 1aaca02e7..000000000 --- a/src/pages/questions/index.astro +++ /dev/null @@ -1,37 +0,0 @@ ---- -import GridItem from '../../components/GridItem.astro'; -import SimplePageHeader from '../../components/SimplePageHeader.astro'; -import BaseLayout from '../../layouts/BaseLayout.astro'; -import { getAllQuestionGroups } from '../../lib/question-group'; - -const questionGroups = await getAllQuestionGroups(); ---- - - - - -
-
-
- { - questionGroups.map((questionGroup) => ( - - )) - } -
-
-
-
diff --git a/src/queries/official-guide.ts b/src/queries/official-guide.ts index c8215845b..e3c7c5926 100644 --- a/src/queries/official-guide.ts +++ b/src/queries/official-guide.ts @@ -103,6 +103,22 @@ export async function getOfficialGuide(slug: string, roadmapId?: string) { } } +export async function listOfficialAuthors() { + try { + const authors = await httpGet( + `/v1-list-official-authors`, + ); + + return authors; + } catch (error) { + if (FetchError.isFetchError(error) && error.status === 404) { + return []; + } + + throw error; + } +} + export function getOfficialGuideHref(slug: string, roadmapId?: string) { const isExternal = roadmapId && roadmapId !== 'questions'; return isExternal