get more organized
This commit is contained in:
parent
ca2241fad0
commit
8307f7f73a
8 changed files with 99 additions and 96 deletions
|
@ -1,23 +1,17 @@
|
||||||
|
use crate::components::ui::articles::ArticleInterface;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use serde::*;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct ArticleData {
|
|
||||||
pub content_type: String,
|
|
||||||
pub title: String,
|
|
||||||
pub date: String, // make datetime?
|
|
||||||
pub content: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct ArticleFrontmatter {
|
|
||||||
content_type: String,
|
|
||||||
title: String,
|
|
||||||
date: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub async fn slingshot(path: String) -> Result<Vec<ArticleData>, ServerFnError> {
|
pub async fn slingshot(path: String) -> Result<Vec<ArticleInterface>, ServerFnError> {
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct ArticleFrontmatter {
|
||||||
|
content_type: String,
|
||||||
|
title: String,
|
||||||
|
date: String,
|
||||||
|
}
|
||||||
|
|
||||||
let mut articles = vec![];
|
let mut articles = vec![];
|
||||||
|
|
||||||
for file in std::fs::read_dir(path)? {
|
for file in std::fs::read_dir(path)? {
|
||||||
|
@ -38,7 +32,7 @@ pub async fn slingshot(path: String) -> Result<Vec<ArticleData>, ServerFnError>
|
||||||
let toml: ArticleFrontmatter = toml::from_str(&front_code.source)?;
|
let toml: ArticleFrontmatter = toml::from_str(&front_code.source)?;
|
||||||
|
|
||||||
// println!("{} {}", &toml.date, &toml.title);
|
// println!("{} {}", &toml.date, &toml.title);
|
||||||
articles.push(ArticleData {
|
articles.push(ArticleInterface {
|
||||||
content_type: toml.content_type,
|
content_type: toml.content_type,
|
||||||
title: toml.title,
|
title: toml.title,
|
||||||
date: toml.date,
|
date: toml.date,
|
||||||
|
@ -50,6 +44,5 @@ pub async fn slingshot(path: String) -> Result<Vec<ArticleData>, ServerFnError>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// println!("iran");
|
|
||||||
Ok(articles)
|
Ok(articles)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,73 +1,3 @@
|
||||||
//
|
pub mod articles;
|
||||||
// Pile of UI stuff
|
pub mod cards;
|
||||||
//
|
pub mod containers;
|
||||||
|
|
||||||
use crate::components::slingshot::*;
|
|
||||||
use leptos::*;
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Article(data: ArticleData) -> impl IntoView {
|
|
||||||
view! {
|
|
||||||
<Container>
|
|
||||||
<article>
|
|
||||||
<h1 class="text-3xl font-light text-orange-600 capitalize max-6-xs">
|
|
||||||
{&data.title}
|
|
||||||
</h1>
|
|
||||||
<hr class="opacity-50"/>
|
|
||||||
<span class="pt-0 pb-3.5 text-xs opacity-50 m-t">{&data.date}</span>
|
|
||||||
<div inner_html=&data.content></div>
|
|
||||||
</article>
|
|
||||||
</Container>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn ArticleBuilder() -> impl IntoView {
|
|
||||||
let data_resource = create_local_resource(
|
|
||||||
|| (),
|
|
||||||
|_| async move { slingshot("./public/blog".to_string()).await },
|
|
||||||
);
|
|
||||||
|
|
||||||
let articles_view = move || {
|
|
||||||
data_resource.and_then(|data| {
|
|
||||||
data.iter()
|
|
||||||
.map(|article| view! { <Article data=article.clone()/> })
|
|
||||||
.collect_view()
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
articles_view
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Card(children: Children) -> impl IntoView {
|
|
||||||
view! {
|
|
||||||
<div class="p-7 my-5 mx-2 w-80 rounded-lg shadow-inner min-w-3/12 max-w-3/12 bg-zinc-900 shadow-zinc-950">
|
|
||||||
<h1 class="text-2xl font-light text-orange-600 max-6-xs">
|
|
||||||
"Card Header"
|
|
||||||
</h1>
|
|
||||||
<hr class="opacity-50"/>
|
|
||||||
<p class="text-center">
|
|
||||||
"[image]"
|
|
||||||
</p>
|
|
||||||
{children()}
|
|
||||||
<p class="text-right">
|
|
||||||
<a class="text-orange-300 hover:underline" href="https://lickmysa.cc" >Read more...</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn CardHolder(children: Children) -> impl IntoView {
|
|
||||||
view! { <div class="flex flex-wrap place-content-evenly mx-auto w-11/12">{children()}</div> }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
|
||||||
pub fn Container(children: Children) -> impl IntoView {
|
|
||||||
view! {
|
|
||||||
<div class="p-7 my-5 mx-auto w-11/12 max-w-screen-xl rounded-lg shadow-inner bg-zinc-900 shadow-zinc-950">
|
|
||||||
{children()}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
46
app/src/components/ui/articles.rs
Normal file
46
app/src/components/ui/articles.rs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
use crate::components::slingshot::*;
|
||||||
|
use crate::components::ui::containers::*;
|
||||||
|
use leptos::*;
|
||||||
|
use serde::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
|
pub struct ArticleInterface {
|
||||||
|
pub content_type: String,
|
||||||
|
pub title: String,
|
||||||
|
pub date: String, // make datetime?
|
||||||
|
pub content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Article(data: ArticleInterface) -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<Container>
|
||||||
|
<article>
|
||||||
|
<h1 class="text-3xl font-light text-orange-600 capitalize max-6-xs">
|
||||||
|
{&data.title}
|
||||||
|
</h1>
|
||||||
|
<hr class="opacity-50"/>
|
||||||
|
<span class="pt-0 pb-3.5 text-xs opacity-50 m-t">{&data.date}</span>
|
||||||
|
<div inner_html=&data.content></div>
|
||||||
|
</article>
|
||||||
|
</Container>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn ArticleBuilder() -> impl IntoView {
|
||||||
|
let data_resource = create_local_resource(
|
||||||
|
|| (),
|
||||||
|
|_| async move { slingshot("./public/blog".to_string()).await },
|
||||||
|
);
|
||||||
|
|
||||||
|
let articles_view = move || {
|
||||||
|
data_resource.and_then(|data| {
|
||||||
|
data.iter()
|
||||||
|
.map(|article| view! { <Article data=article.clone()/> })
|
||||||
|
.collect_view()
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
articles_view
|
||||||
|
}
|
25
app/src/components/ui/cards.rs
Normal file
25
app/src/components/ui/cards.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Card(children: Children) -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<div class="p-7 my-5 mx-2 w-80 rounded-lg shadow-inner min-w-3/12 max-w-3/12 bg-zinc-900 shadow-zinc-950">
|
||||||
|
<h1 class="text-2xl font-light text-orange-600 max-6-xs">
|
||||||
|
"Card Header"
|
||||||
|
</h1>
|
||||||
|
<hr class="opacity-50"/>
|
||||||
|
<p class="text-center">
|
||||||
|
"[image]"
|
||||||
|
</p>
|
||||||
|
{children()}
|
||||||
|
<p class="text-right">
|
||||||
|
<a class="text-orange-300 hover:underline" href="https://lickmysa.cc" >Read more...</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn CardHolder(children: Children) -> impl IntoView {
|
||||||
|
view! { <div class="flex flex-wrap place-content-evenly mx-auto w-11/12">{children()}</div> }
|
||||||
|
}
|
10
app/src/components/ui/containers.rs
Normal file
10
app/src/components/ui/containers.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn Container(children: Children) -> impl IntoView {
|
||||||
|
view! {
|
||||||
|
<div class="p-7 my-5 mx-auto w-11/12 max-w-screen-xl rounded-lg shadow-inner bg-zinc-900 shadow-zinc-950">
|
||||||
|
{children()}
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::components::ui::*;
|
use crate::components::ui::articles::*;
|
||||||
use crate::error_template::*;
|
use crate::error_template::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::components::ui::*;
|
use crate::components::ui::cards::*;
|
||||||
use crate::error_template::*;
|
use crate::error_template::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::components::ui::*;
|
use crate::components::ui::cards::*;
|
||||||
// use crate::components::slingshot::*;
|
|
||||||
use crate::error_template::*;
|
use crate::error_template::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue