Skip to content

Commit

Permalink
Add preloads
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechu10 committed Oct 15, 2024
1 parent f5702d1 commit 06ba2e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Trunk.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[build]
filehash = false

[serve]
no_spa = true

[[hooks]]
stage = "post_build"
command = "cargo"
Expand Down
19 changes: 14 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,35 @@ pub mod shell;
use self::shell::*;

use sycamore::prelude::*;
use sycamore_router::Route;

static ROUTES: &[&str] = &["/index.html", "/404.html"];
static PUBLIC_PATH: &str = "dist/.stage";
pub async fn get_static_paths() -> Vec<String> {
let mut paths = vec![];

paths.push("/index.html".to_string());
paths.push("/404.html".to_string());

paths
}

#[cfg_ssr]
#[tokio::main]
async fn main() {
use std::path::PathBuf;
use sycamore_router::Route;
use tokio::fs;

for route in ROUTES {
static PUBLIC_PATH: &str = "dist/.stage";

let routes = get_static_paths().await;
for route in routes {
let path = PathBuf::from(PUBLIC_PATH).join(route.trim_start_matches('/'));

eprintln!("Rendering `{route}` to `{}`", path.display());

let html = sycamore::render_to_string_await_suspense(|| {
view! {
Shell {
sycamore_router::StaticRouter(route=Routes::default().match_path(route), view=App)
sycamore_router::StaticRouter(route=Routes::default().match_path(&route), view=App)
}
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub fn Shell(children: Children) -> View {
html {
sycamore::web::NoHydrate {
head {
link(rel="preload", href="/sycamore-website.js", r#as="script", crossorigin="")
link(rel="preload", href="/sycamore-website_bg.wasm", r#as="fetch", crossorigin="")
script(r#type="module") {
r#"import init from "/sycamore-website.js"; init();"#
}
Expand Down

0 comments on commit 06ba2e6

Please sign in to comment.