mirror of
https://github.com/RGBCube/rgbcube.github.io
synced 2025-05-15 06:24:58 +00:00
Make warp work
This commit is contained in:
parent
9434ff9e8d
commit
dc82b04345
7 changed files with 41 additions and 42 deletions
|
@ -1,7 +1,7 @@
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Bai Jamjuree";
|
font-family: "Bai Jamjuree";
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
src: url("assets/BaiJamjuree700.woff2") format("woff2");
|
src: url("/assets/BaiJamjuree700.woff2") format("woff2");
|
||||||
}
|
}
|
||||||
|
|
||||||
body,
|
body,
|
||||||
|
|
|
@ -9,6 +9,8 @@ mod routes;
|
||||||
use constants::*;
|
use constants::*;
|
||||||
use env_logger::Target;
|
use env_logger::Target;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
|
use routes::*;
|
||||||
|
use warp::Filter;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
@ -17,7 +19,9 @@ async fn main() -> anyhow::Result<()> {
|
||||||
.target(Target::Stdout)
|
.target(Target::Stdout)
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
warp::serve(routes::filter()).run(([0, 0, 0, 0], 80)).await;
|
let routes = index::filter().or(assets::filter()).or(_404::filter());
|
||||||
|
|
||||||
|
warp::serve(routes).run(([0, 0, 0, 0], 80)).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn create(head: Markup, body: Markup) -> Markup {
|
||||||
(pname("description", description))
|
(pname("description", description))
|
||||||
(property("og:description", description))
|
(property("og:description", description))
|
||||||
|
|
||||||
link rel="icon" href="assets/icon.gif" type="image/gif";
|
link rel="icon" href="/assets/icon.gif" type="image/gif";
|
||||||
|
|
||||||
(property("og:image", "thumbnail.png"))
|
(property("og:image", "thumbnail.png"))
|
||||||
(property("og:image:type", "image/png"))
|
(property("og:image:type", "image/png"))
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
use std::{
|
use std::{
|
||||||
array,
|
array,
|
||||||
|
convert::Infallible,
|
||||||
sync::LazyLock,
|
sync::LazyLock,
|
||||||
};
|
};
|
||||||
|
|
||||||
use maud::{
|
use maud::html;
|
||||||
html,
|
use warp::{
|
||||||
Markup,
|
reply::{
|
||||||
|
self,
|
||||||
|
Html,
|
||||||
|
},
|
||||||
|
Filter,
|
||||||
};
|
};
|
||||||
use warp::Filter;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cube,
|
cube,
|
||||||
minify,
|
minify,
|
||||||
};
|
};
|
||||||
|
|
||||||
static PAGE: LazyLock<Markup> = LazyLock::new(|| {
|
static PAGE: LazyLock<String> = LazyLock::new(|| {
|
||||||
cube::create(
|
cube::create(
|
||||||
minify::css(embed::string!("404.css")),
|
minify::css(embed::string!("404.css")),
|
||||||
array::from_fn(|_| {
|
array::from_fn(|_| {
|
||||||
|
@ -28,8 +32,9 @@ static PAGE: LazyLock<Markup> = LazyLock::new(|| {
|
||||||
.clone()
|
.clone()
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
.into_string()
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn filter() -> impl Filter {
|
pub fn filter() -> impl Filter<Extract = (Html<&'static str>,), Error = Infallible> + Clone {
|
||||||
warp::any().map(|| &*PAGE)
|
warp::any().map(|| reply::html(PAGE.as_str()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,12 @@ use std::{
|
||||||
|
|
||||||
use tar::Archive;
|
use tar::Archive;
|
||||||
use warp::{
|
use warp::{
|
||||||
filters::path::FullPath,
|
filters::fs::File,
|
||||||
|
reject::Rejection,
|
||||||
Filter,
|
Filter,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ASSETS: LazyLock<HashMap<String, Vec<u8>>> = LazyLock::new(|| {
|
static _ASSETS: LazyLock<HashMap<String, Vec<u8>>> = LazyLock::new(|| {
|
||||||
let contents = embed::bytes!("../../assets.tar");
|
let contents = embed::bytes!("../../assets.tar");
|
||||||
|
|
||||||
let mut archive = Archive::new(Cursor::new(contents.as_ref()));
|
let mut archive = Archive::new(Cursor::new(contents.as_ref()));
|
||||||
|
@ -38,16 +39,6 @@ static ASSETS: LazyLock<HashMap<String, Vec<u8>>> = LazyLock::new(|| {
|
||||||
assets
|
assets
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn filter() -> impl Filter {
|
pub fn filter() -> impl Filter<Extract = (File,), Error = Rejection> + Clone {
|
||||||
warp::path!("assets" / ..)
|
warp::path("assets").and(warp::fs::dir("assets"))
|
||||||
.and(warp::path::full())
|
|
||||||
.map(|path: FullPath| {
|
|
||||||
println!("{}", path.as_str());
|
|
||||||
|
|
||||||
if let Some(asset) = ASSETS.get(path.as_str()) {
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
warp::reject::not_found()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,33 @@
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use maud::{
|
use maud::html;
|
||||||
html,
|
use warp::{
|
||||||
Markup,
|
reject::Rejection,
|
||||||
|
reply::{
|
||||||
|
self,
|
||||||
|
Html,
|
||||||
|
},
|
||||||
|
Filter,
|
||||||
};
|
};
|
||||||
use warp::Filter;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cube,
|
cube,
|
||||||
minify,
|
minify,
|
||||||
};
|
};
|
||||||
|
|
||||||
static PAGE: LazyLock<Markup> = LazyLock::new(|| {
|
static PAGE: LazyLock<String> = LazyLock::new(|| {
|
||||||
cube::create(
|
cube::create(
|
||||||
minify::css(embed::string!("index.css")),
|
minify::css(embed::string!("index.css")),
|
||||||
[
|
[
|
||||||
html! {
|
html! {
|
||||||
a href="contact" {
|
a href="/contact" {
|
||||||
div class="frame" {
|
div class="frame" {
|
||||||
"contact"
|
"contact"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
html! {
|
html! {
|
||||||
a href="github" {
|
a href="/github" {
|
||||||
div class="frame" {
|
div class="frame" {
|
||||||
"github"
|
"github"
|
||||||
}
|
}
|
||||||
|
@ -35,8 +39,9 @@ static PAGE: LazyLock<Markup> = LazyLock::new(|| {
|
||||||
html! {},
|
html! {},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
.into_string()
|
||||||
});
|
});
|
||||||
|
|
||||||
pub fn filter() -> impl Filter {
|
pub fn filter() -> impl Filter<Extract = (Html<&'static str>,), Error = Rejection> + Clone {
|
||||||
warp::any().map(|| &*PAGE)
|
warp::path!().map(|| reply::html(PAGE.as_str()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
use warp::Filter;
|
pub mod _404;
|
||||||
|
pub mod assets;
|
||||||
mod _404;
|
pub mod index;
|
||||||
mod assets;
|
|
||||||
mod index;
|
|
||||||
|
|
||||||
pub fn filter() -> impl Filter {
|
|
||||||
warp::get().and(index::filter().or(assets::filter()).or(_404::filter()))
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue