From 25a330b1a4b1974d3fe5452bf285e58b4253ccc4 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 29 Mar 2021 17:44:45 +0200 Subject: [PATCH] Fixed date display & posts update --- raws/projets/2019-02-01_nexusV6.md | 2 +- raws/projets/2021-01-01_nexusV7.md | 2 +- src/generator/models/post.rs | 31 +++++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/raws/projets/2019-02-01_nexusV6.md b/raws/projets/2019-02-01_nexusV6.md index 1f3932c..f4f02b1 100644 --- a/raws/projets/2019-02-01_nexusV6.md +++ b/raws/projets/2019-02-01_nexusV6.md @@ -1,6 +1,6 @@ --- title: NexusV6 -tags: Main website, iteration 6 +tags: typescript pug markdown static site generator date: 2019-02-01 yearonly: true url: nexusv6.html diff --git a/raws/projets/2021-01-01_nexusV7.md b/raws/projets/2021-01-01_nexusV7.md index a93df7c..9b71686 100644 --- a/raws/projets/2021-01-01_nexusV7.md +++ b/raws/projets/2021-01-01_nexusV7.md @@ -10,6 +10,6 @@ git: [git.gltronic.ovh/gltron/NexusV7](https://git.gltronic.ovh/gltron/NexusV7) app: [gltronic.ovh](https://gltronic.ovh) -NexusV7 est un générateur de site statique écrit Rust. +NexusV7 est un générateur de site statique écrit en Rust. La génération repose sur les templates handlebars & des fichiers markdown contenant des metadata. diff --git a/src/generator/models/post.rs b/src/generator/models/post.rs index 46d8d59..49f802d 100644 --- a/src/generator/models/post.rs +++ b/src/generator/models/post.rs @@ -29,11 +29,7 @@ impl Post { if is_year_only { date_printable.push_str(&year.to_string()); } else { - date_printable.push_str(&day.to_string()); - date_printable.push_str("-"); - date_printable.push_str(&month.to_string()); - date_printable.push_str("-"); - date_printable.push_str(&year.to_string()); + date_printable = beautify_date(day, month, year); } Post { @@ -66,4 +62,29 @@ fn to_date_number(date: &String) -> (i32, i32, i32) { let day = split[2].parse::().unwrap(); return (year, month, day); +} + +fn beautify_date(day: i32, month: i32, year: i32) -> String { + let mut date = String::new(); + if day < 10 { + date.push_str("0"); + date.push_str(&day.to_string()); + } else { + date.push_str(&day.to_string()); + } + + date.push_str("-"); + + if month < 10 { + date.push_str("0"); + date.push_str(&month.to_string()); + } else { + date.push_str(&month.to_string()); + } + + date.push_str("-"); + + date.push_str(&year.to_string()); + + date } \ No newline at end of file