mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2026-03-12 17:51:53 +08:00
Add kotlin assets
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
"enabled": false
|
||||
},
|
||||
"_variables": {
|
||||
"lastUpdateCheck": 1756224238932
|
||||
"lastUpdateCheck": 1757411878192
|
||||
}
|
||||
}
|
||||
1
.astro/types.d.ts
vendored
1
.astro/types.d.ts
vendored
@@ -1,2 +1 @@
|
||||
/// <reference types="astro/client" />
|
||||
/// <reference path="content.d.ts" />
|
||||
BIN
public/pdfs/roadmaps/kotlin.pdf
Normal file
BIN
public/pdfs/roadmaps/kotlin.pdf
Normal file
Binary file not shown.
BIN
public/roadmaps/kotlin.png
Normal file
BIN
public/roadmaps/kotlin.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 476 KiB |
@@ -1,49 +1,33 @@
|
||||
import playwright from 'playwright';
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import matter from 'gray-matter';
|
||||
import type { RoadmapFrontmatter } from '../src/lib/roadmap';
|
||||
|
||||
// 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
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
// Usage: tsx ./scripts/editor-roadmap-dirs.ts <roadmapId>
|
||||
|
||||
// Directory containing the roadmaps
|
||||
const ROADMAP_CONTENT_DIR = path.join(__dirname, '../src/data/roadmaps');
|
||||
const roadmapId = process.argv[2];
|
||||
|
||||
const allowedRoadmapIds = await fs.readdir(ROADMAP_CONTENT_DIR);
|
||||
if (!roadmapId) {
|
||||
console.error('Roadmap Id is required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!allowedRoadmapIds.includes(roadmapId)) {
|
||||
console.error(`Invalid roadmap key ${roadmapId}`);
|
||||
console.error(`Allowed keys are ${allowedRoadmapIds.join(', ')}`);
|
||||
// Fetch roadmap data from API
|
||||
const apiUrl = `https://roadmap.sh/api/v1-official-roadmap/${roadmapId}`;
|
||||
console.log(`Fetching roadmap data from ${apiUrl}`);
|
||||
|
||||
let roadmapData: any;
|
||||
try {
|
||||
const response = await fetch(apiUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
roadmapData = await response.json();
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch roadmap data: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const roadmapFrontmatterDir = path.join(
|
||||
ROADMAP_CONTENT_DIR,
|
||||
roadmapId,
|
||||
`${roadmapId}.md`,
|
||||
);
|
||||
const roadmapFrontmatterRaw = await fs.readFile(roadmapFrontmatterDir, 'utf-8');
|
||||
const { data } = matter(roadmapFrontmatterRaw);
|
||||
|
||||
const roadmapFrontmatter = data as RoadmapFrontmatter;
|
||||
if (!roadmapFrontmatter) {
|
||||
console.error('Invalid roadmap frontmatter');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (roadmapFrontmatter.renderer !== 'editor') {
|
||||
console.error('Only Editor Rendered Roadmaps are allowed');
|
||||
// Check if dimensions exist in the API response
|
||||
if (!roadmapData.dimensions) {
|
||||
console.error('Invalid roadmap data: missing dimensions');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -61,8 +45,8 @@ console.log(`Generating PDF ${pageUrl}`);
|
||||
await page.pdf({
|
||||
path: `./public/pdfs/roadmaps/${roadmapId}.pdf`,
|
||||
margin: { top: 0, right: 0, bottom: 0, left: 0 },
|
||||
height: roadmapFrontmatter?.dimensions?.height || 2000,
|
||||
width: roadmapFrontmatter?.dimensions?.width || 968,
|
||||
height: roadmapData.dimensions?.height || 2000,
|
||||
width: roadmapData.dimensions?.width || 968,
|
||||
});
|
||||
|
||||
// @todo generate png from the pdf
|
||||
|
||||
Reference in New Issue
Block a user