|
1 |
| -use std::io::Write; |
| 1 | +use serde::{Deserialize, Serialize}; |
2 | 2 | use std::{
|
3 | 3 | fs,
|
4 | 4 | fs::{DirEntry, Metadata},
|
| 5 | + io::Write, |
5 | 6 | path::PathBuf,
|
6 | 7 | };
|
7 | 8 |
|
@@ -49,15 +50,37 @@ fn generate_comunity(path: PathBuf) {
|
49 | 50 | }
|
50 | 51 | let file_path = file.path();
|
51 | 52 | let toml_str = fs::read_to_string(&file_path).unwrap();
|
| 53 | + let toml_str = toml::from_str::<CommunityItem>(&toml_str).unwrap(); |
52 | 54 | comunities.push((file_path, toml_str));
|
53 | 55 | }
|
54 | 56 | let mut out = fs::File::create("src/extras/comunities.rs").unwrap();
|
55 |
| - write!(out, "use crate::models::CommunityItem;\npub const OTHER_COMUNITIES: &[CommunityItem] = &[\n").unwrap(); |
| 57 | + write!( |
| 58 | + out, |
| 59 | + "use crate::models::CommunityItem;\npub const OTHER_COMUNITIES: &[CommunityItem] = &[\n" |
| 60 | + ) |
| 61 | + .unwrap(); |
56 | 62 | for (_p, t) in comunities {
|
57 |
| - write!(out, r#" |
| 63 | + let CommunityItem { |
| 64 | + name, |
| 65 | + description, |
| 66 | + link, |
| 67 | + icon, |
| 68 | + brand_src, |
| 69 | + brand_alt, |
| 70 | + } = t; |
| 71 | + write!( |
| 72 | + out, |
| 73 | + r#" |
58 | 74 | CommunityItem {{
|
59 |
| - {t} |
60 |
| - }},"#).unwrap(); |
| 75 | + name: &{name:?}, |
| 76 | + description: "{description}", |
| 77 | + link: "{link}", |
| 78 | + icon: "{icon}", |
| 79 | + brand_src: "{brand_src}", |
| 80 | + brand_alt: "{brand_alt}", |
| 81 | + }},"# |
| 82 | + ) |
| 83 | + .unwrap(); |
61 | 84 | }
|
62 | 85 | write!(out, "\n];").unwrap();
|
63 | 86 | }
|
@@ -89,25 +112,65 @@ fn generate_projects(path: PathBuf) {
|
89 | 112 | }
|
90 | 113 | let file_path = file.path();
|
91 | 114 | let toml_str = fs::read_to_string(&file_path).unwrap();
|
| 115 | + let toml_str = toml::from_str::<ProjectItem>(&toml_str).unwrap(); |
92 | 116 | projects.push((category.clone(), file_path, toml_str));
|
93 | 117 | });
|
94 | 118 | });
|
95 | 119 |
|
96 | 120 | let mut out = fs::File::create("src/extras/projects.rs").unwrap();
|
97 |
| - write!(out, "use crate::models::ProjectItem;\npub const COMUNITY_PROJECTS: &[ProjectItem] = &[\n").unwrap(); |
| 121 | + write!( |
| 122 | + out, |
| 123 | + "use crate::models::ProjectItem;\npub const COMUNITY_PROJECTS: &[ProjectItem] = &[\n" |
| 124 | + ) |
| 125 | + .unwrap(); |
98 | 126 | for (_c, _p, t) in projects {
|
99 |
| - // name: , |
100 |
| - // description: , |
101 |
| - // link: , |
102 |
| - // brand_src: , |
103 |
| - // button_link: , |
104 |
| - // button_text: , |
105 |
| - // brand_as_letter: |
106 |
| - // button_bg_color: , |
107 |
| - write!(out, r#" |
| 127 | + let ProjectItem { |
| 128 | + name, |
| 129 | + description, |
| 130 | + link, |
| 131 | + brand_src, |
| 132 | + button_link, |
| 133 | + button_text, |
| 134 | + brand_as_letter, |
| 135 | + button_bg_color, |
| 136 | + } = t; |
| 137 | + write!( |
| 138 | + out, |
| 139 | + r#" |
108 | 140 | ProjectItem {{
|
109 |
| - {t} |
110 |
| - }},"#).unwrap(); |
| 141 | + name: &{name:?}, |
| 142 | + description: "{description}", |
| 143 | + link: "{link}", |
| 144 | + brand_src: "{brand_src}", |
| 145 | + button_link: "{button_link}", |
| 146 | + button_text: "{button_text}", |
| 147 | + brand_as_letter: {brand_as_letter}, |
| 148 | + button_bg_color: "{button_bg_color}", |
| 149 | + }},"# |
| 150 | + ) |
| 151 | + .unwrap(); |
111 | 152 | }
|
112 | 153 | write!(out, "\n];").unwrap();
|
113 | 154 | }
|
| 155 | + |
| 156 | +#[derive(Serialize, Deserialize)] |
| 157 | +struct CommunityItem { |
| 158 | + pub name: Vec<String>, |
| 159 | + pub description: String, |
| 160 | + pub link: String, |
| 161 | + pub icon: String, |
| 162 | + pub brand_src: String, |
| 163 | + pub brand_alt: String, |
| 164 | +} |
| 165 | + |
| 166 | +#[derive(Serialize, Deserialize)] |
| 167 | +struct ProjectItem { |
| 168 | + pub name: Vec<String>, |
| 169 | + pub description: String, |
| 170 | + pub link: String, |
| 171 | + pub brand_src: String, |
| 172 | + pub button_link: String, |
| 173 | + pub button_text: String, |
| 174 | + pub brand_as_letter: bool, |
| 175 | + pub button_bg_color: String, |
| 176 | +} |
0 commit comments