1
Fork 0
mirror of https://github.com/RGBCube/rgbcube.github.io synced 2025-05-14 05:54:58 +00:00

Make warp work

This commit is contained in:
RGBCube 2023-12-27 11:08:16 +03:00
parent 9434ff9e8d
commit dc82b04345
No known key found for this signature in database
7 changed files with 41 additions and 42 deletions

View file

@ -1,7 +1,7 @@
@font-face {
font-family: "Bai Jamjuree";
font-weight: 700;
src: url("assets/BaiJamjuree700.woff2") format("woff2");
src: url("/assets/BaiJamjuree700.woff2") format("woff2");
}
body,

View file

@ -9,6 +9,8 @@ mod routes;
use constants::*;
use env_logger::Target;
use log::LevelFilter;
use routes::*;
use warp::Filter;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
@ -17,7 +19,9 @@ async fn main() -> anyhow::Result<()> {
.target(Target::Stdout)
.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(())
}

View file

@ -45,7 +45,7 @@ pub fn create(head: Markup, body: Markup) -> Markup {
(pname("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:type", "image/png"))

View file

@ -1,20 +1,24 @@
use std::{
array,
convert::Infallible,
sync::LazyLock,
};
use maud::{
html,
Markup,
use maud::html;
use warp::{
reply::{
self,
Html,
},
Filter,
};
use warp::Filter;
use crate::{
cube,
minify,
};
static PAGE: LazyLock<Markup> = LazyLock::new(|| {
static PAGE: LazyLock<String> = LazyLock::new(|| {
cube::create(
minify::css(embed::string!("404.css")),
array::from_fn(|_| {
@ -28,8 +32,9 @@ static PAGE: LazyLock<Markup> = LazyLock::new(|| {
.clone()
}),
)
.into_string()
});
pub fn filter() -> impl Filter {
warp::any().map(|| &*PAGE)
pub fn filter() -> impl Filter<Extract = (Html<&'static str>,), Error = Infallible> + Clone {
warp::any().map(|| reply::html(PAGE.as_str()))
}

View file

@ -9,11 +9,12 @@ use std::{
use tar::Archive;
use warp::{
filters::path::FullPath,
filters::fs::File,
reject::Rejection,
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 mut archive = Archive::new(Cursor::new(contents.as_ref()));
@ -38,16 +39,6 @@ static ASSETS: LazyLock<HashMap<String, Vec<u8>>> = LazyLock::new(|| {
assets
});
pub fn filter() -> impl Filter {
warp::path!("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()
}
})
pub fn filter() -> impl Filter<Extract = (File,), Error = Rejection> + Clone {
warp::path("assets").and(warp::fs::dir("assets"))
}

View file

@ -1,29 +1,33 @@
use std::sync::LazyLock;
use maud::{
html,
Markup,
use maud::html;
use warp::{
reject::Rejection,
reply::{
self,
Html,
},
Filter,
};
use warp::Filter;
use crate::{
cube,
minify,
};
static PAGE: LazyLock<Markup> = LazyLock::new(|| {
static PAGE: LazyLock<String> = LazyLock::new(|| {
cube::create(
minify::css(embed::string!("index.css")),
[
html! {
a href="contact" {
a href="/contact" {
div class="frame" {
"contact"
}
}
},
html! {
a href="github" {
a href="/github" {
div class="frame" {
"github"
}
@ -35,8 +39,9 @@ static PAGE: LazyLock<Markup> = LazyLock::new(|| {
html! {},
],
)
.into_string()
});
pub fn filter() -> impl Filter {
warp::any().map(|| &*PAGE)
pub fn filter() -> impl Filter<Extract = (Html<&'static str>,), Error = Rejection> + Clone {
warp::path!().map(|| reply::html(PAGE.as_str()))
}

View file

@ -1,9 +1,3 @@
use warp::Filter;
mod _404;
mod assets;
mod index;
pub fn filter() -> impl Filter {
warp::get().and(index::filter().or(assets::filter()).or(_404::filter()))
}
pub mod _404;
pub mod assets;
pub mod index;