Compare commits

...

3 Commits

Author SHA1 Message Date
Arik Chakma
0560cc930a fix: topic path 2025-08-20 20:00:03 +06:00
Arik Chakma
c903b76934 fix: remove title 2025-08-20 19:34:41 +06:00
Arik Chakma
4f586fd122 fix: sync content description 2025-08-20 19:31:17 +06:00
3 changed files with 45 additions and 16 deletions

View File

@@ -54,7 +54,7 @@ jobs:
automated pr
reviewers: arikchakma
commit-message: "chore: sync content to repo"
title: "Sync Content to Repo - Automated"
title: "chore: sync content to repository"
body: |
## Sync Content to Repo

View File

@@ -2,6 +2,7 @@ import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { slugify } from '../src/lib/slugger';
import type { OfficialRoadmapDocument } from '../src/queries/official-roadmap';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -43,7 +44,6 @@ export interface OfficialRoadmapTopicContentDocument {
_id?: string;
roadmapSlug: string;
nodeId: string;
title: string;
description: string;
resources: OfficialRoadmapTopicResource[];
createdAt: Date;
@@ -68,6 +68,25 @@ export async function roadmapTopics(
return data;
}
export async function fetchRoadmapJson(
roadmapId: string,
): Promise<OfficialRoadmapDocument> {
const response = await fetch(
`https://roadmap.sh/api/v1-official-roadmap/${roadmapId}`,
);
if (!response.ok) {
throw new Error(`Failed to fetch roadmap json: ${response.statusText}`);
}
const data = await response.json();
if (data.error) {
throw new Error(`Failed to fetch roadmap json: ${data.error}`);
}
return data;
}
// Directory containing the roadmaps
const ROADMAP_CONTENT_DIR = path.join(
__dirname,
@@ -76,12 +95,27 @@ const ROADMAP_CONTENT_DIR = path.join(
);
const allTopics = await roadmapTopics(roadmapSlug, secret);
const roadmap = await fetchRoadmapJson(roadmapSlug);
const { nodes } = roadmap;
for (const topic of allTopics) {
const { title, nodeId } = topic;
const { nodeId } = topic;
const topicSlug = `${slugify(title)}@${nodeId}.md`;
const node = nodes.find((node) => node.id === nodeId);
if (!node) {
console.error(`Node not found: ${nodeId}`);
continue;
}
const topicPath = path.join(ROADMAP_CONTENT_DIR, topicSlug);
const label = node?.data?.label as string;
if (!label) {
console.error(`Label not found: ${nodeId}`);
continue;
}
const topicSlug = `${slugify(label)}@${nodeId}.md`;
const topicPath = path.join(ROADMAP_CONTENT_DIR, 'content', topicSlug);
const topicDir = path.dirname(topicPath);
const topicDirExists = await fs
.stat(topicDir)
@@ -99,12 +133,10 @@ for (const topic of allTopics) {
function prepareTopicContent(topic: OfficialRoadmapTopicContentDocument) {
const { description, resources = [] } = topic;
const content = `${description}
Visit the following resources to learn more:
${resources.map((resource) => `- [@${resource.type}@${resource.title}](${resource.url})`).join('\n')}
`.trim();
let content = description;
if (resources.length > 0) {
content += `\n\nVisit the following resources to learn more:\n\n${resources.map((resource) => `- [@${resource.type}@${resource.title}](${resource.url})`).join('\n')}`;
}
return content;
}

View File

@@ -1,7 +1,6 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { slugify } from '../src/lib/slugger';
import type { OfficialRoadmapDocument } from '../src/queries/official-roadmap';
import { parse } from 'node-html-parser';
import { markdownToHtml } from '../src/lib/markdown';
@@ -192,9 +191,8 @@ try {
const htmlStringWithoutLinks = rootHtml.toString();
const description = htmlToMarkdown(htmlStringWithoutLinks);
const updatedDescription = `# ${title?.textContent}
${description}`.trim();
const updatedDescription =
`# ${title?.textContent}\n\n${description}`.trim();
const label = node?.data?.label as string;
if (!label) {
@@ -205,7 +203,6 @@ ${description}`.trim();
topics.push({
roadmapSlug,
nodeId,
title: label,
description: updatedDescription,
resources: listLinks,
});