From 79f3b5909ee28e3e80bc715c31c8e481b6473cbb Mon Sep 17 00:00:00 2001 From: Josiah Bradbury Date: Fri, 10 May 2019 20:42:38 -0500 Subject: [PATCH] Repo list now pulls from a JSON list like Blogs --- README.md | 7 ++++++- assets/index.html | 19 ++++++++++++++++++ build.js | 51 ++++++++++++++++++++++++++++------------------- repos.js | 45 +++++++++++++++++++++++++++++++++++++++++ repos/repos.json | 0 5 files changed, 101 insertions(+), 21 deletions(-) create mode 100644 repos.js create mode 100644 repos/repos.json diff --git a/README.md b/README.md index bea55af..1f93104 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,18 @@ You could also add in your custom CSS inside `index.css` to give it a more perso ### Let's Publish -You can host your website using github pages and use a custom domain aswell or simply use `username.github.io`. +You can host your website using github pages and use a custom domain as well or simply use `username.github.io`. ### Updating To update your info, follow the same steps shown in `Let's build` part +The repo list can be updated independently with the following command: + +``` +$ node repos --name username +``` ### Add a Blog diff --git a/assets/index.html b/assets/index.html index 929185e..5e1dcbf 100644 --- a/assets/index.html +++ b/assets/index.html @@ -62,6 +62,25 @@ `) } }); + $.getJSON("repos.json", function(repos){ + for(var i = 0; i < repos.length; i++){ + $("#projects").append(` + +
+
${repos[i].name}
+
+ ${repos[i].description} +
+
+   ${repos[i].language} +   ${repos[i].stargazers_count} +   ${repos[i].forks_count} +
+
+
+ `) + } + }); \ No newline at end of file diff --git a/build.js b/build.js index ad4b281..72ade69 100644 --- a/build.js +++ b/build.js @@ -76,26 +76,7 @@ jsdom.fromFile("./assets/index.html", options).then(function (dom) { (async () => { try { console.log("Building HTML/CSS..."); - var repos = await got(`https://api.github.com/users/${username}/repos?sort=created`); - repos = JSON.parse(repos.body); - for(var i = 0;i < repos.length;i++){ - if(repos[i].fork == false){ - document.getElementById("projects").innerHTML += ` - -
-
${repos[i].name}
-
- ${convertToEmoji(repos[i].description)} -
-
-   ${repos[i].language} -   ${repos[i].stargazers_count} -   ${repos[i].forks_count} -
-
-
`; - } - } + var user = await got(`https://api.github.com/users/${username}`); user = JSON.parse(user.body); document.title = user.login; @@ -155,8 +136,38 @@ jsdom.fromFile("./blog/blog_template.html", options).then(function (dom) { }); } +function populateRepos(username){ + var repoData = []; + (async () => { + try { + var repos = await got(`https://api.github.com/users/${username}/repos?sort=created`); + repos = JSON.parse(repos.body); + for(var i = 0;i < repos.length;i++){ + if(repos[i].fork == false){ + repoData.push({ + "html_url": repos[i].html_url, + "name": repos[i].name, + "description": repos[i].description, + "language": repos[i].language, + "stargazers_count": repos[i].stargazers_count, + "forks_count" :repos[i].forks_count + }); + } + + } + fs.writeFile('./repos/repos.json', JSON.stringify(repoData), function(err){ + if (err) throw err; + console.log('Repos Created Successfully in root folder.'); + }); + } catch (error) { + console.log(error); + } +})(); +} + if (program.name) { populateHTML(('%s', program.name)); + populateRepos(('%s', program.name)); } else { console.log("Provide a username"); } \ No newline at end of file diff --git a/repos.js b/repos.js new file mode 100644 index 0000000..8049ede --- /dev/null +++ b/repos.js @@ -0,0 +1,45 @@ +const program = require('commander'); +const fs = require('fs'); +const got = require('got'); +options = { + resources: "usable" +}; + +program + .version('0.1.0') + .option('-n, --name [username]', 'get username') + .parse(process.argv); + +function populateRepos(username){ + var repoData = []; + (async () => { + try { + var repos = await got(`https://api.github.com/users/${username}/repos?sort=created`); + repos = JSON.parse(repos.body); + for(var i = 0;i < repos.length;i++){ + if(repos[i].fork == false){ + repoData.push({ + "html_url": repos[i].html_url, + "name": repos[i].name, + "description": repos[i].description, + "language": repos[i].language, + "stargazers_count": repos[i].stargazers_count, + "forks_count" :repos[i].forks_count + }); + } + + } + fs.writeFile('repos.json', JSON.stringify(repoData), function(err){ + if (err) throw err; + console.log('Repos Created Successfully in root folder.'); + }); + } catch (error) { + console.log(error); + } +})(); +} +if (program.name) { + populateRepos(('%s', program.name)); +} else { + console.log("provide a name to scrape repos"); +} \ No newline at end of file diff --git a/repos/repos.json b/repos/repos.json new file mode 100644 index 0000000..e69de29