cleanup
This commit is contained in:
parent
f37ebd0445
commit
bfff54c2b2
11 changed files with 130 additions and 55 deletions
68
Cargo.lock
generated
68
Cargo.lock
generated
|
@ -56,6 +56,21 @@ version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android-tzdata"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "android_system_properties"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.79"
|
version = "1.0.79"
|
||||||
|
@ -364,6 +379,20 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chrono"
|
||||||
|
version = "0.4.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f13690e35a5e4ace198e7beea2895d29f3a9cc55015fcebe6336bd2010af9eb"
|
||||||
|
dependencies = [
|
||||||
|
"android-tzdata",
|
||||||
|
"iana-time-zone",
|
||||||
|
"js-sys",
|
||||||
|
"num-traits",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"windows-targets 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ciborium"
|
name = "ciborium"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
@ -456,6 +485,12 @@ dependencies = [
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "core-foundation-sys"
|
||||||
|
version = "0.8.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.12"
|
version = "0.2.12"
|
||||||
|
@ -1190,6 +1225,29 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone"
|
||||||
|
version = "0.1.59"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539"
|
||||||
|
dependencies = [
|
||||||
|
"android_system_properties",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"iana-time-zone-haiku",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"windows-core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iana-time-zone-haiku"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ident_case"
|
name = "ident_case"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -2415,6 +2473,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app",
|
"app",
|
||||||
"axum",
|
"axum",
|
||||||
|
"chrono",
|
||||||
"femark",
|
"femark",
|
||||||
"leptos",
|
"leptos",
|
||||||
"leptos_axum",
|
"leptos_axum",
|
||||||
|
@ -3528,6 +3587,15 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-core"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.48.0"
|
version = "0.48.0"
|
||||||
|
|
|
@ -1,9 +1,27 @@
|
||||||
use crate::components::ui::articles::*;
|
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||||
|
pub enum ArticleType {
|
||||||
|
All,
|
||||||
|
Blog,
|
||||||
|
Game,
|
||||||
|
Project,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))]
|
||||||
|
pub struct Article {
|
||||||
|
pub content_type: String,
|
||||||
|
pub title: String,
|
||||||
|
pub date: String, // make datetime?
|
||||||
|
pub content: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[server]
|
#[server]
|
||||||
pub async fn get_articles(article_type: ArticleType) -> Result<Vec<Article>, ServerFnError> {
|
pub async fn get_articles(article_type: ArticleType) -> Result<Vec<Article>, ServerFnError> {
|
||||||
use sqlx::*;
|
use sqlx::*;
|
||||||
|
|
||||||
let query = match article_type {
|
let query = match article_type {
|
||||||
ArticleType::All => "select * from blog order by date",
|
ArticleType::All => "select * from blog order by date",
|
||||||
ArticleType::Blog => "select * from blog where content_type like 'blog'",
|
ArticleType::Blog => "select * from blog where content_type like 'blog'",
|
||||||
|
@ -13,9 +31,7 @@ pub async fn get_articles(article_type: ArticleType) -> Result<Vec<Article>, Ser
|
||||||
|
|
||||||
let pool: SqlitePool = use_context::<SqlitePool>().expect("couldn't get pool context");
|
let pool: SqlitePool = use_context::<SqlitePool>().expect("couldn't get pool context");
|
||||||
|
|
||||||
let result = sqlx::query_as::<_, Article>(query)
|
let articles: Vec<Article> = sqlx::query_as::<_, Article>(query).fetch_all(&pool).await?;
|
||||||
.fetch_all(&pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(result)
|
Ok(articles)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,6 @@
|
||||||
use crate::components::api::*;
|
use crate::components::api::*;
|
||||||
use crate::components::ui::containers::*;
|
use crate::components::ui::containers::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use serde::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
|
||||||
#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))]
|
|
||||||
pub struct Article {
|
|
||||||
pub content_type: String,
|
|
||||||
pub title: String,
|
|
||||||
pub date: String, // make datetime?
|
|
||||||
pub content: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
|
||||||
pub enum ArticleType {
|
|
||||||
All,
|
|
||||||
Blog,
|
|
||||||
Game,
|
|
||||||
Project,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn Article(data: Article) -> impl IntoView {
|
pub fn Article(data: Article) -> impl IntoView {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::components::ui::articles::*;
|
use crate::components::api::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
use crate::components::api::get_articles;
|
use crate::components::api::get_articles;
|
||||||
|
@ -7,17 +7,15 @@ use crate::components::api::get_articles;
|
||||||
pub fn Card(data: Article) -> impl IntoView {
|
pub fn Card(data: Article) -> impl IntoView {
|
||||||
view! {
|
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">
|
<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">
|
<h1 class="text-2xl font-light text-orange-600 max-6-xs">{&data.title}</h1>
|
||||||
{&data.title}
|
|
||||||
</h1>
|
|
||||||
<hr class="opacity-50"/>
|
<hr class="opacity-50"/>
|
||||||
<span class="pt-0 pb-3.5 text-xs opacity-50 m-t">{&data.date}</span>
|
<span class="pt-0 pb-3.5 text-xs opacity-50 m-t">{&data.date}</span>
|
||||||
<p class="text-center">
|
<p class="text-center">"[image]"</p>
|
||||||
"[image]"
|
|
||||||
</p>
|
|
||||||
<div inner_html=&data.content></div>
|
<div inner_html=&data.content></div>
|
||||||
<p class="text-right">
|
<p class="text-right">
|
||||||
<a class="text-orange-300 hover:underline" href="https://lickmysa.cc" >Read more...</a>
|
<a class="text-orange-300 hover:underline" href="https://lickmysa.cc">
|
||||||
|
Read more...
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
@ -33,13 +31,9 @@ pub fn CardBuilder(article_type: ArticleType) -> impl IntoView {
|
||||||
let cards_view = move || {
|
let cards_view = move || {
|
||||||
data_resource.and_then(|data| {
|
data_resource.and_then(|data| {
|
||||||
data.iter()
|
data.iter()
|
||||||
.map(|article| view! {<Card data=article.clone()/> })
|
.map(|article| view! { <Card data=article.clone()/> })
|
||||||
.collect_view()
|
.collect_view()
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
view! {
|
view! { <div class="flex flex-wrap place-content-evenly mx-auto max-w-11/12">{cards_view}</div> }
|
||||||
<div class="flex flex-wrap place-content-evenly mx-auto max-w-8/12">
|
|
||||||
{cards_view}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::components::ui::articles::*;
|
use crate::components::api::ArticleType;
|
||||||
|
use crate::components::ui::articles::ArticleBuilder;
|
||||||
use crate::error_template::*;
|
use crate::error_template::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
#[island]
|
#[island]
|
||||||
pub fn Blog() -> impl IntoView {
|
pub fn Blog() -> impl IntoView {
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Suspense fallback=move || {
|
<Suspense fallback=move || {
|
||||||
view! { <p>"Loading..."</p> }
|
view! { <p>"Loading..."</p> }
|
||||||
|
@ -12,7 +12,7 @@ pub fn Blog() -> impl IntoView {
|
||||||
<ErrorBoundary fallback=|errors| {
|
<ErrorBoundary fallback=|errors| {
|
||||||
view! { <ErrorTemplate errors=errors/> }
|
view! { <ErrorTemplate errors=errors/> }
|
||||||
}>
|
}>
|
||||||
<ArticleBuilder article_type={ArticleType::Blog} />
|
<ArticleBuilder article_type=ArticleType::Blog/>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::components::ui::articles::*;
|
use crate::components::api::ArticleType;
|
||||||
use crate::components::ui::cards::*;
|
use crate::components::ui::cards::*;
|
||||||
use crate::error_template::*;
|
use crate::error_template::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
@ -13,7 +13,7 @@ pub fn Games() -> impl IntoView {
|
||||||
<ErrorBoundary fallback=|errors| {
|
<ErrorBoundary fallback=|errors| {
|
||||||
view! { <ErrorTemplate errors=errors/> }
|
view! { <ErrorTemplate errors=errors/> }
|
||||||
}>
|
}>
|
||||||
<CardBuilder article_type={ArticleType::Game} />
|
<CardBuilder article_type=ArticleType::Game/>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::components::ui::articles::*;
|
use crate::components::api::ArticleType;
|
||||||
|
use crate::components::ui::articles::ArticleBuilder;
|
||||||
use crate::components::ui::cards::*;
|
use crate::components::ui::cards::*;
|
||||||
use crate::error_template::*;
|
use crate::error_template::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
@ -13,8 +14,8 @@ pub fn Home() -> impl IntoView {
|
||||||
<ErrorBoundary fallback=|errors| {
|
<ErrorBoundary fallback=|errors| {
|
||||||
view! { <ErrorTemplate errors=errors/> }
|
view! { <ErrorTemplate errors=errors/> }
|
||||||
}>
|
}>
|
||||||
<CardBuilder article_type={ArticleType::Game} />
|
<CardBuilder article_type=ArticleType::Game/>
|
||||||
<ArticleBuilder article_type={ArticleType::All} />
|
<ArticleBuilder article_type=ArticleType::All/>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::components::ui::articles::*;
|
use crate::components::api::ArticleType;
|
||||||
|
use crate::components::ui::articles::ArticleBuilder;
|
||||||
use crate::error_template::*;
|
use crate::error_template::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
#[island]
|
#[island]
|
||||||
pub fn Projects() -> impl IntoView {
|
pub fn Projects() -> impl IntoView {
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Suspense fallback=move || {
|
<Suspense fallback=move || {
|
||||||
view! { <p>"Loading..."</p> }
|
view! { <p>"Loading..."</p> }
|
||||||
|
@ -12,7 +12,7 @@ pub fn Projects() -> impl IntoView {
|
||||||
<ErrorBoundary fallback=|errors| {
|
<ErrorBoundary fallback=|errors| {
|
||||||
view! { <ErrorTemplate errors=errors/> }
|
view! { <ErrorTemplate errors=errors/> }
|
||||||
}>
|
}>
|
||||||
<ArticleBuilder article_type={ArticleType::Project} />
|
<ArticleBuilder article_type=ArticleType::Project/>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use app::*; // don't remove this when using experimental-islands
|
use app::*; // https://github.com/leptos-rs/leptos/issues/2083
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use wasm_bindgen::prelude::wasm_bindgen;
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,4 @@ sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "sqlite"] }
|
||||||
toml = "0.8.8"
|
toml = "0.8.8"
|
||||||
femark = "0.1.5"
|
femark = "0.1.5"
|
||||||
serde = "1.0.196"
|
serde = "1.0.196"
|
||||||
|
chrono = "0.4.33"
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
|
use app::components::api::Article;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use serde::*;
|
use serde::*;
|
||||||
use sqlx::*;
|
use sqlx::*;
|
||||||
|
|
||||||
use app::components::ui::articles::Article;
|
|
||||||
|
|
||||||
pub async fn db_build(pool: SqlitePool) -> Result<(), ServerFnError> {
|
pub async fn db_build(pool: SqlitePool) -> Result<(), ServerFnError> {
|
||||||
let _ = query("CREATE TABLE blog (content_type TEXT, title TEXT, date TEXT, content TEXT)")
|
let _res = query(
|
||||||
.execute(&pool)
|
"
|
||||||
.await?;
|
CREATE TABLE
|
||||||
|
blog (
|
||||||
|
content_type TEXT,
|
||||||
|
title TEXT,
|
||||||
|
date TEXT,
|
||||||
|
content TEXT
|
||||||
|
)
|
||||||
|
",
|
||||||
|
)
|
||||||
|
.execute(&pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// println!("{:?}", _res);
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct ArticleFrontmatter {
|
struct ArticleFrontmatter {
|
||||||
|
@ -40,7 +51,7 @@ pub async fn db_build(pool: SqlitePool) -> Result<(), ServerFnError> {
|
||||||
content,
|
content,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _ = sqlx::query(
|
let _res = sqlx::query(
|
||||||
"
|
"
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
blog (content_type, title, date, content)
|
blog (content_type, title, date, content)
|
||||||
|
@ -54,6 +65,8 @@ pub async fn db_build(pool: SqlitePool) -> Result<(), ServerFnError> {
|
||||||
.bind(article.content)
|
.bind(article.content)
|
||||||
.execute(&pool)
|
.execute(&pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// println!("{:?}", _res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue