Skip to content

Commit

Permalink
Merge pull request #77 from kamranahmedse/master
Browse files Browse the repository at this point in the history
Create a new pull request by comparing changes across two branches
  • Loading branch information
GulajavaMinistudio authored Apr 18, 2023
2 parents 9fb0c7c + 03f9fa5 commit 1114561
Show file tree
Hide file tree
Showing 289 changed files with 13,448 additions and 1,290 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PUBLIC_API_URL=http://api.roadmap.sh
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches: [ master ]
env:
PUBLIC_API_URL: "https://api.roadmap.sh"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PAT: ${{ secrets.PAT }}
CI: true
Expand Down
5 changes: 4 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// https://astro.build/config
import sitemap from '@astrojs/sitemap';
import tailwind from '@astrojs/tailwind';
import compress from 'astro-compress';
import { defineConfig } from 'astro/config';
import compress from 'astro-compress';
import rehypeExternalLinks from 'rehype-external-links';
import { serializeSitemap, shouldIndexPage } from './sitemap.mjs';
import preact from '@astrojs/preact';

// https://astro.build/config
export default defineConfig({
site: 'https://roadmap.sh/',
markdown: {
Expand Down Expand Up @@ -56,5 +58,6 @@ export default defineConfig({
css: false,
js: false,
}),
preact(),
],
});
98 changes: 54 additions & 44 deletions bin/roadmap-content.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ function writeTopicContent(currTopicUrl) {
.slice(-2)
.map((topic) => topic.replace(/-/g, ' '));

const roadmapTitle = roadmapId.replace(/-/g, ' ');
// const roadmapTitle = roadmapId.replace(/-/g, ' ');
const roadmapTitle = 'PostgreSQL';

let prompt = `I am reading a guide about "${roadmapTitle}". I am on the topic "${parentTopic}". I want to know more about "${childTopic}". Write me a brief summary for that topic. Content should be in markdown. Behave as if you are the author of the guide.`;
if (!childTopic) {
prompt = `I am reading a guide about "${roadmapTitle}". I am on the topic "${parentTopic}". I want to know more about "${parentTopic}". Write me a brief summary for that topic. Content should be in markdown. Behave as if you are the author of the guide.`;
}

console.log(`Genearting '${childTopic || parentTopic}'...`);
console.log(`Generating '${childTopic || parentTopic}'...`);

return new Promise((resolve, reject) => {
openai
Expand All @@ -90,6 +91,52 @@ function writeTopicContent(currTopicUrl) {
});
}

async function writeFileForGroup(group, topicUrlToPathMapping) {
const topicId = group?.properties?.controlName;
const topicTitle = group?.children?.controls?.control?.find(
(control) => control?.typeID === 'Label'
)?.properties?.text;
const currTopicUrl = topicId?.replace(/^\d+-/g, '/')?.replace(/:/g, '/');
if (!currTopicUrl) {
return;
}

const contentFilePath = topicUrlToPathMapping[currTopicUrl];

if (!contentFilePath) {
console.log(`Missing file for: ${currTopicUrl}`);
return;
}

const currentFileContent = fs.readFileSync(contentFilePath, 'utf8');
const isFileEmpty = currentFileContent.replace(/^#.+/, ``).trim() === '';

if (!isFileEmpty) {
console.log(`Ignoring ${topicId}. Not empty.`);
return;
}

let newFileContent = `# ${topicTitle}`;

if (!OPEN_AI_API_KEY) {
console.log(`Writing ${topicId}..`);

fs.writeFileSync(contentFilePath, newFileContent, 'utf8');
return;
}

const topicContent = await writeTopicContent(currTopicUrl);
newFileContent += `\n\n${topicContent}`;

console.log(`Writing ${topicId}..`);
fs.writeFileSync(contentFilePath, newFileContent, 'utf8');

// console.log(currentFileContent);
// console.log(currTopicUrl);
// console.log(topicTitle);
// console.log(topicUrlToPathMapping[currTopicUrl]);
}

async function run() {
const topicUrlToPathMapping = getFilesInFolder(ROADMAP_CONTENT_DIR);

Expand All @@ -106,50 +153,13 @@ async function run() {
console.log('----------------------------------------');
}

const writePromises = [];
for (let group of groups) {
const topicId = group?.properties?.controlName;
const topicTitle = group?.children?.controls?.control?.find(
(control) => control?.typeID === 'Label'
)?.properties?.text;
const currTopicUrl = topicId?.replace(/^\d+-/g, '/')?.replace(/:/g, '/');
if (!currTopicUrl) {
continue;
}

const contentFilePath = topicUrlToPathMapping[currTopicUrl];

if (!contentFilePath) {
console.log(`Missing file for: ${currTopicUrl}`);
return;
}

const currentFileContent = fs.readFileSync(contentFilePath, 'utf8');
const isFileEmpty = currentFileContent.replace(/^#.+/, ``).trim() === '';

if (!isFileEmpty) {
console.log(`Ignoring ${topicId}. Not empty.`);
continue;
}

let newFileContent = `# ${topicTitle}`;

if (!OPEN_AI_API_KEY) {
console.log(`Writing ${topicId}..`);
fs.writeFileSync(contentFilePath, newFileContent, 'utf8');
continue;
}

const topicContent = await writeTopicContent(currTopicUrl);
newFileContent += `\n\n${topicContent}`;

console.log(`Writing ${topicId}..`);
fs.writeFileSync(contentFilePath, newFileContent, 'utf8');

// console.log(currentFileContent);
// console.log(currTopicUrl);
// console.log(topicTitle);
// console.log(topicUrlToPathMapping[currTopicUrl]);
writePromises.push(writeFileForGroup(group, topicUrlToPathMapping));
}

console.log('Waiting for all files to be written...');
await Promise.all(writePromises);
}

run()
Expand Down
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,33 @@
"test:e2e": "playwright test"
},
"dependencies": {
"@astrojs/sitemap": "^1.2.1",
"@astrojs/preact": "^2.1.0",
"@astrojs/sitemap": "^1.2.2",
"@astrojs/tailwind": "^3.1.1",
"astro": "^2.1.9",
"@fingerprintjs/fingerprintjs": "^3.4.1",
"@nanostores/preact": "^0.3.1",
"astro": "^2.2.3",
"astro-compress": "^1.1.35",
"jose": "^4.13.2",
"js-cookie": "^3.0.1",
"nanostores": "^0.7.4",
"node-html-parser": "^6.1.5",
"npm-check-updates": "^16.9.0",
"npm-check-updates": "^16.10.8",
"preact": "^10.13.2",
"rehype-external-links": "^2.0.1",
"roadmap-renderer": "^1.0.4",
"roadmap-renderer": "^1.0.5",
"tailwindcss": "^3.3.1"
},
"devDependencies": {
"@playwright/test": "^1.32.1",
"@playwright/test": "^1.32.3",
"@tailwindcss/typography": "^0.5.9",
"@types/js-cookie": "^3.0.3",
"gh-pages": "^5.0.0",
"js-yaml": "^4.1.0",
"markdown-it": "^13.0.1",
"openai": "^3.2.1",
"prettier": "^2.8.7",
"prettier-plugin-astro": "^0.8.0",
"prettier-plugin-tailwindcss": "^0.2.6"
"prettier-plugin-tailwindcss": "^0.2.7"
}
}
Loading

0 comments on commit 1114561

Please sign in to comment.