From 4e67a31cdc0ae187e85015a4f5a4fc3418641de4 Mon Sep 17 00:00:00 2001 From: buckn Date: Wed, 15 Feb 2023 15:57:49 -0500 Subject: [PATCH] init --- .gitignore | 4 +++ .gitmodules | 3 ++ Cargo.toml | 11 +++++++ contact/index.html | 32 ++++++++++++++++++ index/index.html | 34 +++++++++++++++++++ index/main.js | 27 ++++++++++++++++ resume | 1 + src/main.rs | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 193 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 Cargo.toml create mode 100644 contact/index.html create mode 100644 index/index.html create mode 100644 index/main.js create mode 160000 resume create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3765cea --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +debug/ +target/ +Cargo.lock +**/*.rs.bk diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..edd7397 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "resume"] + path = resume + url = http://208.167.242.150:3000/buckn/resume diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2878eb2 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "buckn_dev" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +actix-files = "0.6.2" +actix-web = "4.3.0" +structopt = "0.3.26" diff --git a/contact/index.html b/contact/index.html new file mode 100644 index 0000000..a407ae8 --- /dev/null +++ b/contact/index.html @@ -0,0 +1,32 @@ + + + + + + + Nathan Buck's Site + + +
+
+
+
+

+
+

Contact Info:

+
+
+
+

+
+
+
+

Email: public@buckn.dev

+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/index/index.html b/index/index.html new file mode 100644 index 0000000..b18215e --- /dev/null +++ b/index/index.html @@ -0,0 +1,34 @@ + + + + + + + Nathan Buck's Site + + +
+
+
+
+

+
+

Hi, I'm Nathan

+
+
+
+

+
+
+
+

This is my personal site

+

Here you can find my git, resume, and contact info

+

I'll be adding more to this site as I work on music, programming projects and more!

+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/index/main.js b/index/main.js new file mode 100644 index 0000000..8e45d70 --- /dev/null +++ b/index/main.js @@ -0,0 +1,27 @@ +let url; + +if (window.location.hostname.substring(0, 3) == "www") { + url = window.location.hostname.substring(4, window.location.hostname.length); +} else { + url = window.location.hostname; +} + +let navbar = ` + +`; + +document.querySelector("body").insertAdjacentHTML("afterbegin", navbar) \ No newline at end of file diff --git a/resume b/resume new file mode 160000 index 0000000..039b435 --- /dev/null +++ b/resume @@ -0,0 +1 @@ +Subproject commit 039b4356d057994938e3a24e8ad86f9611fe9d36 diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..b0e273e --- /dev/null +++ b/src/main.rs @@ -0,0 +1,81 @@ +use std::path::PathBuf; +use std::fs::*; +use std::io::prelude::*; + +use structopt::StructOpt; + +use actix_web::{get, web, App, HttpServer, HttpResponse, Responder, Result, HttpRequest}; + +use actix_files; +use actix_files::*; + +#[derive(StructOpt, Debug)] +#[structopt(name = "personal site server")] +struct Opt { + #[structopt(short, long)] + address: String, + #[structopt(short, long)] + port: u16, +} + +fn inject_js(html: &mut String) { + let body_location; + match html.find("") { + Some(val) => body_location = val, + None => { eprintln!("this html string failed to inject the js string: {:?}", html); return; }, + } + html.insert_str(body_location - 1 as usize, r#""#); +} + +#[get("/")] +async fn index() -> impl Responder { + let mut file = File::open("index/index.html").unwrap(); + let mut html = String::new(); + file.read_to_string(&mut html).unwrap(); + inject_js(&mut html); + HttpResponse::Ok().body(html) +} + +#[get("/resume")] +async fn resume() -> impl Responder { + let mut file = File::open("resume/index.html").unwrap(); + let mut html = String::new(); + file.read_to_string(&mut html).unwrap(); + inject_js(&mut html); + HttpResponse::Ok().body(html) +} + +#[get("/contact")] +async fn contact() -> impl Responder { + let mut file = File::open("contact/index.html").unwrap(); + let mut html = String::new(); + file.read_to_string(&mut html).unwrap(); + inject_js(&mut html); + HttpResponse::Ok().body(html) +} + +#[get("/main.js")] +async fn js() -> impl Responder { + let mut file = File::open("index/main.js").unwrap(); + let mut js = String::new(); + file.read_to_string(&mut js).unwrap(); + HttpResponse::Ok().body(js) +} + +#[actix_web::main] // or #[tokio::main] +async fn main() -> std::io::Result<()> { + use actix_web::{web, App, HttpServer}; + + let opt = Opt::from_args(); + + HttpServer::new(|| { + App::new() + .service(index) + .service(js) + .service(resume) + .service(contact) + }) + .bind((opt.address, opt.port))? + .run() + .await +} \ No newline at end of file