mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-25 08:35:42 +02:00
Revert "chore: update roadmap json endpoint"
This reverts commit 580e764097
.
This commit is contained in:
@@ -3,7 +3,6 @@ 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;
|
||||||
|
|
||||||
@@ -31,16 +30,10 @@ type RoadmapJson = {
|
|||||||
|
|
||||||
export async function fetchRoadmapJson(
|
export async function fetchRoadmapJson(
|
||||||
roadmapId: string,
|
roadmapId: string,
|
||||||
): Promise<OfficialRoadmapDocument> {
|
): Promise<RoadmapJson> {
|
||||||
const isDev = import.meta.env.DEV;
|
const response = await fetch(
|
||||||
const baseUrl = new URL(
|
`https://roadmap.sh/api/v1-official-roadmap/${roadmapId}`,
|
||||||
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}`);
|
||||||
@@ -63,7 +56,48 @@ 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,60 +2,14 @@ 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;
|
||||||
order: number;
|
title: string;
|
||||||
|
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