diff --git a/Cargo.lock b/Cargo.lock
index 07b6439..fef4d2e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -99,6 +99,7 @@ dependencies = [
name = "banii-cafe"
version = "0.1.0"
dependencies = [
+ "rand",
"rocket",
]
diff --git a/Cargo.toml b/Cargo.toml
index ecf64b0..32f1838 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,4 +4,5 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-rocket = "0.5.0"
\ No newline at end of file
+rand = "0.8.5"
+rocket = "0.5.0"
diff --git a/src/htmlgenerator.rs b/src/htmlgenerator.rs
new file mode 100644
index 0000000..cd719a4
--- /dev/null
+++ b/src/htmlgenerator.rs
@@ -0,0 +1,3 @@
+pub mod blocks;
+pub mod builder;
+pub mod errors;
\ No newline at end of file
diff --git a/src/htmlgenerator/blocks.rs b/src/htmlgenerator/blocks.rs
new file mode 100644
index 0000000..e268b98
--- /dev/null
+++ b/src/htmlgenerator/blocks.rs
@@ -0,0 +1,105 @@
+use std::{ffi::OsString, fs};
+pub fn gen_head(charset: &str, author: &str, title: &str, stylesheet: &str) -> String {
+ String::from(format!(r#"
+
+
+
+
+ {}
+
+
+"#, charset, author, title, stylesheet))}
+
+pub fn gen_header(site_name: &str, quote: String) -> String {
+ let blinkie_string = gen_imgs("blinkies");
+ String::from(format!(r#"
+
+"#, site_name, quote, blinkie_string, blinkie_string))}
+
+pub fn gen_main(nav: String, content: String) -> String {
+ String::from(format!(r#"
+
+ {}
+ {}
+
+"#, nav, content))
+}
+
+pub fn gen_footer() -> String {
+ let banners_string = gen_imgs("banners");
+ String::from(format!(r#"
+
+"#, banners_string, banners_string))}
+
+pub fn gen_nav(links_map: Vec<(&str, &str)>) -> String{
+ let mut links:String = String::from("");
+ for (url, label) in links_map.into_iter() {
+ let mut newtab = "";
+ if url.chars().nth(0).unwrap() != '/' {
+ newtab = "target='_blank'"
+ }
+ let link_tag = format!("{}", newtab ,url, label);
+ links = format!("{links}{link_tag}");
+ }
+
+ String::from(format!(r#"
+
+"#, links))}
+
+// use for when no content for main availiable
+pub fn gen_placeholder() -> String{
+ String::from(format!(r#"
+
+
+
!under construction!
+
+
+"#))}
+
+fn gen_imgs(images: &str) -> String {
+ let paths = fs::read_dir(format!("./static/img/{images}/")).unwrap();
+ let mut imgs:String = String::from("");
+
+ for path in paths {
+ let file_name = OsString::from(path.unwrap().file_name());
+ let img_tag = format!("
", file_name.to_str().unwrap());
+ imgs = format!("{imgs}{img_tag}");
+ }
+
+ return imgs;
+}
+
+//content
+pub fn home_content() -> String {
+ String::from(format!(r#"
+
+
+
welcome!
+
hiii!!! welcome to my site, feel free to look around and learn something your government doesn't want you to :3
+
+
+
+"#, gen_imgs("stamps")))}
\ No newline at end of file
diff --git a/src/htmlgenerator/builder.rs b/src/htmlgenerator/builder.rs
new file mode 100644
index 0000000..0fe5554
--- /dev/null
+++ b/src/htmlgenerator/builder.rs
@@ -0,0 +1,11 @@
+pub fn build_page(head: String, header: String, main: String, footer: String) -> String {format!(r#"
+
+
+ {}
+
+ {}
+ {}
+ {}
+
+
+"#, head, header, main, footer)}
\ No newline at end of file
diff --git a/src/htmlgenerator/errors.rs b/src/htmlgenerator/errors.rs
new file mode 100644
index 0000000..1f8c767
--- /dev/null
+++ b/src/htmlgenerator/errors.rs
@@ -0,0 +1,22 @@
+use rocket::response::content::RawHtml;
+use rocket::Request;
+use rocket::http::Status;
+
+use crate::*;
+
+#[catch(default)]
+pub fn default(status: Status, req: &Request)-> RawHtml{
+ RawHtml(crate::htmlgenerator::builder::build_page(
+ gen_head("UTF-8", "genki_angel", "banii.cafe", "base"),
+ gen_header("BANII.CAFE", "uh-oh, something has gone wrong!".to_string()),
+ gen_main(gen_nav(get_links()), String::from(format!(r#"
+
+
+

+
{}
+
+
+ "#, status.code, req.uri()))),
+ gen_footer()
+ ))
+}
\ No newline at end of file
diff --git a/src/index_builder.rs b/src/index_builder.rs
deleted file mode 100644
index a3d061d..0000000
--- a/src/index_builder.rs
+++ /dev/null
@@ -1,130 +0,0 @@
-use std::ffi::OsString;
-use std::fs;
-
-pub fn build_index() -> String {format!(r#"
-
-
- {}
-
- {}
- {}
- {}
-
-
-"#, gen_head(), gen_header(), gen_main(), gen_footer())}
-
-fn gen_head() -> String {String::from(format!(r#"
-
-
-
-
- banii.cafe
-
-
-"#))}
-
-fn gen_header() -> String {
- let blinkie_string = gen_img("blinkies");
- String::from(format!(r#"
-
-"#, "BANII.CAFE", "Site under construction...", blinkie_string, blinkie_string))}
-
-fn gen_main() -> String {String::from(format!(r#"
-
-
-
-
-
-
$$ most wanted $$
-
-
-

-
-
-
-
- name: |
- genki_angel |
-
-
- height: |
- mouse-sized |
-
-
- gender: |
- dangerous |
-
-
- wanted for: |
- being too silly |
-
-
- last seen: |
- in your walls |
-
-
-
-
-
- !INFO: likes to smell plants and look at funny animals...
can be found eating plastic from your bins and drinking kerosene at your nearest airport
-
-
-
- !CAUTION: will bark very loud if approached
-
-
-
- !REWARD!
second-hand Hwasong-18 ICBM
[fuel not included]
-
-
-
-
-
-
-
-
-"#,"./img/genki.gif", gen_img("stamps")))}
-
-fn gen_footer() -> String {
- let banners_string = gen_img("banners");
- String::from(format!(r#"
-
-"#, banners_string, banners_string))}
-
-fn gen_img(images: &str) -> String {
- let paths = fs::read_dir(format!("./static/img/{images}/")).unwrap();
- let mut imgs:String = String::from("");
-
- for path in paths {
- let file_name = OsString::from(path.unwrap().file_name());
- let img_tag = format!("
", file_name.to_str().unwrap());
- imgs = format!("{imgs}{img_tag}");
- }
-
- return imgs;
-}
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 90fc451..3e44d58 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,21 +1,48 @@
-use index_builder::build_index;
+use htmlgenerator::errors::*;
+use htmlgenerator::blocks::*;
+use randomquote::get_quote;
use rocket::fs::FileServer;
use rocket::response::content::RawHtml;
-mod index_builder;
-
+mod htmlgenerator;
+mod randomquote;
#[macro_use] extern crate rocket;
+//TODO replace with file/env configuration
+fn get_links() -> Vec<(&'static str, &'static str)>{
+ Vec::from([
+ ("/", "/home"),
+ ("/gallery", "/gallery"),
+ ("https://git.banii.cafe", "/repos"),
+ ("https://github.com/genki-angel", ">github")
+ ])
+}
+
#[get("/")]
fn index() -> RawHtml {
- RawHtml(build_index())
-
+ RawHtml(htmlgenerator::builder::build_page(
+ gen_head("UTF-8", "genki_angel", "banii.cafe", "base"),
+ gen_header("BANII.CAFE", get_quote()),
+ gen_main(gen_nav(get_links()), home_content()),
+ gen_footer()
+ ))
+}
+
+#[get("/gallery")]
+fn gallery()-> RawHtml {
+ RawHtml(htmlgenerator::builder::build_page(
+ gen_head("UTF-8", "genki_angel", "banii.cafe", "base"),
+ gen_header("BANII.CAFE", "under construction!".to_string()),
+ gen_main(gen_nav(get_links()), gen_placeholder()),
+ gen_footer()
+ ))
}
#[launch]
fn rocket() -> _ {
rocket::build()
- .mount("/", routes![index])
+ .register("/", catchers![default])
+ .mount("/", routes![index, gallery])
.mount("/", FileServer::from("./static"))
}
diff --git a/src/randomquote.rs b/src/randomquote.rs
new file mode 100644
index 0000000..eb51258
--- /dev/null
+++ b/src/randomquote.rs
@@ -0,0 +1,15 @@
+use rand::seq::SliceRandom;
+
+pub fn get_quote() -> String{
+ let quotes = Vec::from([
+ "random quote here",
+ "made with rust!",
+ "don't trust anyone that calls me a furry",
+ "haters welcome!",
+ "no bunnies were harmed in the making of this site",
+ "check out my repos and github!",
+ "remember to be nice :3",
+ ":3 :3 :3 :3 :3 :3 :3 :3 :3 :3 :3 :3 :3 :3 :3"
+ ]);
+ quotes.choose(&mut rand::thread_rng()).unwrap().to_string()
+}
\ No newline at end of file