Skip to content

Commit 96066d0

Browse files
committed
fix: 🐛 fixed inconsistent path prefixing in build_state calls
1 parent 71a5445 commit 96066d0

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

examples/showcase/app/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ enum AppRoute {
1414
About,
1515
#[to("/post/new")]
1616
NewPost,
17-
#[to("/post/<slug>")]
18-
Post { slug: String },
17+
#[to("/post/<slug..>")]
18+
Post { slug: Vec<String> },
1919
#[to("/ip")]
2020
Ip,
2121
#[to("/time")]
@@ -82,7 +82,7 @@ pub fn run() -> Result<(), JsValue> {
8282
get_error_pages()
8383
),
8484
AppRoute::Post { slug } => app_shell(
85-
format!("post/{}", slug),
85+
format!("post/{}", slug.join("/")),
8686
pages::post::template_fn(),
8787
get_error_pages()
8888
),

examples/showcase/app/src/pages/post.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ pub fn get_page<G: GenericNode>() -> Template<G> {
3131
}
3232

3333
pub async fn get_static_props(path: String) -> Result<String, String> {
34-
let path_vec: Vec<&str> = path.split('/').collect();
35-
let title_slug = path_vec[path_vec.len() - 1];
3634
// This is just an example
37-
let title = urlencoding::decode(title_slug).unwrap();
35+
let title = urlencoding::decode(&path).unwrap();
3836
let content = format!(
3937
"This is a post entitled '{}'. Its original slug was '{}'.",
40-
title, title_slug
38+
title, path
4139
);
4240

4341
Ok(serde_json::to_string(&PostPageProps {
@@ -48,7 +46,10 @@ pub async fn get_static_props(path: String) -> Result<String, String> {
4846
}
4947

5048
pub async fn get_static_paths() -> Result<Vec<String>, String> {
51-
Ok(vec!["test".to_string()])
49+
Ok(vec![
50+
"test".to_string(),
51+
"blah/test/blah".to_string()
52+
])
5253
}
5354

5455
pub fn template_fn<G: GenericNode>() -> perseus::template::TemplateFn<G> {

src/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub async fn build_template(
4040
// Handle static initial state generation
4141
// We'll only write a static state if one is explicitly generated
4242
if template.uses_build_state() {
43-
// We pass in the latter part of the path, without the base specifier (because that would be the same for everything in the template)
44-
let initial_state = template.get_build_state(path.to_string()).await?;
43+
// We pass in the path to get a state (including the template path for consistency with the incremental logic)
44+
let initial_state = template.get_build_state(full_path.clone()).await?;
4545
// Write that intial state to a static JSON file
4646
config_manager.write(&format!("./dist/static/{}.json", full_path), &initial_state)?;
4747
// Prerender the template using that state

src/serve.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ async fn revalidate(
135135

136136
/// Gets the HTML/JSON data for the given page path. This will call SSG/SSR/etc., whatever is needed for that page. Note that HTML generated
137137
/// at request-time will **always** replace anything generated at build-time, incrementally, revalidated, etc.
138-
// TODO let this function take a request struct of some form
139138
// TODO possible further optimizations on this for futures?
140139
pub async fn get_page(
141140
path: &str,
@@ -225,7 +224,7 @@ pub async fn get_page(
225224
// We need to generate and cache this page for future usage
226225
let state = Some(
227226
template
228-
.get_build_state(format!("{}/{}", template.get_path(), path))
227+
.get_build_state(path.to_string())
229228
.await?,
230229
);
231230
let html_val =

0 commit comments

Comments
 (0)