Refactor faqs

feat/roadmap-slug
Kamran Ahmed 11 months ago
parent bd01586e8e
commit 7b4ced400c
  1. 2
      src/data/roadmaps/frontend/faqs.astro
  2. 8
      src/lib/roadmap.ts
  3. 24
      src/pages/[roadmapId]/index.astro

@ -1,5 +1,5 @@
--- ---
import type { FAQType } from '../../components/FAQs/FAQs.astro'; import type { FAQType } from '../../../components/FAQs/FAQs.astro';
export const faqs: FAQType[] = [ export const faqs: FAQType[] = [
{ {

@ -130,3 +130,11 @@ export async function getRoadmapsByIds(
return Promise.all(ids.map((id) => getRoadmapById(id))); return Promise.all(ids.map((id) => getRoadmapById(id)));
} }
export async function getRoadmapFaqsById(roadmapId: string): Promise<string[]> {
const { faqs } = await import(
`/src/data/roadmaps/${roadmapId}/faqs.astro`
).catch(() => ({}));
return faqs || [];
}

@ -12,31 +12,25 @@ import {
generateArticleSchema, generateArticleSchema,
generateFAQSchema, generateFAQSchema,
} from '../../lib/jsonld-schema'; } from '../../lib/jsonld-schema';
import { type RoadmapFrontmatter } from '../../lib/roadmap';
import {
getRoadmapById,
type RoadmapFrontmatter,
getRoadmapFaqsById,
} from '../../lib/roadmap';
interface Params extends Record<string, string | undefined> { interface Params extends Record<string, string | undefined> {
roadmapId: string; roadmapId: string;
} }
const { roadmapId } = Astro.params as Params; const { roadmapId } = Astro.params as Params;
let roadmapFile;
let roadmapFAQs = [];
try {
roadmapFile = await import(
`../../data/roadmaps/${roadmapId}/${roadmapId}.md`
);
if (!roadmapFile) {
return Astro.redirect('/404');
}
const { faqs } = await import(`../../data/roadmaps/${roadmapId}/faqs.astro`); const roadmapFile = await getRoadmapById(roadmapId).catch(() => null);
roadmapFAQs = faqs || []; if (!roadmapFile) {
} catch (error) {
return Astro.redirect('/404'); return Astro.redirect('/404');
} }
const roadmapFAQs = await getRoadmapFaqsById(roadmapId);
const roadmapData = roadmapFile.frontmatter as RoadmapFrontmatter; const roadmapData = roadmapFile.frontmatter as RoadmapFrontmatter;
let jsonLdSchema = []; let jsonLdSchema = [];

Loading…
Cancel
Save