From 2e5ef4391a912b1237bcedde47480d42dc6d9bc1 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Sat, 8 Oct 2022 09:19:40 -0500 Subject: [PATCH] Made page gathering dynamic, added favicon, included css, worked on some content, created first bash page. Still very much in-progress but the framework is pretty much done. Needs more CSS and content. --- main.js | 104 ++++++++++++++++++------------ pages/about.php | 24 +++++++ pages/helpers/advisory.php | 1 + pages/helpers/body_close.php | 3 +- pages/helpers/body_open.php | 9 ++- pages/helpers/footer.php | 9 ++- pages/helpers/head.php | 1 - pages/helpers/header.php | 15 ++++- pages/{ => helpers}/main.css | 15 +++++ pages/helpers/menu.php | 3 +- pages/helpers/section_close.php | 1 + pages/helpers/section_open.php | 1 + pages/subpages/about/notice.php | 1 + pages/subpages/about/stance.php | 1 + pages/subpages/about/whoami.php | 1 + pages/subpages/home/apps.php | 1 + pages/subpages/home/contact.php | 1 + pages/subpages/home/health.php | 5 +- pages/subpages/support/donate.php | 3 +- pages/subpages/support/gifts.php | 3 +- pages/support.php | 4 +- pages/test.sh | 31 +++++++++ run.sh | 16 ++++- test.html | 27 -------- 24 files changed, 190 insertions(+), 90 deletions(-) mode change 100644 => 100755 pages/about.php create mode 100755 pages/helpers/advisory.php mode change 100644 => 100755 pages/helpers/body_close.php mode change 100644 => 100755 pages/helpers/body_open.php mode change 100644 => 100755 pages/helpers/footer.php delete mode 100644 pages/helpers/head.php mode change 100644 => 100755 pages/helpers/header.php rename pages/{ => helpers}/main.css (80%) mode change 100644 => 100755 pages/helpers/menu.php mode change 100644 => 100755 pages/helpers/section_close.php mode change 100644 => 100755 pages/helpers/section_open.php mode change 100644 => 100755 pages/subpages/about/notice.php mode change 100644 => 100755 pages/subpages/about/stance.php mode change 100644 => 100755 pages/subpages/about/whoami.php mode change 100644 => 100755 pages/subpages/home/apps.php mode change 100644 => 100755 pages/subpages/home/contact.php mode change 100644 => 100755 pages/subpages/home/health.php mode change 100644 => 100755 pages/subpages/support/donate.php mode change 100644 => 100755 pages/subpages/support/gifts.php mode change 100644 => 100755 pages/support.php create mode 100755 pages/test.sh delete mode 100644 test.html diff --git a/main.js b/main.js index 812be30..8793957 100755 --- a/main.js +++ b/main.js @@ -1,76 +1,98 @@ #!/usr/bin/node 'use strict'; - /* -2022-09-14 Mockup of what a web server may look like. -Should serve very quick since it's all from scratch, nothing to load like WordPress. -May even skip out on things like + 2022-09-14 Hyperling + Coding my own website rather than using WordPress or anything bloaty. */ -const app_name = "www.example.com"; +//// Libraries //// + let express = require('express'); let app = express(); const execSync = require('child_process').execSync; -let pages = {}; -pages.home = require('./pages/home.js'); -//pages.notice = require('./pages/notice.js'); +const fs = require('fs'); -let pages_php = {}; -pages.home = './pages/home.php'; -//pages.notice = './pages/notice.php'; +//// Global Variables //// -// Even better, look through ./pages/ for *.php or *.js and add them to the array! +const DEBUG = false; + +const app_name = "hyperling.com"; + +let pages = []; +const pages_dir = "./pages/"; +const file_types = ["php", "sh"]; let ports = []; ports.push(8080); -async function main() { - console.log("Starting Main"); +//// Functions //// +async function main() { + console.log("...Starting Main..."); + + console.log("Set app to return HTML documents."); app.use(function (req, res, next) { res.contentType('text/html'); next(); }); - console.log("Adding Routes"); + /* Loop through all file in the pages subdirectory and add the allowed + // file types into the pages array for automatic router creation. + */ + console.log("...Starting Main..."); + let ls = await fs.promises.readdir(pages_dir); + if (DEBUG) console.log("DEBUG: Results of ls, ", ls); + for (let file of ls) { + let file_test = file.split("."); + let file_name = file_test[0]; + let file_type = file_test[file_test.length - 1]; + if (file_types.includes(file_type)) { + if (DEBUG) console.log("DEBUG: Hooray!", file, "is being added."); + pages[file_name] = pages_dir + file; + console.log(" * Added page", file); + } else { + if (DEBUG) console.log("DEBUG: ", file, "is not an approved type, skipping."); + } + } + console.log(" * Pages loaded: ", pages); + //return; // Stop execution FORTESTING + + console.log("...Adding Routes..."); let router = express.Router(); -/* MANUAL METHOD, SPECIFY EVERY PATH+FILE - router.get('/', function (req, res) { - console.log("Fetching"); - require('lib/home.js'); // one way, maybe? - }); - router.get('/notice', function (req, res) { - pages.notice(req, res); // another way? - }); -*/ -/* AUTOMATIC METHOD BASED ON OBJECT/ARRAY - for page in pages { // FORTESTING pseudocode - router.get("/" + page.key, function (req,res) { - page.value(req, res); + + /* AUTOMATIC METHOD BASED ON OBJECT/ARRAY OF PHP scripts + // Creates routes with the URL of the key and location of the value. + */ + for (let key in pages) { + console.log(" * Creating router for", key); + router.get("/" + key, function (req,res) { + console.log(key, "fulfilling request to", req.socket.remoteAddress, "asking for", req.url) + res.send(execSync(pages[key])); }); } -*/ -/* AUTOMATIC METHOD BASED ON OBJECT/ARRAY OF PHP scripts - for page in pages { // FORTESTING pseudocode - router.get("/" + page.key, function (req,res) { - res.send(system("php page.value")); - }); - } -*/ - // Test (Also a decent catch-all to Home!) + + // Provide css. + router.get('/main.css', function (req, res) { + console.log("css being provided to", req.socket.remoteAddress) + let html = execSync("cat ./pages/main.css"); + res.send(html); + }); + + // Originally a test, now a catch-all redirection to Home! router.get('/*', function (req, res) { + // WARNING: These are huge so only look when you need to. //console.log(req); //console.log(res); - console.log(req.socket.remoteAddress, "asked for", req.url) - let html = execSync("php ./pages/home.php"); + console.log("*wildcard* replying to", req.socket.remoteAddress, "asking for", req.url) + let html = execSync("./pages/home.php"); res.send(html); }); app.use('', router); - console.log("Adding Ports"); + console.log("...Adding Ports..."); ports.forEach(port => { app.listen(port); console.log(" * Now listening on port " + port + "."); @@ -78,4 +100,6 @@ async function main() { console.log("Done! Now we wait..."); } +//// Program Execution //// + main(); diff --git a/pages/about.php b/pages/about.php old mode 100644 new mode 100755 index 8471a42..2e4c7d7 --- a/pages/about.php +++ b/pages/about.php @@ -1,2 +1,26 @@ #!/usr/bin/php + + +

Curious About Me?

+

+ TBD +

+ + diff --git a/pages/helpers/advisory.php b/pages/helpers/advisory.php new file mode 100755 index 0000000..ed3f2eb --- /dev/null +++ b/pages/helpers/advisory.php @@ -0,0 +1 @@ +#!/usr/bin/php diff --git a/pages/helpers/body_close.php b/pages/helpers/body_close.php old mode 100644 new mode 100755 index 26293f9..d88d9ce --- a/pages/helpers/body_close.php +++ b/pages/helpers/body_close.php @@ -1,5 +1,4 @@ - - +#!/usr/bin/php diff --git a/pages/helpers/body_open.php b/pages/helpers/body_open.php old mode 100644 new mode 100755 index 3313b5e..ef6b335 --- a/pages/helpers/body_open.php +++ b/pages/helpers/body_open.php @@ -1,12 +1,11 @@ - - +#!/usr/bin/php - diff --git a/pages/helpers/footer.php b/pages/helpers/footer.php old mode 100644 new mode 100755 index b662d86..fd45d7c --- a/pages/helpers/footer.php +++ b/pages/helpers/footer.php @@ -1,3 +1,6 @@ - -
Copyright $year
- +#!/usr/bin/php +
+ + Copyright + +
diff --git a/pages/helpers/head.php b/pages/helpers/head.php deleted file mode 100644 index 4648beb..0000000 --- a/pages/helpers/head.php +++ /dev/null @@ -1 +0,0 @@ -DELETEME diff --git a/pages/helpers/header.php b/pages/helpers/header.php old mode 100644 new mode 100755 index d7fcafc..51e12eb --- a/pages/helpers/header.php +++ b/pages/helpers/header.php @@ -1,7 +1,16 @@ - - +#!/usr/bin/php + Hyperling + + + + - diff --git a/pages/main.css b/pages/helpers/main.css similarity index 80% rename from pages/main.css rename to pages/helpers/main.css index e09edfd..f7c822e 100644 --- a/pages/main.css +++ b/pages/helpers/main.css @@ -40,3 +40,18 @@ clear: both; display: table; } + +/* MyStuff ***/ +/** Dark Theme **/ +body { + background-color: #333333; +} +* { + color: #CCCCCC; +} +a { + color: #FF9900 +} +h1,h2,h3,h4,h5,h6 { + color: #6633FF +} \ No newline at end of file diff --git a/pages/helpers/menu.php b/pages/helpers/menu.php old mode 100644 new mode 100755 index 8c9242b..599a575 --- a/pages/helpers/menu.php +++ b/pages/helpers/menu.php @@ -1,5 +1,4 @@ - - +#!/usr/bin/php