back with rocket, using leptos 0.7.0-rc1 ssr only

This commit is contained in:
Philippe Loctaux 2024-11-08 17:59:03 +01:00
parent feba0ad668
commit 1d1b7db7b7
26 changed files with 1573 additions and 1532 deletions

1794
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,12 +4,3 @@ members = ["crates/gen-wallpapers", "crates/plcom"]
[workspace.dependencies]
serde = "1.0"
# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
inherits = "release"
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"

View file

@ -4,7 +4,7 @@ use location::Gps;
use location::Location;
use location::parse_coordinates;
use exif::{DateTime, Exif, In, Tag};
use exif::{DateTime, In, Tag};
use serde::Serialize;
use std::fs::ReadDir;
use std::io::BufReader;

View file

@ -3,116 +3,15 @@ name = "plcom"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
# leptos + axum
axum = { version = "0.7", optional = true }
console_error_panic_hook = "0.1"
leptos = { version = "0.6" }
leptos_axum = { version = "0.6", optional = true }
leptos_meta = { version = "0.6" }
leptos_router = { version = "0.6" }
tokio = { version = "1", features = ["rt-multi-thread"], optional = true }
tower = { version = "0.4", optional = true }
tower-http = { version = "0.5", features = ["fs"], optional = true }
wasm-bindgen = "=0.2.93"
thiserror = "1"
tracing = { version = "0.1", optional = true }
http = "1"
# external crates
tailwind_fuse = { version = "0.2.0", features = ["variant"] }
chrono = "0.4.37"
getrandom = { version = "0.2", features = ["js"] }
rand = "0.8.5"
leptos-leaflet = "0.8.0"
rocket = "0.5"
leptos = {version = "0.7.0-rc1" , features = ["ssr"]}
jiff = "0.1"
rocket_async_compression = "0.6"
nanorand = { version = "0.7", features = ["chacha"] }
tailwind_fuse = { version = "0.3", features = ["variant"] }
[build-dependencies]
serde = { workspace = true }
serde_json = "1.0"
gen-wallpapers = { path = "../../crates/gen-wallpapers" }
[features]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate", "leptos-leaflet/hydrate"]
ssr = [
"dep:axum",
"dep:tokio",
"dep:tower",
"dep:tower-http",
"dep:leptos_axum",
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
"dep:tracing",
"leptos-leaflet/ssr"
]
[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "plcom"
# 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.
site-root = "target/site"
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
# Defaults to pkg
site-pkg-dir = "pkg"
# The tailwind input file.
#
# Optional, Activates the tailwind build
tailwind-input-file = "css/main.css"
# The tailwind config file.
#
# Optional, defaults to "tailwind.config.js" which if is not present
# is generated for you
tailwind-config-file = "tailwind.config.js"
# Assets source dir. All files found here will be copied and synchronized to site-root.
# The assets-dir cannot have a sub directory with the same name/path as site-pkg-dir.
#
# Optional. Env: LEPTOS_ASSETS_DIR.
assets-dir = "../../public"
# Additional files triggering recompilation
watch-additional-files = ["resume.json", "wallpapers.json"]
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
site-addr = "0.0.0.0:3000"
# The port to use for automatic reload monitoring
reload-port = 3001
# The browserlist query used for optimizing the CSS.
browserquery = "defaults"
# The environment Leptos will run in, usually either "DEV" or "PROD"
env = "DEV"
# The features to use when compiling the bin target
#
# Optional. Can be over-ridden with the command line parameter --bin-features
bin-features = ["ssr"]
# If the --no-default-features flag should be used when compiling the bin target
#
# Optional. Defaults to false.
bin-default-features = false
# The features to use when compiling the lib target
#
# Optional. Can be over-ridden with the command line parameter --lib-features
lib-features = ["hydrate"]
# If the --no-default-features flag should be used when compiling the lib target
#
# Optional. Defaults to false.
lib-default-features = false
# The profile to use for the lib target when compiling for release
#
# Optional. Defaults to "release".
lib-profile-release = "wasm-release"

View file

@ -1,71 +0,0 @@
use crate::{
error_template::{AppError, ErrorTemplate},
pages::*,
Link, UnderlineLink,
};
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
use tailwind_fuse::*;
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
let formatter = |text| format!("{text} — Philippe Loctaux");
view! {
<Html lang="en"/>
<Stylesheet id="leptos" href="/pkg/plcom.css"/>
// sets the document title
<Title formatter/>
<Meta name="viewport" content="width=device-width"/>
// favicon
<Link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/>
<Link rel="icon" type_="image/png" sizes="32x32" href="/favicon-32x32.png"/>
<Link rel="icon" type_="image/png" sizes="16x16" href="/favicon-16x16.png"/>
<Link rel="manifest" href="/site.webmanifest"/>
<Link
rel="mask-icon"
href="/safari-pinned-tab.svg"
attrs=vec![("color", Attribute::String(Oco::Borrowed("#0c4a6e")))]
/>
<Meta name="msapplication-TileColor" content="#0c4a6e"/>
<Meta name="theme-color" content="#0c4a6e"/>
// stats
<Script
defer="true"
src="https://plausible.y.z.x4m3.rocks/js/script.js"
attrs=vec![("data-domain", Attribute::String(Oco::Borrowed("philippeloctaux.com")))]
/>
// actual routes
<Router fallback=|| {
let mut outside_errors = Errors::default();
outside_errors.insert_with_default_key(AppError::NotFound);
view! { <ErrorTemplate outside_errors/> }.into_view()
}>
<Body class=tw_join!("flex", "flex-col", "min-h-screen", "bg-gray-900", "text-white")/>
<main class=tw_join!("flex-grow")>
<Routes>
<Route path="" view=RootPage ssr=SsrMode::Async/>
<Route path="email" view=EmailPage/>
<Route path="wallpapers" view=WallpapersPage/>
</Routes>
</main>
<footer class=tw_join!("bg-black")>
<div class=tw_join!("container", "mx-auto", "px-4", "py-8")>
<p>
"© 2015 - "{crate::get_year()}" Philippe Loctaux, made with "
<UnderlineLink link=Link::new("https://leptos.dev", "Leptos")/>
</p>
</div>
</footer>
</Router>
}
}

57
crates/plcom/src/cache.rs Normal file
View file

@ -0,0 +1,57 @@
use rocket::fairing::{self, Fairing};
use rocket::http::{ContentType, Header};
use rocket::{Request, Response};
#[derive(Debug)]
pub struct CacheControl {
duration_secs: u32,
types: Vec<ContentType>,
routes: Vec<&'static str>,
}
impl Default for CacheControl {
fn default() -> Self {
CacheControl {
duration_secs: 60 * 60, // 60 secs * 60 minutes
types: vec![ContentType::HTML, ContentType::CSS, ContentType::JavaScript],
routes: vec!["/wallpapers", "/pub", "/images", "/icons"],
}
}
}
#[rocket::async_trait]
impl Fairing for CacheControl {
fn info(&self) -> fairing::Info {
fairing::Info {
name: "Cache Control",
kind: fairing::Kind::Response,
}
}
async fn on_response<'r>(&self, request: &'r Request<'_>, response: &mut Response<'r>) {
let mut should_cache = false;
// Check if content type matches
if let Some(content_type) = response.content_type() {
if self.types.contains(&content_type) {
println!("going to cache {:?}", content_type);
should_cache = true;
}
}
// TODO: make sure if it is either
// Check if route matches
self.routes
.iter()
.filter(|s| request.uri().path().starts_with(*s))
.for_each(|_| should_cache = true);
if should_cache {
response.set_header(Header::new(
"Cache-Control",
format!("public, max-age={}", self.duration_secs),
));
}
}
}

View file

@ -1,11 +1,6 @@
pub mod icon;
pub mod link;
pub fn get_year() -> i32 {
use chrono::Datelike;
chrono::Utc::now().year()
}
#[derive(Clone, PartialEq)]
pub struct Date {
pub year: u32,
@ -14,7 +9,22 @@ pub struct Date {
impl std::fmt::Display for Date {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}-{:02}", self.year, self.month)
let month = match self.month {
1 => "January",
2 => "Februrary",
3 => "March",
4 => "April",
5 => "May",
6 => "June",
7 => "July",
8 => "August",
9 => "September",
10 => "October",
11 => "November",
12 => "December",
_ => panic!("wtf not a month"),
};
write!(f, "{month} {}", self.year)
}
}
@ -65,18 +75,14 @@ pub mod resume {
pub not_available: bool,
}
use crate::{Link, OutlineButtonLink};
use http::Uri;
use leptos::*;
use crate::common::link::{Link, outline_button_link};
use leptos::prelude::*;
use tailwind_fuse::tw_join;
impl IntoView for ResumeLink {
fn into_view(self) -> View {
impl IntoAny for ResumeLink {
fn into_any(self) -> AnyView {
if !self.not_available {
let link = Link {
label: self.label.into(),
uri: Uri::from_static(self.uri),
};
view! { <OutlineButtonLink link=link/> }.into_view()
let link = Link::parse(self.uri, self.label);
outline_button_link(link).into_any()
} else {
view! {
<span class=tw_join!(
@ -85,7 +91,7 @@ pub mod resume {
"items-center"
)>{self.label}</span>
}
.into_view()
.into_any()
}
}
}
@ -120,6 +126,12 @@ pub mod wallpapers {
pub longitude: f32,
}
impl std::fmt::Display for Gps {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "[{}, {}]", self.latitude, self.longitude)
}
}
#[derive(Clone, Copy)]
pub struct Location {
pub precise: &'static str,
@ -128,8 +140,19 @@ pub mod wallpapers {
impl Wallpaper {
pub fn random() -> Option<&'static Wallpaper> {
let random_value = rand::Rng::gen_range(&mut rand::thread_rng(), 0..WALLPAPERS.len());
WALLPAPERS.get(random_value)
use nanorand::{ChaCha20, Rng};
use std::ops::Range;
let range = Range {
start: 0,
end: WALLPAPERS.len(),
};
WALLPAPERS.get(ChaCha20::new().generate_range(range))
}
pub fn find(filename: &str) -> Option<&'static Wallpaper> {
WALLPAPERS.iter().find(|w| w.filename.contains(filename))
}
}

View file

@ -1,4 +1,4 @@
use leptos::*;
use leptos::prelude::*;
use tailwind_fuse::tw_join;
#[derive(Clone, Copy, PartialEq)]
@ -15,8 +15,8 @@ pub enum Icon {
Map,
}
impl IntoView for Icon {
fn into_view(self) -> View {
impl IntoAny for Icon {
fn into_any(self) -> AnyView {
match self {
Self::Email => view! {
<svg
@ -33,7 +33,7 @@ impl IntoView for Icon {
d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"
></path>
</svg>
}.into_view(),
}.into_any(),
Self::Link => view! {
<svg
@ -45,7 +45,7 @@ impl IntoView for Icon {
<path d="M12.232 4.232a2.5 2.5 0 013.536 3.536l-1.225 1.224a.75.75 0 001.061 1.06l1.224-1.224a4 4 0 00-5.656-5.656l-3 3a4 4 0 00.225 5.865.75.75 0 00.977-1.138 2.5 2.5 0 01-.142-3.667l3-3z"></path>
<path d="M11.603 7.963a.75.75 0 00-.977 1.138 2.5 2.5 0 01.142 3.667l-3 3a2.5 2.5 0 01-3.536-3.536l1.225-1.224a.75.75 0 00-1.061-1.06l-1.224 1.224a4 4 0 105.656 5.656l3-3a4 4 0 00-.225-5.865z"></path>
</svg>
}.into_view(),
}.into_any(),
Self::Calendar => view! {
<svg
@ -60,7 +60,7 @@ impl IntoView for Icon {
clip-rule="evenodd"
></path>
</svg>
}.into_view(),
}.into_any(),
Self::Location => view! {
<svg
@ -75,7 +75,7 @@ impl IntoView for Icon {
clip-rule="evenodd"
></path>
</svg>
}.into_view(),
}.into_any(),
Icon::Twitter => view! {
<svg
class=tw_join!("w-6", "h-6", "fill-current", "mr-0", "sm:mr-2")
@ -84,7 +84,7 @@ impl IntoView for Icon {
>
<path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"></path>
</svg>
}.into_view(),
}.into_any(),
Icon::Telegram => view! {
<svg
class=tw_join!("w-6", "h-6", "fill-current", "mr-0", "sm:mr-2")
@ -93,7 +93,7 @@ impl IntoView for Icon {
>
<path d="M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z"></path>
</svg>
}.into_view(),
}.into_any(),
Icon::Mastodon => view! {
<svg
class=tw_join!("w-6", "h-6", "fill-current", "mr-0", "sm:mr-2")
@ -102,7 +102,7 @@ impl IntoView for Icon {
>
<path d="M23.268 5.313c-.35-2.578-2.617-4.61-5.304-5.004C17.51.242 15.792 0 11.813 0h-.03c-3.98 0-4.835.242-5.288.309C3.882.692 1.496 2.518.917 5.127.64 6.412.61 7.837.661 9.143c.074 1.874.088 3.745.26 5.611.118 1.24.325 2.47.62 3.68.55 2.237 2.777 4.098 4.96 4.857 2.336.792 4.849.923 7.256.38.265-.061.527-.132.786-.213.585-.184 1.27-.39 1.774-.753a.057.057 0 0 0 .023-.043v-1.809a.052.052 0 0 0-.02-.041.053.053 0 0 0-.046-.01 20.282 20.282 0 0 1-4.709.545c-2.73 0-3.463-1.284-3.674-1.818a5.593 5.593 0 0 1-.319-1.433.053.053 0 0 1 .066-.054c1.517.363 3.072.546 4.632.546.376 0 .75 0 1.125-.01 1.57-.044 3.224-.124 4.768-.422.038-.008.077-.015.11-.024 2.435-.464 4.753-1.92 4.989-5.604.008-.145.03-1.52.03-1.67.002-.512.167-3.63-.024-5.545zm-3.748 9.195h-2.561V8.29c0-1.309-.55-1.976-1.67-1.976-1.23 0-1.846.79-1.846 2.35v3.403h-2.546V8.663c0-1.56-.617-2.35-1.848-2.35-1.112 0-1.668.668-1.67 1.977v6.218H4.822V8.102c0-1.31.337-2.35 1.011-3.12.696-.77 1.608-1.164 2.74-1.164 1.311 0 2.302.5 2.962 1.498l.638 1.06.638-1.06c.66-.999 1.65-1.498 2.96-1.498 1.13 0 2.043.395 2.74 1.164.675.77 1.012 1.81 1.012 3.12z"></path>
</svg>
}.into_view(),
}.into_any(),
Icon::Github => view! {
<svg
class=tw_join!("w-6", "h-6", "fill-current", "mr-0", "sm:mr-2")
@ -111,7 +111,7 @@ impl IntoView for Icon {
>
<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"></path>
</svg>
}.into_view(),
}.into_any(),
Icon::Linkedin => view! {
<svg
class=tw_join!("w-6", "h-6", "fill-current", "mr-0", "sm:mr-2")
@ -120,7 +120,7 @@ impl IntoView for Icon {
>
<path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"></path>
</svg>
}.into_view(),
}.into_any(),
Icon::Map => view! {
<svg
class=tw_join!("w-5", "h-5")
@ -134,7 +134,7 @@ impl IntoView for Icon {
clip-rule="evenodd"
></path>
</svg>
}.into_view(),
}.into_any(),
}
}
}

View file

@ -1,53 +1,55 @@
use http::Uri;
use leptos::*;
use tailwind_fuse::tw_join;
use crate::Icon;
use crate::prelude::*;
use rocket::http::uri::Uri;
use tailwind_fuse::tw_merge;
#[derive(Clone, PartialEq)]
pub struct Link {
pub struct Link<'a> {
pub label: String,
pub uri: Uri,
pub uri: Uri<'a>,
}
impl Link {
pub fn new(uri: &'static str, label: impl Into<String>) -> Self {
impl<'a> Link<'a> {
pub fn new(uri: Uri<'a>, label: impl Into<String>) -> Self {
Self {
uri: Uri::from_static(uri),
uri,
label: label.into(),
}
}
pub fn slides(uri: &'static str) -> Self {
pub fn parse(uri: &'static str, label: impl Into<String>) -> Self {
Self {
uri: Uri::parse_any(uri).expect("not a real uri"),
label: label.into(),
}
}
pub fn slides(uri: Uri<'a>) -> Self {
Self::new(uri, "Slides")
}
}
#[component]
pub fn UnderlineLink(
#[prop(into)] link: MaybeSignal<Link>,
#[prop(into, optional)] class: MaybeSignal<String>,
#[prop(attrs)] attributes: Vec<(&'static str, Attribute)>,
pub fn underline_link(
link: Link,
class: Option<String>,
) -> impl IntoView {
let class = tailwind_fuse::tw_merge!("underline", class.get());
let class = class.unwrap_or_default();
let class = tw_merge!("underline", class);
view! {
<a href=link.get().uri.to_string() {..attributes} class=class target="_blank">
{link.get().label}
<a href=link.uri.to_string() class=class>
{link.label}
</a>
}
.into_view()
}
type HideTextSmallDisplay = bool;
#[component]
pub fn ButtonLink(
#[prop(into)] link: MaybeSignal<Link>,
#[prop(into, optional)] icon: Option<MaybeSignal<Icon>>,
#[prop(into, optional)] hide_text_small_display: Option<MaybeSignal<HideTextSmallDisplay>>,
#[prop(attrs)] attributes: Vec<(&'static str, Attribute)>,
) -> impl IntoView {
pub fn button_link(
link: Link,
icon: Option<Icon>,
hide_text_small_display: Option<HideTextSmallDisplay>,
) -> impl IntoAny {
let text_css = hide_text_small_display
.and_then(|hide| {
if hide.get() {
if hide {
Some(tw_join!("hidden", "sm:inline"))
} else {
None
@ -55,11 +57,14 @@ pub fn ButtonLink(
})
.unwrap_or(tw_join!("ml-2", "sm:ml-0", "text-center"));
let icon = icon
.map(|icon| icon.into_any())
.unwrap_or_else(|| ().into_any());
view! {
<a
href=link.get().uri.to_string()
{..attributes}
aria-label=link.get().label
href=link.uri.to_string()
aria-label=link.label.to_string()
class=tw_join!(
"inline-flex", "bg-sky-900", "hover:bg-sky-700", "transition-all", "duration-200",
"text-white", "font-bold", "py-2", "px-4", "rounded-xl", "items-center"
@ -68,21 +73,19 @@ pub fn ButtonLink(
{icon}
<div class=tw_join!("inline-flex", "items-center")>
<span class=text_css>{link.get().label}</span>
<span class=text_css>{link.label.to_string()}</span>
</div>
</a>
}
.into_any()
}
#[component]
pub fn OutlineButtonLink(
#[prop(into)] link: MaybeSignal<Link>,
#[prop(attrs)] attributes: Vec<(&'static str, Attribute)>,
) -> impl IntoView {
pub fn outline_button_link(
link: Link,
) -> impl IntoAny {
view! {
<a
href=link.get().uri.to_string()
{..attributes}
href=link.uri.to_string()
class=tw_join!(
"mt-4", "inline-flex", "bg-transparent", "hover:bg-sky-700", "text-white",
"font-semibold", "py-1.5", "px-4", "rounded-xl", "items-center", "border",
@ -90,10 +93,11 @@ pub fn OutlineButtonLink(
)
>
{Icon::Link}
{Icon::Link.into_any()}
<div class=tw_join!("inline-flex", "items-center")>
<span class=tw_join!("ml-2", "sm:ml-0", "text-center")>{link.get().label}</span>
<span class=tw_join!("ml-2", "sm:ml-0", "text-center")>{link.label}</span>
</div>
</a>
}
.into_any()
}

View file

@ -1,83 +0,0 @@
use crate::ContentPage;
use http::status::StatusCode;
use leptos::*;
use thiserror::Error;
#[derive(Clone, Debug, Error)]
pub enum AppError {
#[error("Not Found")]
NotFound,
}
impl AppError {
pub fn status_code(&self) -> StatusCode {
match self {
AppError::NotFound => StatusCode::NOT_FOUND,
}
}
pub fn canonical_reason(&self) -> String {
match self {
AppError::NotFound => StatusCode::NOT_FOUND.to_string(),
}
}
pub fn description(&self) -> String {
match self {
AppError::NotFound => "This page could not be found.".to_string(),
}
}
}
// 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(
#[prop(optional)] outside_errors: Option<Errors>,
#[prop(optional)] errors: Option<RwSignal<Errors>>,
) -> impl IntoView {
let errors = match outside_errors {
Some(e) => create_rw_signal(e),
None => match errors {
Some(e) => e,
None => panic!("No Errors found and we expected errors!"),
},
};
// Get Errors from Signal
let errors = errors.get_untracked();
// Downcast lets us take a type that implements `std::error::Error`
let errors: Vec<AppError> = errors
.into_iter()
.filter_map(|(_k, v)| v.downcast_ref::<AppError>().cloned())
.collect();
println!("Errors: {errors:#?}");
// Only the response code for the first error is actually sent from the server
// this may be customized by the specific application
#[cfg(feature = "ssr")]
{
use leptos_axum::ResponseOptions;
let response = use_context::<ResponseOptions>();
if let Some(response) = response {
response.set_status(errors[0].status_code());
}
}
view! {
<For
// a function that returns the items we're iterating over; a signal is fine
each=move || { errors.clone().into_iter().enumerate() }
// a unique key for each item as a reference
key=|(index, _error)| *index
// renders each item to a view
children=move |error| {
view! {
<ContentPage title=error.1.canonical_reason()>
<p>{error.1.description()}</p>
</ContentPage>
}
}
/>
}
}

View file

@ -1,42 +0,0 @@
use axum::{
body::Body,
extract::State,
response::IntoResponse,
http::{Request, Response, StatusCode, Uri},
};
use axum::response::Response as AxumResponse;
use tower::ServiceExt;
use tower_http::services::ServeDir;
use leptos::*;
use crate::app::App;
pub async fn file_and_error_handler(uri: Uri, State(options): State<LeptosOptions>, req: Request<Body>) -> AxumResponse {
let root = options.site_root.clone();
let res = get_static_file(uri.clone(), &root).await.unwrap();
if res.status() == StatusCode::OK {
res.into_response()
} else {
let handler = leptos_axum::render_app_to_stream(options.to_owned(), App);
handler(req).await.into_response()
}
}
async fn get_static_file(
uri: Uri,
root: &str,
) -> Result<Response<Body>, (StatusCode, String)> {
let req = Request::builder()
.uri(uri.clone())
.body(Body::empty())
.unwrap();
// `ServeDir` implements `tower::Service` so we can call it with `tower::ServiceExt::oneshot`
// This path is relative to the cargo root
match ServeDir::new(root).oneshot(req).await {
Ok(res) => Ok(res.into_response()),
Err(err) => Err((
StatusCode::INTERNAL_SERVER_ERROR,
format!("Something went wrong: {err}"),
)),
}
}

View file

@ -1,45 +0,0 @@
use leptos::*;
use prelude::*;
pub mod app;
pub mod common;
pub mod error_template;
#[cfg(feature = "ssr")]
pub mod fileserv;
pub mod pages;
#[cfg(feature = "hydrate")]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn hydrate() {
use crate::app::*;
console_error_panic_hook::set_once();
mount_to_body(App);
}
pub mod prelude {
pub use super::ContentPage;
pub use crate::common::icon::*;
pub use crate::common::link::*;
pub use crate::common::resume::*;
pub use crate::common::wallpapers::*;
pub use crate::common::*;
pub use leptos::*;
pub use leptos_meta::*;
pub use tailwind_fuse::tw_join;
pub use http::Uri;
}
#[component]
pub fn ContentPage(
#[prop(into, optional)] title: MaybeSignal<String>,
children: Children,
) -> impl IntoView {
view! {
<leptos_meta::Title text=title.get()></leptos_meta::Title>
<div class=tw_join!("container", "mx-auto", "px-4", "py-16")>
<h1 class=tw_join!("text-3xl", "sm:text-4xl", "font-bold")>{title}</h1>
<UnderlineLink link=Link::new("/", "← Home")/>
<div class=tw_join!("mt-8")>{children()}</div>
</div>
}
}

View file

@ -1,38 +1,44 @@
#[cfg(feature = "ssr")]
#[tokio::main]
async fn main() {
use axum::Router;
use leptos::*;
use leptos_axum::{generate_route_list, LeptosRoutes};
use plcom::app::*;
use plcom::fileserv::file_and_error_handler;
// Setting get_configuration(None) means we'll be using cargo-leptos's env values
// For deployment these variables are:
// <https://github.com/leptos-rs/start-axum#executing-a-server-on-a-remote-machine-without-the-toolchain>
// Alternately a file can be specified such as Some("Cargo.toml")
// The file would need to be included with the executable when moved to deployment
let conf = get_configuration(None).await.unwrap();
let leptos_options = conf.leptos_options;
let addr = leptos_options.site_addr;
let routes = generate_route_list(App);
// build our application with a route
let app = Router::new()
.leptos_routes(&leptos_options, routes, App)
.fallback(file_and_error_handler)
.with_state(leptos_options);
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
logging::log!("listening on http://{}", &addr);
axum::serve(listener, app.into_make_service())
.await
.unwrap();
mod prelude {
pub use crate::common::icon::Icon;
pub use crate::common::link::*;
pub use crate::common::Date;
pub use crate::views::*;
pub use leptos::prelude::*;
pub use rocket::uri;
pub use tailwind_fuse::tw_join;
}
#[cfg(not(feature = "ssr"))]
pub fn main() {
// no client-side main function
// unless we want this to work with e.g., Trunk for a purely client-side app
// see lib.rs for hydration function instead
mod cache;
mod common;
mod pages;
mod views;
use pages::*;
#[rocket::launch]
fn rocket() -> _ {
let server = rocket::build()
.mount("/", rocket::fs::FileServer::from("public"))
.mount(
"/",
rocket::routes![root_route, email_route, wallpapers_route],
)
.register("/", rocket::catchers![not_found]);
if cfg!(debug_assertions) {
server
} else {
server
.attach(
rocket_async_compression::CachedCompression::path_suffix_fairing(vec![
// Code
".js".into(),
".css".into(),
// Documents
".pdf".into(),
".txt".into(),
]),
)
.attach(cache::CacheControl::default())
}
}

View file

@ -1,7 +1,47 @@
pub mod root;
pub mod email;
pub mod wallpapers;
mod email;
mod root;
mod wallpapers;
pub use root::RootPage;
pub use email::EmailPage;
pub use wallpapers::WallpapersPage;
use crate::common::wallpapers::Wallpaper;
use crate::prelude::*;
use rocket::get;
#[derive(rocket::Responder)]
#[response(content_type = "text/html")]
pub struct LeptosResponder(String);
impl From<AnyView> for LeptosResponder {
fn from(value: AnyView) -> Self {
Self(value.to_html())
}
}
#[rocket::catch(404)]
pub fn not_found() -> LeptosResponder {
content_page(
"404 Not Found",
view! {
<div>"This page could not be found."</div>
},
)
.into()
}
#[get("/?<wallpaper>")]
pub fn root_route(wallpaper: Option<&str>) -> LeptosResponder {
let wallpaper = wallpaper
.and_then(Wallpaper::find)
.or_else(Wallpaper::random);
shell("Philippe Loctaux", root::root_page(wallpaper)).into()
}
#[get("/email")]
pub fn email_route() -> LeptosResponder {
content_page("Email", email::email_page()).into()
}
#[get("/wallpapers")]
pub fn wallpapers_route() -> LeptosResponder {
content_page("Wallpapers", wallpapers::wallpapers_page()).into()
}

View file

@ -1,37 +1,29 @@
use crate::prelude::*;
#[component]
pub fn EmailPage() -> impl IntoView {
pub fn email_page() -> impl IntoAny {
view! {
<ContentPage title="Email">
<p>
"Send an email if you want to work with me, propose a project idea, or just to say hi!"
</p>
<div class=tw_join!("my-4")>
<ButtonLink
link=Link::new(
"mailto:wwwATphilippeloctaux~DOT~com",
{button_link(Link::new(
uri!("mailto:wwwATphilippeloctaux~DOT~com").into(),
"www at philippeloctaux dot com",
)
icon=Icon::Email
/>
), Some(Icon::Email), None).into_any()}
</div>
<p class=tw_join!(
"mb-2"
)>
"If you want to encrypt your message, I have a "
<UnderlineLink link=Link::new("/pub/pgp-0x69771CD04BA82EC0.txt", "pgp key")/>
{underline_link(Link::new(uri!("/pub/pgp-0x69771CD04BA82EC0.txt").into(), "pgp key"), None).into_any()}
" at your disposal."
</p>
<p class=tw_join!(
"mb-2"
)>
"I also have a " <UnderlineLink link=Link::new("/keybase.txt", "Keybase")/>
"I also have a "{underline_link(Link::new(uri!("/keybase.txt").into(), "Keybase"), None).into_any()}
" account, but I do not check it often."
</p>
</ContentPage>
}
}.into_any()
}

View file

@ -1,38 +1,35 @@
use crate::prelude::*;
mod hero;
mod www;
mod education;
mod experience;
mod friends;
mod hero;
mod jobs;
mod projects;
mod education;
mod talks;
mod friends;
mod www;
#[component]
pub fn RootPage() -> impl IntoView {
let random_wallpaper = Wallpaper::random();
use crate::common::wallpapers::Wallpaper;
use crate::prelude::*;
pub fn root_page(wallpaper: Option<&'static Wallpaper>) -> impl IntoAny {
view! {
<Title text="Hello"/>
<hero::Hero wallpaper=random_wallpaper></hero::Hero>
{hero::hero(wallpaper).into_any()}
<div class=tw_join!("container", "mx-auto", "px-4", "md:px-8", "lg:px-16", "py-16")>
<Whoami/>
{whoami}
<div class=tw_join!("my-16", "space-y-16", "md:space-y-32")>
<www::Www></www::Www>
<jobs::Jobs></jobs::Jobs>
<projects::Projects></projects::Projects>
<education::EducationList></education::EducationList>
<talks::Talks></talks::Talks>
<friends::Friends></friends::Friends>
{www::list().into_any()}
{jobs::jobs().into_any()}
{projects::projects().into_any()}
{education::education_list().into_any()}
{talks::talks().into_any()}
{friends::friends().into_any()}
</div>
</div>
}
.into_any()
}
#[component]
fn Whoami() -> impl IntoView {
fn whoami() -> impl IntoView {
view! {
<div class=tw_join!("md:flex", "md:flex-row-reverse", "items-center")>
<div class=tw_join!("md:w-1/2", "mb-4", "md:mb-0")>

View file

@ -1,8 +1,9 @@
use crate::prelude::*;
use super::experience::*;
use crate::common::resume::{self, Education};
use crate::prelude::*;
impl IntoView for Education {
fn into_view(self) -> View {
impl IntoAny for Education {
fn into_any(self) -> AnyView {
let subtitle = format!("{} in {}", self.study_type, self.area);
view! {
<div class=tw_join!(
@ -15,7 +16,7 @@ impl IntoView for Education {
self.institution,
&subtitle,
self.logo.as_ref(),
)}
).into_any()}
<div class=tw_join!("space-y-2")>
<ul class=tw_join!(
"list-disc", "mt-6"
@ -31,12 +32,12 @@ impl IntoView for Education {
</div>
</div>
}.into_view()
}
.into_any()
}
}
#[component]
pub fn EducationList() -> impl IntoView {
pub fn education_list() -> impl IntoView {
view! {
<div>
@ -44,8 +45,7 @@ pub fn EducationList() -> impl IntoView {
<div class=tw_join!(
"mt-4", "grid", "grid-cols-1", "md:grid-cols-2", "gap-6", "place-content-center"
)>{resume::EDUCATION.collect_view()}</div>
)>{resume::EDUCATION.map(|education| education.into_any()).collect_view()}</div>
</div>
}
}

View file

@ -1,7 +1,6 @@
use tailwind_fuse::*;
use leptos::*;
use crate::common::Date;
use crate::common::resume::Logo;
use crate::prelude::*;
use tailwind_fuse::*;
#[derive(TwClass, Clone, Copy, PartialEq)]
#[tw(class = r#"h-16 w-16 rounded-xl"#)]
@ -17,24 +16,17 @@ enum ImageBackground {
Plain,
}
#[component]
fn ExperienceLogo(
#[prop(into)] image: MaybeSignal<String>,
/// Name of the experience, used in the alt of the image
#[prop(into)]
name: MaybeSignal<String>,
#[prop(into, optional)] background: MaybeSignal<ImageBackground>,
#[prop(into, optional)] class: MaybeSignal<String>,
#[prop(attrs)] attributes: Vec<(&'static str, Attribute)>,
fn experience_logo(
image: String,
// Name of the experience, used in the alt of the image
name: String,
background: ImageBackground,
class: String,
) -> impl IntoView {
let class = create_memo(move |_| {
let background = background.get();
let logo = LogoOptions { background };
logo.with_class(class.get())
});
let alt = format!("{} logo", name.get());
let class = LogoOptions { background }.with_class(class);
let alt = format!("{} logo", name);
view! { <img {..attributes} loading="lazy" src=image.get() alt=alt class=class/> }
view! { <img loading="lazy" src=image alt=alt class=class/> }
}
struct ExperienceLogo {
@ -50,19 +42,17 @@ pub struct ExperienceHeader {
logo: Option<ExperienceLogo>,
}
impl IntoView for ExperienceHeader {
fn into_view(self) -> View {
impl IntoAny for ExperienceHeader {
fn into_any(self) -> AnyView {
let logo = match self.logo {
Some(logo) => view! {
<ExperienceLogo
image=logo.file
name=self.name.clone()
background=logo.options.map(|o| o.background).unwrap_or_default()
class=tw_join!("mr-4")
/>
}
.into_view(),
None => view! {}.into_view(),
Some(logo) => experience_logo(
logo.file,
self.name.clone(),
logo.options.map(|o| o.background).unwrap_or_default(),
tw_join!("mr-4"),
)
.into_any(),
None => ().into_any(),
};
let date = match self.date_end {
@ -87,7 +77,7 @@ impl IntoView for ExperienceHeader {
)>{self.description}</p>
</div>
}
.into_view()
.into_any()
}
}

View file

@ -1,4 +1,5 @@
use crate::prelude::*;
use rocket::http::uri::Absolute;
#[derive(Clone, PartialEq)]
struct Name {
@ -51,21 +52,21 @@ impl std::fmt::Display for Name {
#[derive(Clone, PartialEq)]
struct Friend {
name: Name,
uri: Uri,
uri: Absolute<'static>,
}
impl Friend {
pub fn nick(nick: impl Into<String>, uri: &'static str) -> Self {
pub fn nick(nick: impl Into<String>, uri: Absolute<'static>) -> Self {
Self {
name: Name::nick(nick),
uri: Uri::from_static(uri),
uri,
}
}
pub fn new(first: impl Into<String>, last: impl Into<String>, uri: &'static str) -> Self {
pub fn new(first: impl Into<String>, last: impl Into<String>, uri: Absolute<'static>) -> Self {
Self {
name: Name::new(first, last),
uri: Uri::from_static(uri),
uri,
}
}
@ -77,12 +78,11 @@ impl Friend {
}
}
#[component]
fn Friend(#[prop(into)] friend: MaybeSignal<Friend>) -> impl IntoView {
impl IntoAny for Friend {
fn into_any(self) -> AnyView {
view! {
<a
href=friend.get().uri.to_string()
target="_blank"
href=self.uri.to_string()
class=tw_join!(
"hover:bg-gray-500", "transition-all", "duration-200", "flex", "items-center",
"rounded-lg", "p-2"
@ -92,30 +92,31 @@ fn Friend(#[prop(into)] friend: MaybeSignal<Friend>) -> impl IntoView {
<span class=tw_join!(
"rounded-full", "flex-shrink-0", "mr-4", "w-10", "h-10", "bg-sky-900", "text-white",
"flex", "items-center", "justify-center", "text-lg", "font-medium"
)>{friend.get().name.initials()}</span>
)>{self.name.initials()}</span>
<div>
<p class=tw_join!("font-bold")>{friend.get().name.to_string()}</p>
<p>{friend.get().domain_name()}</p>
<p class=tw_join!("font-bold")>{self.name.to_string()}</p>
<p>{self.domain_name()}</p>
</div>
</a>
}
.into_any()
}
}
#[component]
pub fn Friends() -> impl IntoView {
pub fn friends() -> impl IntoView {
let friends = [
Friend::new("Paolo", "Rotolo", "https://rotolo.dev"),
Friend::new("Polly", "Bishop", "https://github.com/itspolly"),
Friend::new("Ayden", "Panhuyzen", "https://ayden.dev"),
Friend::new("Corbin", "Crutchley", "https://crutchcorn.dev"),
Friend::new("James", "Fenn", "https://jfenn.me"),
Friend::new("Alex", "Dueppen", "https://ajd.sh"),
Friend::new("Lyra", "Messier", "https://lyramsr.co"),
Friend::new("Peter", "Soboyejo", "https://twitter.com/pxtvr"),
Friend::nick("Millomaker", "https://youtube.com/millomaker"),
Friend::new("Alexandre", "Wagner", "https://dev4people.fr"),
Friend::new("Aidan", "Follestad", "https://af.codes"),
Friend::new("Victor", "Simon", "https://simonvictor.com"),
Friend::new("Paolo", "Rotolo", uri!("https://rotolo.dev")),
Friend::new("Polly", "Bishop", uri!("https://github.com/itspolly")),
Friend::new("Ayden", "Panhuyzen", uri!("https://ayden.dev")),
Friend::new("Corbin", "Crutchley", uri!("https://crutchcorn.dev")),
Friend::new("James", "Fenn", uri!("https://jfenn.me")),
Friend::new("Alex", "Dueppen", uri!("https://ajd.sh")),
Friend::new("Lyra", "Messier", uri!("https://lyramsr.co")),
Friend::new("Peter", "Soboyejo", uri!("https://twitter.com/pxtvr")),
Friend::nick("Millomaker", uri!("https://youtube.com/millomaker")),
Friend::new("Alexandre", "Wagner", uri!("https://dev4people.fr")),
Friend::new("Aidan", "Follestad", uri!("https://af.codes")),
Friend::new("Victor", "Simon", uri!("https://simonvictor.com")),
];
view! {
@ -129,10 +130,10 @@ pub fn Friends() -> impl IntoView {
)>
{friends
.into_iter()
.map(|f| {
.map(|friend| {
view! {
<li class=tw_join!("py-2")>
<Friend friend=f/>
{friend.into_any()}
</li>
}
})

View file

@ -1,7 +1,7 @@
use crate::common::wallpapers::Wallpaper;
use crate::prelude::*;
#[component]
fn WallpaperInfo(#[prop(into)] wallpaper: &'static Wallpaper) -> impl IntoView {
fn wallpaper_info(wallpaper: &'static Wallpaper) -> impl IntoAny {
view! {
<div class=tw_join!(
"absolute", "bottom-3", "sm:bottom-5", "left-2", "sm:left-5", "inline-block",
@ -14,11 +14,10 @@ fn WallpaperInfo(#[prop(into)] wallpaper: &'static Wallpaper) -> impl IntoView {
<div class=tw_join!(
"inline-flex", "items-center"
)>
{Icon::Map}
{Icon::Map.into_any()}
<a
class=tw_join!("ml-1", "text-sm", "underline")
href="/wallpapers"
target="_blank"
>
"See more!"
</a>
@ -30,7 +29,7 @@ fn WallpaperInfo(#[prop(into)] wallpaper: &'static Wallpaper) -> impl IntoView {
<div class=tw_join!(
"inline-flex", "items-center"
)>
{Icon::Location}
{Icon::Location.into_any()}
<span class=tw_join!(
"ml-1", "text-sm"
)>
@ -47,22 +46,21 @@ fn WallpaperInfo(#[prop(into)] wallpaper: &'static Wallpaper) -> impl IntoView {
<div class=tw_join!(
"inline-flex", "items-center"
)>
{Icon::Calendar} <span class=tw_join!("ml-1", "text-sm")>{wallpaper.date}</span>
{Icon::Calendar.into_any()} <span class=tw_join!("ml-1", "text-sm")>{wallpaper.date}</span>
</div>
</div>
</div>
}
}.into_any()
}
#[component]
pub fn Hero(#[prop(into)] wallpaper: Option<&'static Wallpaper>) -> impl IntoView {
pub fn hero(wallpaper: Option<&'static Wallpaper>) -> impl IntoAny {
let (wallpaper_info, background_image) = match wallpaper {
Some(wallpaper) => (
view! { <WallpaperInfo wallpaper=wallpaper/> }.into_view(),
wallpaper_info(wallpaper).into_any(),
format!("background-image: url(/wallpapers/{});", wallpaper.filename),
),
None => (view! {}.into_view(), "".into()),
None => (().into_any(), "".to_string()),
};
view! {

View file

@ -1,8 +1,14 @@
use crate::prelude::*;
use super::experience::*;
use crate::common::resume::{self, Work};
use crate::prelude::*;
impl IntoAny for Work {
fn into_any(self) -> AnyView {
let link = match self.link {
Some(link) => link.into_any(),
None => ().into_any(),
};
impl IntoView for Work {
fn into_view(self) -> View {
view! {
<div class=tw_join!("w-full", "rounded-2xl", "bg-sky-950")>
@ -16,7 +22,7 @@ impl IntoView for Work {
self.name,
self.position,
Some(&self.logo),
)} <div class=tw_join!("space-y-2")>
).into_any()} <div class=tw_join!("space-y-2")>
<p>{self.description}</p>
@ -53,24 +59,22 @@ impl IntoView for Work {
</div>
</div>
</div> {self.link}
</div> {link}
</div>
</div>
}.into_view()
}.into_any()
}
}
#[component]
pub fn Jobs() -> impl IntoView {
pub fn jobs() -> impl IntoView {
view! {
<div>
<h1 class=tw_join!("text-4xl", "font-bold", "mb-4")>"Professional Experiences"</h1>
<div class=tw_join!(
"mt-4", "grid", "grid-cols-1", "sm:grid-cols-2", "gap-4"
)>{resume::WORK.collect_view()}</div>
)>{resume::WORK.map(|work| work.into_any()).collect_view()}</div>
</div>
}
}

View file

@ -1,8 +1,9 @@
use crate::prelude::*;
use super::experience::*;
use crate::common::resume::{self, Project};
use crate::prelude::*;
impl IntoView for Project {
fn into_view(self) -> View {
impl IntoAny for Project {
fn into_any(self) -> AnyView {
let (css_image_position, css_image_position_corner) = match self.image {
Some(image) => {
let position = match image.position {
@ -33,6 +34,11 @@ impl IntoView for Project {
None => ("".into(), "".into()),
};
let link = match self.link {
Some(link) => link.into_any(),
None => ().into_any(),
};
view! {
<div class=tw_join!(
"w-full", "rounded-2xl", "bg-pink-950", css_image_position
@ -47,9 +53,9 @@ impl IntoView for Project {
class=css_image_position_corner
/>
}
.into_view()
.into_any()
} else {
view! {}.into_view()
().into_any()
}}
<div class=tw_join!(
"p-6", "justify-between", "h-full"
@ -61,7 +67,7 @@ impl IntoView for Project {
self.name,
self.description,
self.logo.as_ref(),
)}
).into_any()}
<div class=tw_join!(
"space-y-2"
)>
@ -70,7 +76,7 @@ impl IntoView for Project {
.presentation
.iter()
.map(|p| {
view! { <p>{*p}</p> }
view! { <p>{*p}</p> }.into_any()
})
.collect_view()} <div>
<ul class=tw_join!(
@ -80,7 +86,7 @@ impl IntoView for Project {
.highlights
.iter()
.map(|h| {
view! { <li class=tw_join!("ml-5")>{*h}</li> }
view! { <li class=tw_join!("ml-5")>{*h}</li> }.into_any()
})
.collect_view()}
</ul>
@ -99,47 +105,51 @@ impl IntoView for Project {
"items-center", "rounded-md", "bg-blue-100", "px-2", "py-1",
"font-medium", "text-blue-700",
)>{*t}</span>
}
}.into_any()
})
.collect_view()}
</div>
</div>
</div> {self.link}
</div> {link}
</div>
</div>
}.into_view()
}.into_any()
}
}
type ImageProject = Project;
type TextProject = Project;
type ImageProject = Project;
type TextProject = Project;
enum DisplayProject {
enum DisplayProject {
Text(Box<(TextProject, Option<TextProject>)>),
Image(ImageProject)
}
Image(ImageProject),
}
impl IntoView for DisplayProject {
fn into_view(self) -> View {
impl IntoAny for DisplayProject {
fn into_any(self) -> AnyView {
match self {
Self::Image(image) => image.into_view(),
Self::Image(image) => image.into_any(),
Self::Text(boxy) => {
let (text1, text2) = *boxy;
let text2 = match text2 {
Some(text2) => text2.into_any(),
None => ().into_any(),
};
view! {
<div class=tw_join!(
"my-4", "grid", "grid-cols-1", "sm:grid-cols-2", "gap-4"
)>{text1} {text2}</div>
}.into_view()
)>{text1.into_any()} {text2}</div>
}
.into_any()
}
.into_any(),
}
}
}
#[component]
pub fn Projects() -> impl IntoView {
pub fn projects() -> impl IntoView {
let mut projects = vec![];
let mut iter = resume::PROJECTS.iter();
@ -148,7 +158,10 @@ pub fn Projects() -> impl IntoView {
projects.push(DisplayProject::Image(*cur_proj));
} else {
let next_text = iter.next();
projects.push(DisplayProject::Text(Box::new((*cur_proj, next_text.copied()))));
projects.push(DisplayProject::Text(Box::new((
*cur_proj,
next_text.copied(),
))));
}
}
@ -157,7 +170,7 @@ pub fn Projects() -> impl IntoView {
<h1 class=tw_join!("text-4xl", "font-bold", "mb-4")>"Projects"</h1>
{projects}
{projects.into_iter().map(|project| project.into_any()).collect_view()}
</div>
}
}

View file

@ -5,7 +5,7 @@ struct Talk {
title: String,
date: Date,
location: String,
link: Link,
link: Link<'static>,
}
impl Talk {
@ -13,7 +13,7 @@ impl Talk {
title: impl Into<String>,
date: Date,
location: impl Into<String>,
link: Link,
link: Link<'static>,
) -> Self {
Self {
title: title.into(),
@ -24,35 +24,35 @@ impl Talk {
}
}
#[component]
fn Talk(#[prop(into)] talk: MaybeSignal<Talk>) -> impl IntoView {
impl IntoAny for Talk {
fn into_any(self) -> AnyView {
view! {
<div class=tw_join!("rounded-2xl", "w-full", "bg-teal-950", "p-6")>
<div class=tw_join!("text-xl", "font-semibold", "mb-4")>{talk.get().title}</div>
<div class=tw_join!("text-xl", "font-semibold", "mb-4")>{self.title}</div>
<div class=tw_join!("flex")>
<div class=tw_join!(
"inline-flex", "items-center"
)>
{Icon::Calendar}
<span class=tw_join!("ml-2")>{talk.get().date.to_string()}</span>
{Icon::Calendar.into_any()}
<span class=tw_join!("ml-2")>{self.date.to_string()}</span>
</div>
</div>
<div class=tw_join!("flex")>
<div class=tw_join!(
"inline-flex", "items-center"
)>{Icon::Location} <span class=tw_join!("ml-2")>{talk.get().location}</span></div>
)>{Icon::Location.into_any()} <span class=tw_join!("ml-2")>{self.location}</span></div>
</div>
<OutlineButtonLink link=talk.get().link/>
{outline_button_link(self.link).into_any()}
</div>
}.into_any()
}
}
#[component]
pub fn Talks() -> impl IntoView {
pub fn talks() -> impl IntoAny {
let talks = [
Talk::new(
"Vim",
@ -61,7 +61,7 @@ pub fn Talks() -> impl IntoView {
month: 2,
},
"Epitech Rennes",
Link::slides("/pub/talks/vim.pdf"),
Link::slides(uri!("/pub/talks/vim.pdf").into()),
),
Talk::new(
"CLion",
@ -70,7 +70,7 @@ pub fn Talks() -> impl IntoView {
month: 3,
},
"Epitech Rennes",
Link::slides("/pub/talks/clion.pdf"),
Link::slides(uri!("/pub/talks/clion.pdf").into()),
),
Talk::new(
"git & devops 2",
@ -79,7 +79,7 @@ pub fn Talks() -> impl IntoView {
month: 2,
},
"Epitech Rennes",
Link::slides("/pub/talks/git-devops2.pdf"),
Link::slides(uri!("/pub/talks/git-devops2.pdf").into()),
),
Talk::new(
"pass4thewin",
@ -88,7 +88,7 @@ pub fn Talks() -> impl IntoView {
month: 2,
},
"Epitech Rennes",
Link::slides("/pub/talks/pass4thewin.pdf"),
Link::slides(uri!("/pub/talks/pass4thewin.pdf").into()),
),
Talk::new(
"git & devops",
@ -97,7 +97,7 @@ pub fn Talks() -> impl IntoView {
month: 5,
},
"Epitech Rennes",
Link::slides("/pub/talks/git-devops.pdf"),
Link::slides(uri!("/pub/talks/git-devops.pdf").into()),
),
Talk::new(
"git gud",
@ -106,7 +106,7 @@ pub fn Talks() -> impl IntoView {
month: 5,
},
"Epitech Rennes",
Link::slides("/pub/talks/git-tek.pdf"),
Link::slides(uri!("/pub/talks/git-tek.pdf").into()),
),
];
@ -123,15 +123,9 @@ pub fn Talks() -> impl IntoView {
"mt-4", "grid", "grid-cols-1", "sm:grid-cols-2", "lg:grid-cols-3", "gap-6",
"place-content-center"
)>
{talks
.into_iter()
.map(|t| {
view! { <Talk talk=t/> }
})
.collect_view()}
{talks.into_iter().map(|talk| talk.into_any()).collect_view()}
</div>
</div>
}
}

View file

@ -1,36 +1,54 @@
use crate::prelude::*;
#[derive(Clone, PartialEq)]
struct Www {
link: Link,
pub struct Www {
link: Link<'static>,
icon: Icon,
}
#[component]
pub fn Www() -> impl IntoView {
impl IntoAny for Www {
fn into_any(self) -> AnyView {
view! {
<div class=tw_join!("w-full", "h-auto", "md:w-auto")>
<div class=tw_join!("text-center")>
{button_link(self.link, Some(self.icon), Some(true)).into_any()}
</div>
</div>
}
.into_any()
}
}
pub fn list() -> impl IntoAny {
let www = [
Www {
link: Link::new("https://twitter.com/philippeloctaux", "Twitter"),
link: Link::new(
uri!("https://twitter.com/philippeloctaux").into(),
"Twitter",
),
icon: Icon::Twitter,
},
Www {
link: Link::new("https://t.me/philippeloctaux", "Telegram"),
link: Link::new(uri!("https://t.me/philippeloctaux").into(), "Telegram"),
icon: Icon::Telegram,
},
Www {
link: Link::new("https://mastodon.social/@philt3r", "Mastodon"),
link: Link::new(uri!("https://mastodon.social/@philt3r").into(), "Mastodon"),
icon: Icon::Mastodon,
},
Www {
link: Link::new("https://github.com/deadbaed", "GitHub"),
link: Link::new(uri!("https://github.com/deadbaed").into(), "GitHub"),
icon: Icon::Github,
},
Www {
link: Link::new("https://linkedin.com/in/philippeloctaux", "LinkedIn"),
link: Link::new(
uri!("https://linkedin.com/in/philippeloctaux").into(),
"LinkedIn",
),
icon: Icon::Linkedin,
},
Www {
link: Link::new("/email", "Email"),
link: Link::new(uri!("/email").into(), "Email"),
icon: Icon::Email,
},
];
@ -39,27 +57,9 @@ pub fn Www() -> impl IntoView {
"grid", "grid-cols-3", "lg:grid-cols-6", "gap-4", "place-content-center"
)>
{www
.into_iter()
.map(|w| {
view! {
<div class=tw_join!("w-full", "h-auto", "md:w-auto")>
<div class=tw_join!("text-center")>
<ButtonLink
link=w.link
icon=w.icon
hide_text_small_display=true
attributes=vec![
("target", Attribute::String(Oco::Borrowed("_blank"))),
]
/>
</div>
</div>
}
})
.collect_view()}
{www.into_iter().map(|w| {w.into_any()}).collect_view()}
</div>
}
.into_any()
}

View file

@ -1,49 +1,37 @@
use crate::common::wallpapers::WALLPAPERS;
use crate::prelude::*;
#[component]
pub fn WallpapersPage() -> impl IntoView {
use leptos_leaflet::{TileLayer, MapContainer, Position, Marker, position, Popup};
let wallpapers = WALLPAPERS;
pub fn wallpapers_page() -> impl IntoAny {
let wallpaper_markers = WALLPAPERS
.iter()
.map(|wallpaper| {
format!(
r#"L.marker({}).addTo(map).bindPopup(`<p>{}<br>{}<br><b>{}</b></p><a href="/?wallpaper={}">Use as wallpaper</a>`);"#,
wallpaper.gps,
wallpaper.location.precise,
wallpaper.location.broad,
wallpaper.date,
wallpaper.filename,
)
})
.collect::<Vec<String>>()
.join("\n");
view! {
<ContentPage title="Wallpapers">
<Stylesheet href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
<Script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"/>
<p class=tw_join!("mb-2")>"Pictures I took around the world"</p>
<MapContainer
center=Position::new(0.0, 0.0)
zoom=1.0
class=tw_join!("w-full", "h-halfscreen")
>
<TileLayer
url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution="&copy; <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"
/>
<For
each=move || wallpapers
key=|w| w.filename
children=move |w: Wallpaper| {
let uri = format!("/wallpapers/{}", w.filename);
view! {
<Marker position=position!(
w.gps.latitude.into(), w.gps.longitude.into()
)>
<Popup>
<a target="_blank" href=uri>
{w.location.precise}
</a>
<br/>
{w.location.broad}
<br/>
<b>{w.date}</b>
</Popup>
</Marker>
}
}
/>
</MapContainer>
</ContentPage>
}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<div id="map" class="w-full h-halfscreen"></div>
<script inner_html=r#"
let map = L.map('map').setView([48.858288, 2.294442], 2);
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
"#></script>
<script inner_html=wallpaper_markers></script>
}.into_any()
}

63
crates/plcom/src/views.rs Normal file
View file

@ -0,0 +1,63 @@
use crate::prelude::*;
pub fn shell(title: &str, children: impl IntoAny) -> AnyView {
const SUFFIX: &str = "Philippe Loctaux";
let title = if title != SUFFIX {
format!("{title} - {SUFFIX}")
} else {
title.into()
};
let year = jiff::Zoned::now().year();
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width"/>
<link rel="stylesheet" href="/style.css" />
<title>{title}</title>
// favicon
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"/>
<link rel="icon" type_="image/png" sizes="32x32" href="/favicon-32x32.png"/>
<link rel="icon" type_="image/png" sizes="16x16" href="/favicon-16x16.png"/>
<link rel="manifest" href="/site.webmanifest"/>
<link
rel="mask-icon"
href="/safari-pinned-tab.svg"
color="#0c4a6e"
/>
<meta name="msapplication-TileColor" content="#0c4a6e"/>
<meta name="theme-color" content="#0c4a6e"/>
</head>
<body class=tw_join!("flex", "flex-col", "min-h-screen", "bg-gray-900", "text-white")>
<main class=tw_join!("flex-grow")>
{children.into_any()}
</main>
<footer class=tw_join!("bg-black")>
<div class=tw_join!("container", "mx-auto", "px-4", "py-8")>
<p>"© 2015 - "{year}" Philippe Loctaux, made with "{underline_link(Link::new(uri!("https://leptos.dev").into(), "Leptos"), None).into_any()}"."</p>
</div>
</footer>
</body>
</html>
}.into_any()
}
pub fn content_page(title: &str, children: impl IntoAny) -> AnyView {
shell(
title,
view! {
<div class=tw_join!("container", "mx-auto", "px-4", "py-16")>
<h1 class=tw_join!("text-3xl", "sm:text-4xl", "font-bold")>{title.to_string()}</h1>
{underline_link(Link::new(uri!("/").into(), "← Home"), None).into_any()}
<div class=tw_join!("mt-8")>{children.into_any()}</div>
</div>
}
.into_any(),
)
.into_any()
}