Fixed typo with custom font file, added minor templating to replace content::RawHtml() call, updated README.

This commit is contained in:
Ada Werefox 2023-03-29 17:29:57 +00:00
parent b85a03c6fd
commit a9f0964452
7 changed files with 49 additions and 35 deletions

View File

@ -8,12 +8,17 @@ edition = "2021"
[dependencies] [dependencies]
dioxus = "0.3.2" dioxus = "0.3.2"
dioxus-web = "0.3.1"
dioxus-ssr = "0.3.0" dioxus-ssr = "0.3.0"
rocket = "=0.5.0-rc.3"
log = "0.4.6" log = "0.4.6"
[target.'cfg(target_arch = "wasm32")'.dependencies]
dioxus-web = "0.3.1"
# WebAssembly Debug # WebAssembly Debug
wasm-logger = "0.2.0" wasm-logger = "0.2.0"
console_error_panic_hook = "0.1.7" console_error_panic_hook = "0.1.7"
rocket = "=0.5.0-rc.3" wasm-bindgen = "0.2"
[dependencies.rocket_dyn_templates]
version = "=0.1.0-rc.3"
features = ["handlebars"]

View File

@ -1,4 +1,4 @@
# Dioxus - [letter.werefox.cafe](https://letter.werefox.cafe) # Dioxus (& Rocket) - [letter.werefox.cafe](https://letter.werefox.cafe)
> A re-implementation of the Valentine's Day site I made, but using Rust's [Dioxus](https://dioxuslabs.com/) crate and [Rocket](https://rocket.rs/) crate. > A re-implementation of the Valentine's Day site I made, but using Rust's [Dioxus](https://dioxuslabs.com/) crate and [Rocket](https://rocket.rs/) crate.
@ -16,9 +16,15 @@ cargo build
cargo run cargo run
``` ```
### Package this project:
```
cargo build --release
```
## Ignore This Section ## Ignore This Section
> I need to set things up so you can run the Dioxus dev server wothout launching rocket. I'll figire that out later. > **TODO:** Make subcrates for Dioxus and Rocket, should enable dev server for Dioxus while maintaining overall compatibility.
(or, I personally use the following since port `8080` is usually being used and I want hot reloading) (or, I personally use the following since port `8080` is usually being used and I want hot reloading)
@ -26,12 +32,6 @@ cargo run
dioxus serve --hot-reload --port 8234 dioxus serve --hot-reload --port 8234
``` ```
### Package this project:
```
cargo build --release
```
## Project Structure ## Project Structure
``` ```
@ -41,4 +41,5 @@ cargo build --release
- - utils # save some public function - - utils # save some public function
- - data # text files that will be read to for data in the app - - data # text files that will be read to for data in the app
- - components # save some custom components - - components # save some custom components
- - templates # put template files here, right now just using handlebar
``` ```

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
@tailwind base; @tailwind base;
@tailwind components; @tailwind components;
@tailwind utilities; @tailwind utilities;
@font-face {
font-family: 'DejaVuSansMono'; @font-face {
src: local('DejaVuSansMono'), url('/fonts/DejaVuSansMono.ttf'), format('ttf'); font-family: "DejaVuSansMono";
src: url("/fonts/DejaVuSansMono.ttf");
} }

View File

@ -1,28 +1,24 @@
#[macro_use] #[macro_use]
extern crate rocket; extern crate rocket;
use dioxus::core::VirtualDom;
use rocket::fs::FileServer; use rocket::fs::FileServer;
use rocket::http::ContentType; use rocket_dyn_templates::{Template, context};
use rocket::tokio::fs::File; use rust_letter::web_app;
use std::path::Path;
// #[get("/<font>")]
// async fn fonts(font: &str) -> (ContentType, Option<File>) {
// let filename = Path::new("public/fonts/").join(font);
// (ContentType::TTF, File::open(&filename).await.ok())
// }
#[get("/")] #[get("/")]
async fn index() -> rocket::response::content::RawHtml<String> { async fn index() -> Template {
let mut vdom = dioxus::core::VirtualDom::new(rust_letter::web_app::App); let mut vdom = VirtualDom::new(web_app::App);
let _ = vdom.rebuild(); let _ = vdom.rebuild();
let mut output = dioxus_ssr::render(&vdom); let output = dioxus_ssr::render(&vdom);
output = format!( Template::render(
"<head><link href=/styles/tailwind.min.css rel=stylesheet /></head>{}", "index",
output context! {
app_title: "A Letter For You!",
style_include: "<link href=/styles/tailwind.min.css rel=stylesheet />",
test: &output
},
) )
.to_string();
rocket::response::content::RawHtml(output)
} }
#[rocket::main] #[rocket::main]
@ -31,8 +27,8 @@ async fn main() -> Result<(), rocket::Error> {
.mount("/images", FileServer::from("public/images")) .mount("/images", FileServer::from("public/images"))
.mount("/styles", FileServer::from("public/styles")) .mount("/styles", FileServer::from("public/styles"))
.mount("/fonts", FileServer::from("public/fonts")) .mount("/fonts", FileServer::from("public/fonts"))
.mount("/", routes![index]) .mount("/", routes![index]).attach(Template::fairing())
.launch() .launch()
.await?; .await;
Ok(()) Ok(())
} }

12
templates/index.html.hbs Normal file
View File

@ -0,0 +1,12 @@
<html>
<head>
<title>{{app_title}}</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charset="UTF-8" />
{{{style_include}}}
</head>
<body>
<div id="main">{{{test}}}</div>
</body>
</html>