diff --git a/src/app/mod.rs b/src/app/mod.rs
index d1f89ce..529816f 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -15,15 +15,14 @@ pub fn App() -> impl IntoView {
-
- } />
+
+
-
-
-
- } />
- "Not Found" }/>
+
+
+
+
+ }/>
}
diff --git a/src/app/pages/posts.rs b/src/app/pages/posts.rs
index 0c11753..ae59dc2 100644
--- a/src/app/pages/posts.rs
+++ b/src/app/pages/posts.rs
@@ -1,11 +1,10 @@
use leptos::*;
+use leptos_router::*;
use crate::app::models::Post;
#[server]
-pub async fn get_posts(
- folder: String
-) -> Result, ServerFnError> {
- let posts = Post::get_all(&folder)
+pub async fn get_posts() -> Result, ServerFnError> {
+ let posts = Post::get_all("posts")
.map_err(|e| ServerFnError::ServerError(e.to_string()))?;
Ok(posts)
@@ -13,10 +12,9 @@ pub async fn get_posts(
#[server]
pub async fn get_post(
- folder: String,
slug: String
) -> Result {
- let posts = Post::get_all(&folder)
+ let posts = Post::get_all("posts")
.map_err(|e| ServerFnError::ServerError(e.to_string()))?;
let post = posts.into_iter().find(|post| post.slug == slug)
@@ -26,10 +24,8 @@ pub async fn get_post(
}
#[component]
-pub fn PostList(
- folder: String
-) -> impl IntoView {
- let posts = create_resource(|| (), |_| get_posts("posts".to_string()));
+pub fn PostList() -> impl IntoView {
+ let posts = create_resource(|| (), |_| get_posts());
let posts_view = move || {
posts.and_then(|posts| {
@@ -55,10 +51,11 @@ pub fn PostList(
}
#[component]
-pub fn PostElement(
- folder: String,
-) -> impl IntoView {
- let post = create_resource(|| (), |_| get_post("posts".to_string(), "2023-11-26_testing_layout".to_string()));
+pub fn PostElement() -> impl IntoView {
+ let params = use_params_map();
+ let slug = move || params.with(|params| params.get("slug").cloned().unwrap_or_default());
+
+ let post = create_resource(|| (), move |_| get_post(slug()));
let post_view = move || {
post.and_then(|post| {