diff --git a/Cargo.toml b/Cargo.toml index a0d5216..524f90c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,17 @@ edition = "2021" [dependencies] dioxus = "0.3.2" -dioxus-web = "0.3.1" dioxus-ssr = "0.3.0" - +rocket = "=0.5.0-rc.3" log = "0.4.6" +[target.'cfg(target_arch = "wasm32")'.dependencies] +dioxus-web = "0.3.1" # WebAssembly Debug wasm-logger = "0.2.0" 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"] diff --git a/README.md b/README.md index f951a0b..3e07243 100644 --- a/README.md +++ b/README.md @@ -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. @@ -16,9 +16,15 @@ cargo build cargo run ``` +### Package this project: + +``` +cargo build --release +``` + ## 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) @@ -26,12 +32,6 @@ cargo run dioxus serve --hot-reload --port 8234 ``` -### Package this project: - -``` -cargo build --release -``` - ## Project Structure ``` @@ -41,4 +41,5 @@ cargo build --release - - utils # save some public function - - data # text files that will be read to for data in the app - - components # save some custom components +- - templates # put template files here, right now just using handlebar ``` diff --git a/public/fonts/DejaVuSansMono.tff b/public/fonts/DejaVuSansMono.ttf similarity index 100% rename from public/fonts/DejaVuSansMono.tff rename to public/fonts/DejaVuSansMono.ttf diff --git a/public/styles/tailwind.min.css b/public/styles/tailwind.min.css index 462d1c0..bbc3cb4 100644 --- a/public/styles/tailwind.min.css +++ b/public/styles/tailwind.min.css @@ -1 +1 @@ -/*! tailwindcss v3.2.7 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px}}@media (min-width:1536px){.container{max-width:1536px}}.relative{position:relative}.mx-4{margin-left:1rem;margin-right:1rem}.mx-auto{margin-left:auto;margin-right:auto}.flex{display:flex}.hidden{display:none}.h-48{height:12rem}.min-h-screen{min-height:100vh}.w-48{width:12rem}.max-w-fit{max-width:-moz-fit-content;max-width:fit-content}@keyframes growshrink{0%{transform:scale(.5)}40%{transform:scale(1.2)}60%{transform:scale(1.2)}to{transform:scale(.5)}}.animate-growshrink{animation:growshrink 2s cubic-bezier(1,0,0,1) infinite}.flex-col{flex-direction:column}.justify-center{justify-content:center}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.border-4{border-width:4px}.border-alice-werefox-red-dark{--tw-border-opacity:1;border-color:rgb(128 0 8/var(--tw-border-opacity))}.bg-alice-werefox-grey-light{--tw-bg-opacity:1;background-color:rgb(204 204 204/var(--tw-bg-opacity))}.bg-alice-werefox-grey-lightest{--tw-bg-opacity:1;background-color:rgb(238 238 238/var(--tw-bg-opacity))}.p-4{padding:1rem}.py-4{padding-top:1rem;padding-bottom:1rem}.py-8{padding-top:2rem;padding-bottom:2rem}.font-nerd{font-family:DejaVuSansMono}.text-alice-werefox-red-dark{--tw-text-opacity:1;color:rgb(128 0 8/var(--tw-text-opacity))}@font-face{font-family:DejaVuSansMono;src:local("DejaVuSansMono"),url(/fonts/DejaVuSansMono.ttf),format("ttf")}@media (prefers-color-scheme:dark){.dark\:border-alice-werefox-red{--tw-border-opacity:1;border-color:rgb(201 52 57/var(--tw-border-opacity))}.dark\:bg-alice-werefox-grey{--tw-bg-opacity:1;background-color:rgb(36 36 36/var(--tw-bg-opacity))}.dark\:bg-alice-werefox-grey-dark{--tw-bg-opacity:1;background-color:rgb(18 18 18/var(--tw-bg-opacity))}.dark\:text-alice-werefox-red-light{--tw-text-opacity:1;color:rgb(224 133 135/var(--tw-text-opacity))}} \ No newline at end of file +/*! tailwindcss v3.2.7 | MIT License | https://tailwindcss.com*/*,:after,:before{box-sizing:border-box;border:0 solid #e5e7eb}:after,:before{--tw-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-feature-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:initial}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button;background-color:initial;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:initial}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}*,::backdrop,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%}@media (min-width:640px){.container{max-width:640px}}@media (min-width:768px){.container{max-width:768px}}@media (min-width:1024px){.container{max-width:1024px}}@media (min-width:1280px){.container{max-width:1280px}}@media (min-width:1536px){.container{max-width:1536px}}.relative{position:relative}.mx-4{margin-left:1rem;margin-right:1rem}.mx-auto{margin-left:auto;margin-right:auto}.flex{display:flex}.hidden{display:none}.h-48{height:12rem}.min-h-screen{min-height:100vh}.w-48{width:12rem}.max-w-fit{max-width:-moz-fit-content;max-width:fit-content}@keyframes growshrink{0%{transform:scale(.5)}40%{transform:scale(1.2)}60%{transform:scale(1.2)}to{transform:scale(.5)}}.animate-growshrink{animation:growshrink 2s cubic-bezier(1,0,0,1) infinite}.flex-col{flex-direction:column}.justify-center{justify-content:center}.space-y-4>:not([hidden])~:not([hidden]){--tw-space-y-reverse:0;margin-top:calc(1rem*(1 - var(--tw-space-y-reverse)));margin-bottom:calc(1rem*var(--tw-space-y-reverse))}.border-4{border-width:4px}.border-alice-werefox-red-dark{--tw-border-opacity:1;border-color:rgb(128 0 8/var(--tw-border-opacity))}.bg-alice-werefox-grey-light{--tw-bg-opacity:1;background-color:rgb(204 204 204/var(--tw-bg-opacity))}.bg-alice-werefox-grey-lightest{--tw-bg-opacity:1;background-color:rgb(238 238 238/var(--tw-bg-opacity))}.p-4{padding:1rem}.py-4{padding-top:1rem;padding-bottom:1rem}.py-8{padding-top:2rem;padding-bottom:2rem}.font-nerd{font-family:DejaVuSansMono}.text-alice-werefox-red-dark{--tw-text-opacity:1;color:rgb(128 0 8/var(--tw-text-opacity))}@font-face{font-family:DejaVuSansMono;src:url(/fonts/DejaVuSansMono.ttf)}@media (prefers-color-scheme:dark){.dark\:border-alice-werefox-red{--tw-border-opacity:1;border-color:rgb(201 52 57/var(--tw-border-opacity))}.dark\:bg-alice-werefox-grey{--tw-bg-opacity:1;background-color:rgb(36 36 36/var(--tw-bg-opacity))}.dark\:bg-alice-werefox-grey-dark{--tw-bg-opacity:1;background-color:rgb(18 18 18/var(--tw-bg-opacity))}.dark\:text-alice-werefox-red-light{--tw-text-opacity:1;color:rgb(224 133 135/var(--tw-text-opacity))}} \ No newline at end of file diff --git a/src/index.css b/src/index.css index 0657d06..89da347 100644 --- a/src/index.css +++ b/src/index.css @@ -1,8 +1,8 @@ - @tailwind base; @tailwind components; @tailwind utilities; -@font-face { - font-family: 'DejaVuSansMono'; - src: local('DejaVuSansMono'), url('/fonts/DejaVuSansMono.ttf'), format('ttf'); + +@font-face { + font-family: "DejaVuSansMono"; + src: url("/fonts/DejaVuSansMono.ttf"); } diff --git a/src/main.rs b/src/main.rs index af9d7ab..c4a89b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,28 +1,24 @@ #[macro_use] extern crate rocket; +use dioxus::core::VirtualDom; use rocket::fs::FileServer; -use rocket::http::ContentType; -use rocket::tokio::fs::File; -use std::path::Path; - -// #[get("/")] -// async fn fonts(font: &str) -> (ContentType, Option) { -// let filename = Path::new("public/fonts/").join(font); -// (ContentType::TTF, File::open(&filename).await.ok()) -// } +use rocket_dyn_templates::{Template, context}; +use rust_letter::web_app; #[get("/")] -async fn index() -> rocket::response::content::RawHtml { - let mut vdom = dioxus::core::VirtualDom::new(rust_letter::web_app::App); +async fn index() -> Template { + let mut vdom = VirtualDom::new(web_app::App); let _ = vdom.rebuild(); - let mut output = dioxus_ssr::render(&vdom); - output = format!( - "{}", - output + let output = dioxus_ssr::render(&vdom); + Template::render( + "index", + context! { + app_title: "A Letter For You!", + style_include: "", + test: &output + }, ) - .to_string(); - rocket::response::content::RawHtml(output) } #[rocket::main] @@ -31,8 +27,8 @@ async fn main() -> Result<(), rocket::Error> { .mount("/images", FileServer::from("public/images")) .mount("/styles", FileServer::from("public/styles")) .mount("/fonts", FileServer::from("public/fonts")) - .mount("/", routes![index]) + .mount("/", routes![index]).attach(Template::fairing()) .launch() - .await?; + .await; Ok(()) } diff --git a/templates/index.html.hbs b/templates/index.html.hbs new file mode 100644 index 0000000..1a4fe70 --- /dev/null +++ b/templates/index.html.hbs @@ -0,0 +1,12 @@ + + + {{app_title}} + + + + {{{style_include}}} + + +
{{{test}}}
+ + \ No newline at end of file