Skip to content

Commit 961521c

Browse files
committed
feat: separe communities and projects in individual pages
1 parent cb63165 commit 961521c

File tree

8 files changed

+98
-33
lines changed

8 files changed

+98
-33
lines changed

build.rs

+30-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121

2222
// Generate src/extras/mod.rs
2323
let mut out = fs::File::create("src/extras/mod.rs").unwrap();
24-
write!(out, "#[rustfmt::skip]\nmod comunities;\n#[rustfmt::skip]\nmod projects;\npub use comunities::*;\npub use projects::*;\n").unwrap();
24+
write!(out, "#[rustfmt::skip]\nmod other_communities;\nmod rust_communities;\n#[rustfmt::skip]\nmod projects;\npub use other_communities::*;\npub use rust_communities::*;\npub use projects::*;\n").unwrap();
2525

2626
for folder in folders {
2727
let folder = folder.unwrap();
@@ -34,7 +34,7 @@ fn main() {
3434
path.push(folder.path());
3535

3636
match folder.file_name().to_str().unwrap() {
37-
"comunidades" => generate_comunity(&path),
37+
"comunidades" => generate_community(&path),
3838
"proyectos" => generate_projects(&path),
3939
_ => {}
4040
}
@@ -55,9 +55,9 @@ fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result
5555
Ok(())
5656
}
5757

58-
fn generate_comunity(path: &Path) {
58+
fn generate_community(path: &Path) {
5959
let folders = fs::read_dir(path).unwrap();
60-
let mut comunities = Vec::new();
60+
let mut communities = Vec::new();
6161

6262
for file in folders {
6363
let file = file.unwrap();
@@ -68,26 +68,41 @@ fn generate_comunity(path: &Path) {
6868
let file_path = file.path();
6969
let toml_str = fs::read_to_string(&file_path).unwrap();
7070
let toml_str = toml::from_str::<CommunityItem>(&toml_str).unwrap();
71-
comunities.push((file_path, toml_str));
71+
communities.push((file_path, toml_str));
7272
}
73-
let mut out = fs::File::create("src/extras/comunities.rs").unwrap();
73+
let mut other_file = fs::File::create("src/extras/other_communities.rs").unwrap();
7474
write!(
75-
out,
76-
"use crate::models::CommunityItem;\npub const OTHER_COMUNITIES: &[CommunityItem] = &[\n"
75+
other_file,
76+
"use crate::models::CommunityItem;\npub const OTHER_COMMUNITIES: &[CommunityItem] = &[\n"
7777
)
78-
.unwrap();
79-
for (_p, t) in comunities {
78+
.expect("No se pudo crear el archivo src/extras/other_communities.rs");
79+
80+
let mut rust_file = fs::File::create("src/extras/rust_communities.rs").unwrap();
81+
write!(
82+
rust_file,
83+
"use crate::models::CommunityItem;\npub const RUST_COMMUNITIES: &[CommunityItem] = &[\n"
84+
)
85+
.expect("No se pudo crear el archivo src/extras/rust_communities.rs");
86+
87+
for (_p, community) in communities {
88+
let mut output_file = if community.name.join("").to_lowercase().contains("rust") {
89+
&rust_file
90+
} else {
91+
&other_file
92+
};
93+
8094
let CommunityItem {
8195
name,
8296
description,
8397
link,
8498
icon,
8599
brand_src,
86100
brand_alt,
87-
} = t;
101+
} = community;
88102
let brand_src = brand_src.replace("./", "/gen_assets/");
103+
89104
write!(
90-
out,
105+
output_file,
91106
r#"
92107
CommunityItem {{
93108
name: &{name:?},
@@ -100,7 +115,9 @@ fn generate_comunity(path: &Path) {
100115
)
101116
.unwrap();
102117
}
103-
write!(out, "\n];").unwrap();
118+
119+
write!(other_file, "\n];").unwrap();
120+
write!(rust_file, "\n];").unwrap();
104121
}
105122

106123
fn iter_dir(path: &Path, mut callback: impl FnMut(DirEntry, Metadata)) {

src/app.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use leptos_router::{Router, Routes, StaticParamsMap, StaticRoute};
44

55
use crate::{
66
components::{Footer, HeadInformation, Header},
7-
pages::{Aprende, Communidad, Contributors, Index},
7+
pages::{Aprende, Communities, Contributors, Index, Projects},
88
};
99

1010
#[component]
@@ -33,15 +33,20 @@ pub fn App() -> impl IntoView {
3333
static_params=move || Box::pin(async move { StaticParamsMap::default() })
3434
/>
3535
<StaticRoute
36-
path="/comunidad"
37-
view=Communidad
36+
path="/comunidades"
37+
view=Communities
3838
static_params=move || Box::pin(async move { StaticParamsMap::default() })
3939
/>
4040
<StaticRoute
4141
path="/colaboradores"
4242
view=Contributors
4343
static_params=move || Box::pin(async move { StaticParamsMap::default() })
4444
/>
45+
<StaticRoute
46+
path="/proyectos"
47+
view=Projects
48+
static_params=move || Box::pin(async move { StaticParamsMap::default() })
49+
/>
4550
<StaticRoute
4651
path="/aprende"
4752
view=Aprende

src/components/community_projects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn CommunityProjects(#[prop(default = false)] show_more: bool) -> impl IntoV
4646
view! {
4747
<div class="w-full flex justify-end my-3">
4848
<A
49-
href="/comunidad"
49+
href="/proyectos"
5050
class="text-black/80 dark:text-white/80 hover:text-orange-500 fill-black/80 dark:fill-white/80 hover:fill-orange-500 font-work-sans font-light text-2xl flex justify-center items-center"
5151
>
5252
"Ver todos los proyectos"

src/components/other_communities.rs

+37-11
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,50 @@ use leptos::{component, view, IntoView};
22

33
use crate::{
44
components::{CommunityCard, NextIcon},
5-
extras::OTHER_COMUNITIES,
5+
extras::{OTHER_COMMUNITIES, RUST_COMMUNITIES},
66
};
77

88
#[component]
9-
pub fn OtherCommunities(#[prop(default = false)] show_more: bool) -> impl IntoView {
9+
pub fn OtherCommunities(
10+
#[prop(default = false)] show_more: bool,
11+
#[prop(default = false)] other_communities: bool,
12+
) -> impl IntoView {
13+
let communities = match (other_communities, show_more) {
14+
(true, false) => OTHER_COMMUNITIES.to_vec(),
15+
(false, false) => RUST_COMMUNITIES.to_vec(),
16+
(_, true) => {
17+
let mut all_communities = vec![];
18+
all_communities.extend(OTHER_COMMUNITIES.to_vec());
19+
all_communities.extend(RUST_COMMUNITIES.to_vec());
20+
all_communities
21+
}
22+
};
23+
1024
view! {
1125
<section class="bg-orange-50 dark:bg-transparent py-20">
1226
<div class="container mx-auto px-4">
13-
<h2 class="text-3xl text-left mb-6">
14-
<span class="font-work-sans font-light">"Otras "</span>
15-
<span class="font-alfa-slab text-orange-500">"Comunidades"</span>
16-
<span class="font-work-sans font-light">" recomendadas "</span>
17-
</h2>
27+
28+
{if other_communities {
29+
view! {
30+
<h2 class="text-3xl text-left mb-6">
31+
<span class="font-work-sans font-light">"Otras "</span>
32+
<span class="font-alfa-slab text-orange-500">"Comunidades"</span>
33+
<span class="font-work-sans font-light">" recomendadas "</span>
34+
</h2>
35+
}
36+
} else {
37+
view! {
38+
<h2 class="text-3xl text-left mb-6">
39+
<span class="font-work-sans font-light">"Comunidades de"</span>
40+
<span class="font-alfa-slab text-orange-500">" Rust"</span>
41+
</h2>
42+
}
43+
}}
1844
<div class="w-full grid sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-x-8 gap-y-8">
19-
{OTHER_COMUNITIES
45+
46+
{communities
2047
.iter()
21-
.take(if show_more { 5 } else { OTHER_COMUNITIES.len() })
48+
.take(if show_more { 5 } else { communities.len() })
2249
.map(|item| {
2350
let image_src = if cfg!(debug_assertions)
2451
&& item.brand_src.starts_with("/gen_assets")
@@ -40,12 +67,11 @@ pub fn OtherCommunities(#[prop(default = false)] show_more: bool) -> impl IntoVi
4067
})
4168
.collect::<Vec<_>>()}
4269
</div>
43-
4470
{if show_more {
4571
view! {
4672
<div class="w-full flex justify-end my-3">
4773
<a
48-
href="/comunidad"
74+
href="/comunidades"
4975
class="text-black/80 dark:text-white/80 hover:text-orange-500 fill-black/80 dark:fill-white/80 hover:fill-orange-500 font-work-sans font-light text-2xl flex justify-center items-center"
5076
>
5177
"Ver todas las comunidades"

src/models/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[derive(Clone)]
12
pub struct CommunityItem {
23
pub name: &'static [&'static str],
34
pub description: &'static str,
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use leptos::{component, view, IntoView};
22

3-
use crate::components::{CommunityProjects, OtherCommunities};
3+
use crate::components::OtherCommunities;
44

55
#[component]
6-
pub fn Communidad() -> impl IntoView {
6+
pub fn Communities() -> impl IntoView {
77
view! {
88
<div>
9-
<CommunityProjects/>
109
<OtherCommunities/>
10+
<OtherCommunities other_communities=true/>
1111
</div>
1212
}
1313
}

src/pages/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
mod aprende;
2-
mod communidad;
2+
mod communities;
33
mod contributors;
44
mod index;
5+
mod projects;
56

67
pub use aprende::Aprende;
7-
pub use communidad::Communidad;
8+
pub use communities::Communities;
89
pub use contributors::Contributors;
910
pub use index::Index;
11+
pub use projects::Projects;

src/pages/projects.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use leptos::{component, view, IntoView};
2+
3+
use crate::components::CommunityProjects;
4+
5+
#[component]
6+
pub fn Projects() -> impl IntoView {
7+
view! {
8+
<div class="mx-auto">
9+
<CommunityProjects/>
10+
11+
// TODO: Fetch all our projects from Discord using our API
12+
</div>
13+
}
14+
}

0 commit comments

Comments
 (0)