1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-29 20:21:50 +02:00

fix: sync repo to db

This commit is contained in:
Arik Chakma
2025-08-20 14:38:44 +06:00
committed by Kamran Ahmed
parent d70582411e
commit 885e95399e

View File

@@ -6,9 +6,11 @@ import type { OfficialRoadmapDocument } from '../src/queries/official-roadmap';
import { parse } from 'node-html-parser';
import { markdownToHtml } from '../src/lib/markdown';
import { htmlToMarkdown } from '../src/lib/html';
import type {
OfficialRoadmapTopicContentDocument,
OfficialRoadmapTopicResource,
import {
allowedOfficialRoadmapTopicResourceType,
type AllowedOfficialRoadmapTopicResourceType,
type OfficialRoadmapTopicContentDocument,
type OfficialRoadmapTopicResource,
} from './sync-content-to-repo';
const __filename = fileURLToPath(import.meta.url);
@@ -46,24 +48,38 @@ export async function fetchRoadmapJson(
return data;
}
export const allowedOfficialRoadmapTopicResourceType = [
'official',
'opensource',
'article',
'course',
'podcast',
'video',
'book',
'feed',
] as const;
export type AllowedOfficialRoadmapTopicResourceType =
(typeof allowedOfficialRoadmapTopicResourceType)[number];
export async function syncContentToDatabase(
topics: Omit<
OfficialRoadmapTopicContentDocument,
'createdAt' | 'updatedAt' | '_id'
>[],
) {
const response = await fetch(
`https://roadmap.sh/api/v1-sync-official-roadmap-topics`,
{
method: 'POST',
body: JSON.stringify({
topics,
secret,
}),
},
);
if (!response.ok) {
throw new Error(
`Failed to sync content to database: ${response.statusText}`,
);
}
return response.json();
}
const files = allFiles.split(' ');
console.log(`🚀 Starting ${files.length} files`);
const ROADMAP_CONTENT_DIR = path.join(__dirname, '../src/data/roadmaps');
try {
const topics: Omit<
OfficialRoadmapTopicContentDocument,
'createdAt' | 'updatedAt' | '_id'
@@ -82,6 +98,7 @@ for (const file of files) {
console.error(`🚨 Roadmap slug is required: ${file}`);
continue;
}
const nodeSlug = pathParts?.[2]?.replace('.md', '');
if (!nodeSlug) {
console.error(`🚨 Node id is required: ${file}`);
@@ -165,9 +182,10 @@ for (const file of files) {
ulWithLinks?.remove();
title?.remove();
if (listLinks.length > 0) {
const lastParagraph = rootHtml.querySelector('p:last-child');
console.log(lastParagraph?.textContent);
const allParagraphs = rootHtml.querySelectorAll('p');
if (listLinks.length > 0 && allParagraphs.length > 0) {
// to remove the view more see more from the description
const lastParagraph = allParagraphs[allParagraphs.length - 1];
lastParagraph?.remove();
}
@@ -193,4 +211,8 @@ ${description}`.trim();
});
}
console.log(JSON.stringify(topics, null, 2));
await syncContentToDatabase(topics);
} catch (error) {
console.error(error);
process.exit(1);
}