Skip to content

Commit

Permalink
Merge pull request #11 from rust-dd/feat/add-extra-features
Browse files Browse the repository at this point in the history
feat: refactor file ordering and add hire us and references
  • Loading branch information
dancixx authored Dec 20, 2024
2 parents 3b1b097 + 340cf56 commit e87c54c
Show file tree
Hide file tree
Showing 19 changed files with 813 additions and 185 deletions.
403 changes: 368 additions & 35 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
axum = { version = "0.7", optional = true, features = ["macros"] }
console_error_panic_hook = "0.1"
leptos = { version = "0.7.0", features = ["rustls", "nightly"] }
leptos_axum = { version = "0.7.0", optional = true }
leptos_meta = { version = "0.7.0" }
leptos_router = { version = "0.7.0", features = ["nightly"] }
leptos = { version = "0.7.1", features = ["rustls", "nightly"] }
leptos_axum = { version = "0.7.1", optional = true }
leptos_meta = { version = "0.7.1" }
leptos_router = { version = "0.7.1", features = ["nightly"] }
tokio = { version = "1", features = ["rt-multi-thread"], optional = true }
tower = { version = "0.5.1", optional = true }
tower-http = { version = "0.6.2", features = [
Expand Down Expand Up @@ -41,6 +41,13 @@ katex = { version = "0.4.6", optional = true, default-features = false, features
"duktape",
] }
web-sys = "0.3.72"
lettre = { version = "0.11.9", default-features = false, optional = true, features = [
"builder",
"smtp-transport",
"rustls-tls",
"tokio1",
"tokio1-rustls-tls",
] }

[features]
hydrate = ["leptos/hydrate"]
Expand All @@ -60,6 +67,7 @@ ssr = [
"dep:rss",
"dep:tracing-subscriber",
"dep:katex",
"dep:lettre",
]

# Defines a size-optimized profile for the WASM bundle in release mode
Expand All @@ -74,7 +82,7 @@ panic = "abort"
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "blog"

# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your ssr setup.
site-root = "target/site"

# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
Expand All @@ -92,7 +100,7 @@ tailwind-config-file = "tailwind.config.js"
# Optional. Env: LEPTOS_ASSETS_DIR.
assets-dir = "public"

# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
# The IP and port (ex: 127.0.0.1:3000) where the ssr serves the content. Use it in your ssr setup.
site-addr = "127.0.0.1:3000"

# The port to use for automatic reload monitoring
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ FROM rustlang/rust:nightly-alpine as runner

WORKDIR /app

# Copy the server binary and site content from the builder stage
# Copy the ssr binary and site content from the builder stage
COPY --from=builder /work/target/release/blog /app/
COPY --from=builder /work/target/site /app/site
COPY --from=builder /work/Cargo.toml /app/
Expand All @@ -44,5 +44,5 @@ ENV LEPTOS_SITE_ROOT="site"
EXPOSE 8080


# Run the server
# Run the ssr
CMD ["/app/blog"]
111 changes: 9 additions & 102 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::error_template::{AppError, ErrorTemplate};
use crate::{
components::{error_template, header},
pages::{hireus, home, post, references},
};
use chrono::{Datelike, Utc};
use leptos::prelude::*;
use leptos_meta::*;
Expand All @@ -7,8 +10,6 @@ use leptos_router::{
ParamSegment, SsrMode, StaticSegment,
};

use crate::{home, post};

pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
Expand Down Expand Up @@ -93,110 +94,16 @@ pub fn App() -> impl IntoView {
view! {
<Router>
<div class="overflow-auto text-white font-poppins">
<header class="fixed top-0 right-0 left-0 z-10 py-6 px-4 md:px-6 bg-[#1e1e1e]/80 backdrop-blur-md">
<div class="container mx-auto max-w-5xl">
<div class="flex flex-row justify-between items-center text-white">
<a
href="/"
on:click=move |_| {
use web_sys::window;
let document = window().unwrap().document().unwrap();
if let Some(element) = document.get_element_by_id("giscus") {
if let Some(parent) = element.parent_node() {
parent.remove_child(&element).unwrap();
}
}
}
class="text-xl font-bold transition-all duration-500 sm:text-3xl hover:text-[#ffef5c]"
>
rust-dd.com
</a>
<div class="flex flex-row gap-3 items-center h-10">
<a
href="https://github.com/rust-dd/"
rel="noopener noreferrer"
target="_blank"
aria-label="GitHub"
>
<svg
class="transition-all duration-500 size-6 hover:text-[#ffef5c]"
width="1em"
height="1em"
viewBox="0 0 512 512"
fill="currentColor"
role="graphics-symbol"
data-hk="0-0-0-72"
>
<path d="M256,32C132.3,32,32,134.9,32,261.7c0,101.5,64.2,187.5,153.2,217.9a17.56,17.56,0,0,0,3.8.4c8.3,0,11.5-6.1,11.5-11.4,0-5.5-.2-19.9-.3-39.1a102.4,102.4,0,0,1-22.6,2.7c-43.1,0-52.9-33.5-52.9-33.5-10.2-26.5-24.9-33.6-24.9-33.6-19.5-13.7-.1-14.1,1.4-14.1h.1c22.5,2,34.3,23.8,34.3,23.8,11.2,19.6,26.2,25.1,39.6,25.1a63,63,0,0,0,25.6-6c2-14.8,7.8-24.9,14.2-30.7-49.7-5.8-102-25.5-102-113.5,0-25.1,8.7-45.6,23-61.6-2.3-5.8-10-29.2,2.2-60.8a18.64,18.64,0,0,1,5-.5c8.1,0,26.4,3.1,56.6,24.1a208.21,208.21,0,0,1,112.2,0c30.2-21,48.5-24.1,56.6-24.1a18.64,18.64,0,0,1,5,.5c12.2,31.6,4.5,55,2.2,60.8,14.3,16.1,23,36.6,23,61.6,0,88.2-52.4,107.6-102.3,113.3,8,7.1,15.2,21.1,15.2,42.5,0,30.7-.3,55.5-.3,63,0,5.4,3.1,11.5,11.4,11.5a19.35,19.35,0,0,0,4-.4C415.9,449.2,480,363.1,480,261.7,480,134.9,379.7,32,256,32Z"></path>
</svg>
</a>
<a
href="https://x.com/rust_dd"
rel="noopener noreferrer"
target="_blank"
aria-label="X"
>
<svg
class="transition-all duration-500 size-6 hover:text-[#ffef5c]"
width="1em"
height="1em"
viewBox="0 0 512 512"
fill="currentColor"
role="graphics-symbol"
data-hk="0-0-0-76"
>
<path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"></path>
</svg>
</a>
<a
href="https://www.linkedin.com/company/rust-dd"
rel="noopener noreferrer"
target="_blank"
aria-label="LinkedIn"
>
<svg
class="transition-all duration-500 size-6 hover:text-[#ffef5c]"
width="1em"
height="1em"
viewBox="0 0 448 512"
fill="currentColor"
role="graphics-symbol"
data-hk="0-0-0-80"
>
<path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3zM135.4 416H69V202.2h66.5V416zm-33.2-243c-21.3 0-38.5-17.3-38.5-38.5S80.9 96 102.2 96c21.2 0 38.5 17.3 38.5 38.5 0 21.3-17.2 38.5-38.5 38.5zm282.1 243h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9V416z"></path>
</svg>
</a>
<a
href="/rss.xml"
rel="noopener noreferrer"
target="_blank"
aria-label="RSS"
>
<svg
class="transition-all duration-500 size-6 hover:text-[#ffef5c]"
width="1em"
height="1em"
viewBox="0 0 512 512"
fill="currentColor"
role="graphics-symbol"
data-hk="0-0-0-84"
>
<path d="M108.56,342.78a60.34,60.34,0,1,0,60.56,60.44A60.63,60.63,0,0,0,108.56,342.78Z"></path>
<path d="M48,186.67v86.55c52,0,101.94,15.39,138.67,52.11s52,86.56,52,138.67h86.66C325.33,312.44,199.67,186.67,48,186.67Z"></path>
<path d="M48,48v86.56c185.25,0,329.22,144.08,329.22,329.44H464C464,234.66,277.67,48,48,48Z"></path>
</svg>
</a>
</div>
</div>
</div>
</header>
<header::Component />
<main class="container flex flex-col gap-8 px-4 pt-10 pb-14 mx-auto mt-16 max-w-4xl md:px-0">
<FlatRoutes fallback=|| {
let mut outside_errors = Errors::default();
outside_errors.insert_with_default_key(AppError::NotFound);
view! { <ErrorTemplate outside_errors /> }.into_view()
outside_errors.insert_with_default_key(error_template::AppError::NotFound);
view! { <error_template::Component outside_errors /> }.into_view()
}>
<Route path=StaticSegment("") view=home::Component ssr=SsrMode::InOrder />
// <Route path=StaticSegment("references") view=references::Component />
<Route path=StaticSegment("hireus") view=hireus::Component />
<Route
path=(StaticSegment("post"), ParamSegment("slug"))
view=post::Component
Expand Down
3 changes: 3 additions & 0 deletions src/components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod error_template;
pub mod header;
pub mod loader;
4 changes: 2 additions & 2 deletions src/error_template.rs → src/components/error_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl AppError {
// A basic function to display errors served by the error boundaries.
// Feel free to do more complicated things here than just displaying the error.
#[component]
pub fn ErrorTemplate(
pub fn Component(
#[prop(optional)] outside_errors: Option<Errors>,
#[prop(optional)] errors: Option<RwSignal<Errors>>,
) -> impl IntoView {
Expand All @@ -40,7 +40,7 @@ pub fn ErrorTemplate(
.collect();
println!("Errors: {errors:#?}");

// Only the response code for the first error is actually sent from the server
// Only the response code for the first error is actually sent from the ssr
// this may be customized by the specific application
#[cfg(feature = "ssr")]
{
Expand Down
118 changes: 118 additions & 0 deletions src/components/header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use leptos::prelude::*;

#[component]
pub fn Component() -> impl IntoView {
view! {
<header class="fixed top-0 right-0 left-0 z-10 py-6 px-4 md:px-6 bg-[#1e1e1e]/80 backdrop-blur-md">
<div class="container mx-auto max-w-5xl">
<div class="flex flex-row justify-between items-center text-white">
<div class="flex flex-row gap-4">
<a
href="/"
on:click=move |_| {
use web_sys::window;
let document = window().unwrap().document().unwrap();
if let Some(element) = document.get_element_by_id("giscus") {
if let Some(parent) = element.parent_node() {
parent.remove_child(&element).unwrap();
}
}
}
class="text-lg font-bold transition-all duration-500 sm:text-3xl hover:text-[#ffef5c]"
>
blog
</a>
// <a
// href="/references"
// class="text-lg font-bold transition-all duration-500 sm:text-3xl hover:text-[#ffef5c]"
// >
// references
// </a>
<a
href="/hireus"
class="text-lg font-bold transition-all duration-500 sm:text-3xl hover:text-[#ffef5c]"
>
hire us!
</a>
</div>
<div class="flex flex-row gap-3 items-center h-10">
<a
href="https://github.com/rust-dd/"
rel="noopener noreferrer"
target="_blank"
aria-label="GitHub"
>
<svg
class="transition-all duration-500 size-6 hover:text-[#ffef5c]"
width="1em"
height="1em"
viewBox="0 0 512 512"
fill="currentColor"
role="graphics-symbol"
data-hk="0-0-0-72"
>
<path d="M256,32C132.3,32,32,134.9,32,261.7c0,101.5,64.2,187.5,153.2,217.9a17.56,17.56,0,0,0,3.8.4c8.3,0,11.5-6.1,11.5-11.4,0-5.5-.2-19.9-.3-39.1a102.4,102.4,0,0,1-22.6,2.7c-43.1,0-52.9-33.5-52.9-33.5-10.2-26.5-24.9-33.6-24.9-33.6-19.5-13.7-.1-14.1,1.4-14.1h.1c22.5,2,34.3,23.8,34.3,23.8,11.2,19.6,26.2,25.1,39.6,25.1a63,63,0,0,0,25.6-6c2-14.8,7.8-24.9,14.2-30.7-49.7-5.8-102-25.5-102-113.5,0-25.1,8.7-45.6,23-61.6-2.3-5.8-10-29.2,2.2-60.8a18.64,18.64,0,0,1,5-.5c8.1,0,26.4,3.1,56.6,24.1a208.21,208.21,0,0,1,112.2,0c30.2-21,48.5-24.1,56.6-24.1a18.64,18.64,0,0,1,5,.5c12.2,31.6,4.5,55,2.2,60.8,14.3,16.1,23,36.6,23,61.6,0,88.2-52.4,107.6-102.3,113.3,8,7.1,15.2,21.1,15.2,42.5,0,30.7-.3,55.5-.3,63,0,5.4,3.1,11.5,11.4,11.5a19.35,19.35,0,0,0,4-.4C415.9,449.2,480,363.1,480,261.7,480,134.9,379.7,32,256,32Z"></path>
</svg>
</a>
<a
href="https://x.com/rust_dd"
rel="noopener noreferrer"
target="_blank"
aria-label="X"
>
<svg
class="transition-all duration-500 size-6 hover:text-[#ffef5c]"
width="1em"
height="1em"
viewBox="0 0 512 512"
fill="currentColor"
role="graphics-symbol"
data-hk="0-0-0-76"
>
<path d="M389.2 48h70.6L305.6 224.2 487 464H345L233.7 318.6 106.5 464H35.8L200.7 275.5 26.8 48H172.4L272.9 180.9 389.2 48zM364.4 421.8h39.1L151.1 88h-42L364.4 421.8z"></path>
</svg>
</a>
<a
href="https://www.linkedin.com/company/rust-dd"
rel="noopener noreferrer"
target="_blank"
aria-label="LinkedIn"
>
<svg
class="transition-all duration-500 size-6 hover:text-[#ffef5c]"
width="1em"
height="1em"
viewBox="0 0 448 512"
fill="currentColor"
role="graphics-symbol"
data-hk="0-0-0-80"
>
<path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3zM135.4 416H69V202.2h66.5V416zm-33.2-243c-21.3 0-38.5-17.3-38.5-38.5S80.9 96 102.2 96c21.2 0 38.5 17.3 38.5 38.5 0 21.3-17.2 38.5-38.5 38.5zm282.1 243h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9V416z"></path>
</svg>
</a>
<a
href="/rss.xml"
rel="noopener noreferrer"
target="_blank"
aria-label="RSS"
>
<svg
class="transition-all duration-500 size-6 hover:text-[#ffef5c]"
width="1em"
height="1em"
viewBox="0 0 512 512"
fill="currentColor"
role="graphics-symbol"
data-hk="0-0-0-84"
>
<path d="M108.56,342.78a60.34,60.34,0,1,0,60.56,60.44A60.63,60.63,0,0,0,108.56,342.78Z"></path>
<path d="M48,186.67v86.55c52,0,101.94,15.39,138.67,52.11s52,86.56,52,138.67h86.66C325.33,312.44,199.67,186.67,48,186.67Z"></path>
<path d="M48,48v86.56c185.25,0,329.22,144.08,329.22,329.44H464C464,234.66,277.67,48,48,48Z"></path>
</svg>
</a>
</div>
</div>
</div>
</header>
}
}
File renamed without changes.
25 changes: 3 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#![feature(async_closure)]

pub mod app;
pub mod error_template;
pub mod home;
pub mod loader;
pub mod post;
#[cfg(feature = "ssr")]
pub mod redirect;
pub mod server;
#[cfg(feature = "ssr")]
pub mod server_utils;
pub mod components;
pub mod pages;
pub mod ssr;

#[cfg(feature = "hydrate")]
#[wasm_bindgen::prelude::wasm_bindgen]
Expand All @@ -18,16 +12,3 @@ pub fn hydrate() {
console_error_panic_hook::set_once();
leptos::mount::hydrate_body(App);
}

#[cfg(feature = "ssr")]
pub mod ssr {
use axum::extract::FromRef;
use leptos::prelude::*;
use surrealdb::{engine::remote::http::Client, Surreal};

#[derive(FromRef, Debug, Clone)]
pub struct AppState {
pub db: Surreal<Client>,
pub leptos_options: LeptosOptions,
}
}
Loading

0 comments on commit e87c54c

Please sign in to comment.