Skip to content

Commit

Permalink
Base path for changing directories
Browse files Browse the repository at this point in the history
  • Loading branch information
MolotovCherry committed Mar 15, 2024
1 parent e4c0b76 commit 83c0801
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion stegcloak-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
<link data-trunk rel="tailwind-css" href="tailwind.css" data-target-path="static/css" />
<link data-trunk rel="rust" data-wasm-opt="z" data-weak-refs data-reference-types data-target-path="static/wasm" />
<!-- 🧙🏻‍♂️ -->
<link rel="icon" href="/static/image/favicon.svg"/>
<link data-trunk rel="icon" href="public/image/favicon.svg" data-target-path="static/image"/>

<script data-trunk src="public/js/init.js" data-target-path="static/js" defer />

<base data-trunk-public-url/>
</head>
<body>
<noscript>
Expand Down
9 changes: 6 additions & 3 deletions stegcloak-web/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use leptos_use::{

use crate::{
components::page_base::PageBase,
get_base_url,
pages::{home::Home, not_found::NotFound},
};

Expand All @@ -34,6 +35,8 @@ pub fn App() -> impl IntoView {
provide_context(get_theme);
provide_context(set_theme);

let base = get_base_url();

view! {
<Html lang="en"/>

Expand All @@ -44,10 +47,10 @@ pub fn App() -> impl IntoView {
<Meta name="viewport" content="width=device-width, initial-scale=1.0"/>

<PageBase>
<Router>
<Router clone:base>
<Routes>
<Route path="/" view=Home/>
<Route path="/*" view=NotFound/>
<Route path=base.clone() view=Home/>
<Route path=format!("{base}*") view=NotFound/>
</Routes>
</Router>
</PageBase>
Expand Down
8 changes: 5 additions & 3 deletions stegcloak-web/src/components/page_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use leptos::*;
use crate::{
app::{GetTheme, SetTheme},
components::mockup_code::{MockupCode, Prefix},
Panic,
get_base_url, Panic,
};

#[component]
Expand Down Expand Up @@ -206,6 +206,8 @@ fn Footer() -> impl IntoView {
_ => unreachable!(),
};

let base = get_base_url();

view! {
<footer class="footer items-center p-4 bg-neutral text-neutral-content rounded-b">
<aside class="items-center grid-flow-col">
Expand All @@ -217,11 +219,11 @@ fn Footer() -> impl IntoView {
{move || {
if is_footer_dark_mode() {
view! {
<img src="/static/image/github-mark-white.svg" height="24" width="24" />
<img src=format!("{base}static/image/github-mark-white.svg") height="24" width="24" />
}
} else {
view! {
<img src="/static/image/github-mark.svg" height="24" width="24" />
<img src=format!("{base}static/image/github-mark.svg") height="24" width="24" />
}
}
}}
Expand Down
12 changes: 12 additions & 0 deletions stegcloak-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ mod app;
mod components;
mod pages;

use std::sync::OnceLock;

use leptos::*;

pub use app::App;

static BASE_PATH: OnceLock<String> = OnceLock::new();

#[derive(Debug, Clone)]
pub struct Panic(pub String);

pub fn get_base_url() -> String {
BASE_PATH
.get_or_init(|| document().location().unwrap().pathname().unwrap())
.clone()
}

0 comments on commit 83c0801

Please sign in to comment.