-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add /home with home/index.html for nelsonic/nelsonic.github.io#511
- Loading branch information
Showing
5 changed files
with
868 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
var fs = require('fs'); | ||
var http_request = require('./http_request'); | ||
var cheerio = require('cheerio'); | ||
|
||
// Adding Colors to Terminal *Without* a Library/Module | ||
var bgRedBlack = '\x1b[41m\x1b[30m'; | ||
var bgGreenBlack = '\x1b[42m\x1b[30m'; | ||
var RESET = '\x1b[0m'; // see: https://stackoverflow.com/a/41407246/1148249 | ||
var URL = 'https://github.com/nelsonic/home/blob/master/README.md'; | ||
|
||
http_request(URL, function (status, html) { | ||
if (status !== 200 || !html) { | ||
console.log(bgRedBlack, | ||
" - - - GitHub Scraper FAIL >> " + URL + " - - - ", RESET); | ||
process.exit(); | ||
} | ||
else { | ||
var $ = cheerio.load(html); | ||
var body = $('#readme').html() | ||
var css = fs.readFileSync('./style.css', 'utf8'); | ||
var template = fs.readFileSync('./template.html', 'utf8'); | ||
var out = template.replace('{css}', css).replace('{content}', body); | ||
fs.writeFileSync('./index.html', out, 'utf8'); | ||
console.log(bgGreenBlack, 'done.', RESET); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
var http = require('https'); // ALWAYS use TLS over the internets! | ||
var bgRedBlack = '\x1b[41m\x1b[30m'; | ||
var RESET = '\x1b[0m'; // see: https://stackoverflow.com/a/41407246/1148249 | ||
/** | ||
* simple_http_request is a bare-bones http request using node.js core http | ||
* see: https://nodejs.org/api/http.html#http_http_request_options_callback | ||
* the NPM request module is 3.6 Megabytes and offers v. little benefit ... | ||
* This code achieves the same in less than 1kb. less code = faster response. | ||
* @param {Object} path - the path (on GitHub) we want to "view" | ||
* @param {Function} callback - a standard callback with error & response args | ||
* response is a JSON Object unless there is an error. | ||
*/ | ||
|
||
module.exports = function simple_http_request (path, callback) { | ||
|
||
var options = { | ||
headers: { | ||
'Accept': 'text/html', | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36' | ||
}, | ||
hostname: 'github.com', | ||
port: '443', | ||
path: path | ||
} | ||
|
||
http.request(options, function (res) { | ||
var resStr = ''; | ||
var response; | ||
// console.log(res.statusCode); | ||
if (res.statusCode !== 200) { | ||
console.log(bgRedBlack, ' GOT ', res.statusCode, ' for ', options, RESET); | ||
return callback(res.statusCode); | ||
} | ||
|
||
res.setEncoding('utf8'); | ||
res.on('data', function (chunk) { | ||
// console.log(chunk); | ||
resStr += chunk; | ||
}).on('end', function () { | ||
return callback(res.statusCode, resStr); // return response as HTML! | ||
}); | ||
|
||
return true; | ||
}).end(); | ||
|
||
}; |
Oops, something went wrong.