--- 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; ---
{ showTableOfContent && (
) }

{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 && (
) }