mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-06 23:30:42 +02:00
chore: update roadmap json endpoint
This commit is contained in:
committed by
Kamran Ahmed
parent
111a97bb55
commit
580e764097
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import matter from 'gray-matter';
|
import matter from 'gray-matter';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import type { OfficialRoadmapDocument } from '../queries/official-roadmap';
|
||||||
|
|
||||||
export const prerender = false;
|
export const prerender = false;
|
||||||
|
|
||||||
@@ -30,10 +31,16 @@ type RoadmapJson = {
|
|||||||
|
|
||||||
export async function fetchRoadmapJson(
|
export async function fetchRoadmapJson(
|
||||||
roadmapId: string,
|
roadmapId: string,
|
||||||
): Promise<RoadmapJson> {
|
): Promise<OfficialRoadmapDocument> {
|
||||||
const response = await fetch(
|
const isDev = import.meta.env.DEV;
|
||||||
`https://roadmap.sh/api/v1-official-roadmap/${roadmapId}`,
|
const baseUrl = new URL(
|
||||||
|
isDev ? 'http://localhost:8080' : 'https://roadmap.sh',
|
||||||
);
|
);
|
||||||
|
baseUrl.pathname = isDev
|
||||||
|
? `/v1-official-roadmap/${roadmapId}`
|
||||||
|
: `/api/v1-official-roadmap/${roadmapId}`;
|
||||||
|
|
||||||
|
const response = await fetch(String(baseUrl));
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to fetch roadmap json: ${response.statusText}`);
|
throw new Error(`Failed to fetch roadmap json: ${response.statusText}`);
|
||||||
@@ -56,48 +63,7 @@ export const GET: APIRoute = async function ({ params, request, props }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the path to the markdown file
|
|
||||||
let roadmapFilePath = path.join(
|
|
||||||
projectRoot,
|
|
||||||
'src',
|
|
||||||
'data',
|
|
||||||
'roadmaps',
|
|
||||||
roadmapId,
|
|
||||||
`${roadmapId}.md`,
|
|
||||||
);
|
|
||||||
|
|
||||||
let roadmapJsonPath = path.join(
|
|
||||||
projectRoot,
|
|
||||||
'src',
|
|
||||||
'data',
|
|
||||||
'roadmaps',
|
|
||||||
roadmapId,
|
|
||||||
`${roadmapId}.json`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!fs.existsSync(roadmapFilePath)) {
|
|
||||||
return new Response(JSON.stringify({ message: 'Roadmap not found' }), {
|
|
||||||
status: 404,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read and parse the markdown file
|
|
||||||
const fileContent = fs.readFileSync(roadmapFilePath, 'utf-8');
|
|
||||||
const { data: frontmatter, content } = matter(fileContent);
|
|
||||||
|
|
||||||
if (frontmatter.renderer !== 'editor') {
|
|
||||||
const roadmapJson = JSON.parse(fs.readFileSync(roadmapJsonPath, 'utf-8'));
|
|
||||||
|
|
||||||
return new Response(JSON.stringify(roadmapJson), {
|
|
||||||
status: 200,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const roadmapJson = await fetchRoadmapJson(roadmapId);
|
const roadmapJson = await fetchRoadmapJson(roadmapId);
|
||||||
|
|
||||||
return new Response(JSON.stringify(roadmapJson), {
|
return new Response(JSON.stringify(roadmapJson), {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
|
@@ -2,14 +2,60 @@ import { queryOptions } from '@tanstack/react-query';
|
|||||||
import { httpGet } from '../lib/query-http';
|
import { httpGet } from '../lib/query-http';
|
||||||
import type { Node, Edge } from '@roadmapsh/editor';
|
import type { Node, Edge } from '@roadmapsh/editor';
|
||||||
|
|
||||||
|
export const allowedOfficialRoadmapType = ['skill', 'role'] as const;
|
||||||
|
export type AllowedOfficialRoadmapType =
|
||||||
|
(typeof allowedOfficialRoadmapType)[number];
|
||||||
|
|
||||||
|
export const allowedOfficialRoadmapQuestionType = ['faq', 'main'] as const;
|
||||||
|
export type AllowedOfficialRoadmapQuestionType =
|
||||||
|
(typeof allowedOfficialRoadmapQuestionType)[number];
|
||||||
|
|
||||||
|
export type OfficialRoadmapQuestion = {
|
||||||
|
_id: string;
|
||||||
|
type: AllowedOfficialRoadmapQuestionType;
|
||||||
|
title: string;
|
||||||
|
// Tiptap JSON Content
|
||||||
|
description: any;
|
||||||
|
};
|
||||||
|
|
||||||
export interface OfficialRoadmapDocument {
|
export interface OfficialRoadmapDocument {
|
||||||
_id: string;
|
_id: string;
|
||||||
title: string;
|
order: number;
|
||||||
description?: string;
|
|
||||||
|
title: {
|
||||||
|
card: string;
|
||||||
|
page: string;
|
||||||
|
};
|
||||||
|
description: string;
|
||||||
|
|
||||||
slug: string;
|
slug: string;
|
||||||
nodes: Node[];
|
nodes: Node[];
|
||||||
edges: Edge[];
|
edges: Edge[];
|
||||||
|
|
||||||
|
draft: {
|
||||||
|
nodes: Node[];
|
||||||
|
edges: Edge[];
|
||||||
|
};
|
||||||
|
|
||||||
|
seo: {
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
keywords: string[];
|
||||||
|
};
|
||||||
|
partner?: {
|
||||||
|
description: string;
|
||||||
|
linkText: string;
|
||||||
|
link: string;
|
||||||
|
};
|
||||||
|
type: AllowedOfficialRoadmapType;
|
||||||
|
dimensions?: {
|
||||||
|
height: number;
|
||||||
|
width: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
questions?: OfficialRoadmapQuestion[];
|
||||||
|
relatedRoadmaps?: string[];
|
||||||
|
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user