mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-22 00:43:01 +02:00
chore: update official roadmap endpoint (#8628)
* chore: update official roadmap endpoint * fix: variable typo Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import { slugify } from '../src/lib/slugger';
|
||||
import { markdownToHtml } from '../src/lib/markdown';
|
||||
import { HTMLElement, parse } from 'node-html-parser';
|
||||
import { htmlToMarkdown } from '../src/lib/html';
|
||||
import { httpGet } from '../src/lib/http';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -53,13 +54,16 @@ if (!stats || !stats.isDirectory()) {
|
||||
for (const roadmapId of editorRoadmapIds) {
|
||||
console.log(`🚀 Starting ${roadmapId}`);
|
||||
|
||||
const roadmapDir = path.join(
|
||||
ROADMAP_CONTENT_DIR,
|
||||
roadmapId,
|
||||
`${roadmapId}.json`,
|
||||
const { response: data, error } = await httpGet(
|
||||
`${import.meta.env.PUBLIC_API_URL}/v1-official-roadmap/${roadmapId}`,
|
||||
);
|
||||
const roadmapContent = await fs.readFile(roadmapDir, 'utf-8');
|
||||
let { nodes } = JSON.parse(roadmapContent) as {
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
continue;
|
||||
}
|
||||
|
||||
let { nodes } = data as {
|
||||
nodes: Node[];
|
||||
};
|
||||
nodes = nodes.filter(
|
||||
@@ -97,11 +101,11 @@ for (const roadmapId of editorRoadmapIds) {
|
||||
> = {};
|
||||
|
||||
for (const node of nodes) {
|
||||
const ndoeDirPatterWithoutExt = `${slugify(node.data.label)}@${node.id}`;
|
||||
const nodeDirPattern = `${ndoeDirPatterWithoutExt}.md`;
|
||||
const nodeDirPatternWithoutExt = `${slugify(node?.data?.label as string)}@${node.id}`;
|
||||
const nodeDirPattern = `${nodeDirPatternWithoutExt}.md`;
|
||||
if (!roadmapContentFiles.includes(nodeDirPattern)) {
|
||||
contentMap[nodeDirPattern] = {
|
||||
title: node.data.label,
|
||||
title: node?.data?.label as string,
|
||||
description: '',
|
||||
links: [],
|
||||
};
|
||||
@@ -169,7 +173,7 @@ for (const roadmapId of editorRoadmapIds) {
|
||||
const description = htmlToMarkdown(htmlStringWithoutLinks);
|
||||
|
||||
contentMap[node.id] = {
|
||||
title: node.data.label,
|
||||
title: node.data.label as string,
|
||||
description,
|
||||
links: listLinks,
|
||||
};
|
||||
|
@@ -7,6 +7,7 @@ import type { RoadmapFrontmatter } from '../src/lib/roadmap';
|
||||
import { slugify } from '../src/lib/slugger';
|
||||
import OpenAI from 'openai';
|
||||
import { runPromisesInBatchSequentially } from '../src/lib/promise';
|
||||
import { httpGet } from '../src/lib/http';
|
||||
|
||||
// ERROR: `__dirname` is not defined in ES module scope
|
||||
// https://iamwebwiz.medium.com/how-to-fix-dirname-is-not-defined-in-es-module-scope-34d94a86694d
|
||||
@@ -50,13 +51,16 @@ if (roadmapFrontmatter.renderer !== 'editor') {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const roadmapDir = path.join(
|
||||
ROADMAP_CONTENT_DIR,
|
||||
roadmapId,
|
||||
`${roadmapId}.json`,
|
||||
const { response: roadmapContent, error } = await httpGet(
|
||||
`${import.meta.env.PUBLIC_API_URL}/v1-official-roadmap/${roadmapId}`,
|
||||
);
|
||||
const roadmapContent = await fs.readFile(roadmapDir, 'utf-8');
|
||||
let { nodes, edges } = JSON.parse(roadmapContent) as {
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let { nodes, edges } = roadmapContent as {
|
||||
nodes: Node[];
|
||||
edges: Edge[];
|
||||
};
|
||||
@@ -138,7 +142,7 @@ function writeTopicContent(
|
||||
}
|
||||
|
||||
async function writeNodeContent(node: Node & { parentTitle?: string }) {
|
||||
const nodeDirPattern = `${slugify(node.data.label)}@${node.id}.md`;
|
||||
const nodeDirPattern = `${slugify(node?.data?.label as string)}@${node.id}.md`;
|
||||
if (!roadmapContentFiles.includes(nodeDirPattern)) {
|
||||
console.log(`Missing file for: ${nodeDirPattern}`);
|
||||
return;
|
||||
@@ -152,7 +156,7 @@ async function writeNodeContent(node: Node & { parentTitle?: string }) {
|
||||
return;
|
||||
}
|
||||
|
||||
const topic = node.data.label;
|
||||
const topic = node.data.label as string;
|
||||
const parentTopic = node.parentTitle;
|
||||
|
||||
console.log(`⏳ Generating content for ${topic}...`);
|
||||
|
@@ -5,6 +5,7 @@ import type { Node } from '@roadmapsh/editor';
|
||||
import matter from 'gray-matter';
|
||||
import type { RoadmapFrontmatter } from '../src/lib/roadmap';
|
||||
import { slugify } from '../src/lib/slugger';
|
||||
import { httpGet } from '../src/lib/http';
|
||||
|
||||
// ERROR: `__dirname` is not defined in ES module scope
|
||||
// https://iamwebwiz.medium.com/how-to-fix-dirname-is-not-defined-in-es-module-scope-34d94a86694d
|
||||
@@ -48,13 +49,16 @@ if (roadmapFrontmatter.renderer !== 'editor') {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const roadmapDir = path.join(
|
||||
ROADMAP_CONTENT_DIR,
|
||||
roadmapId,
|
||||
`${roadmapId}.json`,
|
||||
const { response: roadmapContent, error } = await httpGet(
|
||||
`${import.meta.env.PUBLIC_API_URL}/v1-official-roadmap/${roadmapId}`,
|
||||
);
|
||||
const roadmapContent = await fs.readFile(roadmapDir, 'utf-8');
|
||||
let { nodes } = JSON.parse(roadmapContent) as {
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let { nodes } = roadmapContent as {
|
||||
nodes: Node[];
|
||||
};
|
||||
nodes = nodes.filter(
|
||||
@@ -73,7 +77,7 @@ const roadmapContentFiles = await fs.readdir(roadmapContentDir, {
|
||||
});
|
||||
|
||||
nodes.forEach(async (node, index) => {
|
||||
const nodeDirPattern = `${slugify(node.data.label)}@${node.id}.md`;
|
||||
const nodeDirPattern = `${slugify(node.data.label as string)}@${node.id}.md`;
|
||||
if (roadmapContentFiles.includes(nodeDirPattern)) {
|
||||
console.log(`Skipping ${nodeDirPattern}`);
|
||||
return;
|
||||
|
Reference in New Issue
Block a user