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