axum init
This commit is contained in:
parent
3587f20a39
commit
367384dc2c
9 changed files with 0 additions and 1756 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
/target
|
||||
/static
|
1542
Cargo.lock
generated
1542
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,8 +0,0 @@
|
|||
[package]
|
||||
name = "banii-cafe"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
rocket = "0.5.0"
|
|
@ -1,3 +0,0 @@
|
|||
pub mod blocks;
|
||||
pub mod builder;
|
||||
pub mod errors;
|
|
@ -1,105 +0,0 @@
|
|||
use std::{ffi::OsString, fs};
|
||||
pub fn gen_head(charset: &str, author: &str, title: &str, stylesheet: &str) -> String {
|
||||
String::from(format!(r#"
|
||||
<head>
|
||||
<meta charset="{}" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="author" content="{}">
|
||||
<title>{}</title>
|
||||
<link rel="stylesheet" href="./styles/{}.css">
|
||||
</head>
|
||||
"#, charset, author, title, stylesheet))}
|
||||
|
||||
pub fn gen_header(site_name: &str, quote: String) -> String {
|
||||
let blinkie_string = gen_imgs("blinkies");
|
||||
String::from(format!(r#"
|
||||
<header>
|
||||
<div class="header-greet">welcome to...</div>
|
||||
<h1>{}</h1>
|
||||
<div id="header-quotebox" class="window">
|
||||
<div class="billboard">{}</div>
|
||||
</div>
|
||||
<div id="blinkiebox">
|
||||
<div class="marquee"><div class="blinkies">{}</div><div class="blinkies">{}</div></div>
|
||||
</div>
|
||||
</header>
|
||||
"#, site_name, quote, blinkie_string, blinkie_string))}
|
||||
|
||||
pub fn gen_main(nav: String, content: String) -> String {
|
||||
String::from(format!(r#"
|
||||
<main>
|
||||
{}
|
||||
{}
|
||||
</main>
|
||||
"#, nav, content))
|
||||
}
|
||||
|
||||
pub fn gen_footer() -> String {
|
||||
let banners_string = gen_imgs("banners");
|
||||
String::from(format!(r#"
|
||||
<footer>
|
||||
<div id="bannerbox">
|
||||
<div class="marquee"><div class="banners">{}</div><div class="banners">{}</div></div>
|
||||
</div>
|
||||
</footer>
|
||||
"#, 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!("<li><a class='navlink' {} href='{}'>{}</a></li>", newtab ,url, label);
|
||||
links = format!("{links}{link_tag}");
|
||||
}
|
||||
|
||||
String::from(format!(r#"
|
||||
<nav class="window">
|
||||
<h2 style="color: rgb(222,222,108);">travel to...</h2>
|
||||
<ul>
|
||||
{}
|
||||
</ul>
|
||||
</nav>
|
||||
"#, links))}
|
||||
|
||||
// use for when no content for main availiable
|
||||
pub fn gen_placeholder() -> String{
|
||||
String::from(format!(r#"
|
||||
<article>
|
||||
<div class="window">
|
||||
<h2>!under construction!</h2>
|
||||
</div>
|
||||
</article>
|
||||
"#))}
|
||||
|
||||
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!("<img src='./img/{images}/{}'>", file_name.to_str().unwrap());
|
||||
imgs = format!("{imgs}{img_tag}");
|
||||
}
|
||||
|
||||
return imgs;
|
||||
}
|
||||
|
||||
//content
|
||||
pub fn home_content() -> String {
|
||||
String::from(format!(r#"
|
||||
<article>
|
||||
<div class="window">
|
||||
<h2 style="color: rgb(222,222,108);">welcome!</h2>
|
||||
<p>hiii!!! welcome to my site, feel free to look around and learn something your government doesn't want you to :3</p>
|
||||
</div>
|
||||
<div class="window" style="max-width: 400px;">
|
||||
<h2>stampbook</h2>
|
||||
<div class="stamps">
|
||||
{}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
"#, gen_imgs("stamps")))}
|
|
@ -1,11 +0,0 @@
|
|||
pub fn build_page(head: String, header: String, main: String, footer: String) -> String {format!(r#"
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
{}
|
||||
<body>
|
||||
{}
|
||||
{}
|
||||
{}
|
||||
</body>
|
||||
</html>
|
||||
"#, head, header, main, footer)}
|
|
@ -1,22 +0,0 @@
|
|||
use rocket::response::content::RawHtml;
|
||||
use rocket::Request;
|
||||
use rocket::http::Status;
|
||||
|
||||
use crate::*;
|
||||
|
||||
#[catch(default)]
|
||||
pub fn default(status: Status, req: &Request)-> RawHtml<String>{
|
||||
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#"
|
||||
<article>
|
||||
<div class="window">
|
||||
<img src="https://http.cat/{}"/>
|
||||
<p>{}</p>
|
||||
</div>
|
||||
</article>
|
||||
"#, status.code, req.uri()))),
|
||||
gen_footer()
|
||||
))
|
||||
}
|
48
src/main.rs
48
src/main.rs
|
@ -1,48 +0,0 @@
|
|||
use htmlgenerator::errors::*;
|
||||
use htmlgenerator::blocks::*;
|
||||
use randomquote::get_quote;
|
||||
use rocket::fs::FileServer;
|
||||
use rocket::response::content::RawHtml;
|
||||
|
||||
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<String> {
|
||||
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<String> {
|
||||
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()
|
||||
.register("/", catchers![default])
|
||||
.mount("/", routes![index, gallery])
|
||||
.mount("/", FileServer::from("./static"))
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
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()
|
||||
}
|
Loading…
Reference in a new issue