portfolio genericity

This commit is contained in:
Mylloon 2024-01-25 18:23:07 +01:00
parent bc14e1b393
commit c787171d6b
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 14 additions and 9 deletions

View file

@ -20,6 +20,7 @@ async fn page(config: web::Data<Config>) -> impl Responder {
#[derive(Content, Debug)] #[derive(Content, Debug)]
struct PortfolioTemplate<'a> { struct PortfolioTemplate<'a> {
navbar: NavBar, navbar: NavBar,
about: Option<File>,
location_apps: Option<&'a str>, location_apps: Option<&'a str>,
apps: Option<Vec<File>>, apps: Option<Vec<File>>,
archived_apps: Option<Vec<File>>, archived_apps: Option<Vec<File>>,
@ -30,22 +31,29 @@ struct PortfolioTemplate<'a> {
#[once(time = 60)] #[once(time = 60)]
fn build_page(config: Config) -> String { fn build_page(config: Config) -> String {
let projects_dir = format!("{}/projects", config.locations.data_dir); let projects_dir = format!("{}/projects", config.locations.data_dir);
let apps_dir = format!("{}/apps", projects_dir);
let ext = ".md"; let ext = ".md";
// Get about
let about = read_file(
&format!("{}/about.md", projects_dir),
TypeFileMetadata::Generic,
);
// Get apps // Get apps
let apps = glob(&format!("{projects_dir}/*{ext}")) let apps = glob(&format!("{apps_dir}/*{ext}"))
.unwrap() .unwrap()
.map(|e| read_file(&e.unwrap().to_string_lossy(), TypeFileMetadata::Portfolio).unwrap()) .map(|e| read_file(&e.unwrap().to_string_lossy(), TypeFileMetadata::Portfolio).unwrap())
.collect::<Vec<File>>(); .collect::<Vec<File>>();
let appdata = if apps.is_empty() { let appdata = if apps.is_empty() {
(None, Some(projects_dir.as_str())) (None, Some(apps_dir.as_str()))
} else { } else {
(Some(apps), None) (Some(apps), None)
}; };
// Get archived apps // Get archived apps
let archived_apps = glob(&format!("{projects_dir}/archive/*{ext}")) let archived_apps = glob(&format!("{apps_dir}/archive/*{ext}"))
.unwrap() .unwrap()
.map(|e| read_file(&e.unwrap().to_string_lossy(), TypeFileMetadata::Portfolio).unwrap()) .map(|e| read_file(&e.unwrap().to_string_lossy(), TypeFileMetadata::Portfolio).unwrap())
.collect::<Vec<File>>(); .collect::<Vec<File>>();
@ -63,6 +71,7 @@ fn build_page(config: Config) -> String {
portfolio: true, portfolio: true,
..NavBar::default() ..NavBar::default()
}, },
about,
apps: appdata.0, apps: appdata.0,
location_apps: appdata.1, location_apps: appdata.1,
archived_apps: archived_appdata.0, archived_apps: archived_appdata.0,

View file

@ -10,14 +10,10 @@
<main> <main>
{{#data}} {{#data}}
<h1>Portfolio</h1> <h1>Portfolio</h1>
<p> {{#about}} {{&content}} {{/about}}
Je programme depuis 2018 et j'ai appris une multitude de langages
depuis. Étant passionné de logiciels libres depuis que je m'y intéresse,
je publie tout sur des forges publiques.
</p>
{{#location_apps}}
<!-- Error message --> <!-- Error message -->
{{#location_apps}}
<p>{{location_apps}} {{err_msg}}</p> <p>{{location_apps}} {{err_msg}}</p>
{{/location_apps}} {{^location_apps}} {{/location_apps}} {{^location_apps}}