Post date & tags

This commit is contained in:
Thomas
2021-03-29 16:59:17 +02:00
parent b0ee8e2c23
commit a315f5eb24
24 changed files with 70 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
---
title: Blender 2020
description: 2020 blender artworks
tags: 2020 blender artworks
date: 2020-01-01
yearonly: true
url: 2020.html

View File

@@ -1,6 +1,6 @@
---
title: Blender 2021
description: 2021 blender artworks
tags: 2021 blender artworks
date: 2021-01-01
yearonly: true
url: 2021.html

View File

@@ -1,6 +1,6 @@
---
title: Les sites web perso
description: blog sites perso
tags: blog sites perso
date: 2020-01-04
yearonly: false
url: les-sites-web-perso.html

View File

@@ -1,6 +1,6 @@
---
title: La grande virtualization
description: docker virtualization
tags: docker virtualization
date: 2020-01-12
yearonly: false
url: la-grande-virtualization.html

View File

@@ -1,6 +1,6 @@
---
title: Migration gitea vers docker
description: gitea docker
tags: gitea docker
date: 2020-03-03
yearonly: false
url: migration-gitea-docker.html

View File

@@ -1,6 +1,6 @@
---
---
title: Faire une PWA avec VueJS
description: docker vuejs buefy
tags: docker vuejs buefy
date: 2020-03-07
yearonly: false
url: pwavuejs.html

View File

@@ -1,6 +1,6 @@
---
title: Sculpter avec Blender
description: sculpt blender 3D
tags: sculpt blender 3D
date: 2020-04-19
yearonly: false
url: sculptblender.html

View File

@@ -1,6 +1,6 @@
---
title: Les frameworks Javascript
description: javascript framework
tags: javascript framework
date: 2020-04-23
yearonly: false
url: vanillajs.html

View File

@@ -1,6 +1,6 @@
---
title: Sculpter avec Blender 2
description: sculpt blender 3D
tags: sculpt blender 3D
date: 2020-06-06
yearonly: false
url: sculptblender2.html

View File

@@ -1,6 +1,6 @@
---
title: Setup Gitea / Drone / Docker
description: gitea drone cicd docker
tags: gitea drone cicd docker
date: 2021-01-15
yearonly: false
url: giteadronedocker.html

View File

@@ -1,6 +1,6 @@
---
title: Initial2D
description: A simple GTK race game
tags: A simple GTK race game
date: 2018-01-01
yearonly: true
url: initial2D.html

View File

@@ -1,6 +1,6 @@
---
title: Oozik
description: Lecteur de musique collaboratif
tags: Lecteur de musique collaboratif
date: 2019-01-01
yearonly: true
url: oozik.html

View File

@@ -1,6 +1,6 @@
---
title: NexusV6
description: Main website, iteration 6
tags: Main website, iteration 6
date: 2019-02-01
yearonly: true
url: nexusv6.html

View File

@@ -1,6 +1,6 @@
---
title: Etienne's Remote
description: Une télécommande de soundboard
tags: Une télécommande de soundboard
date: 2020-01-01
yearonly: true
url: etienneremote.html

View File

@@ -1,6 +1,6 @@
---
title: Cloud32
description: Un cloud personnel pas pratique
tags: Un cloud personnel pas pratique
date: 2020-02-01
yearonly: true
url: cloud32.html

View File

@@ -1,6 +1,6 @@
---
title: LilStreamy
description: application web video p2p
tags: application web video p2p
date: 2020-03-01
yearonly: true
url: lilstreamy.html

View File

@@ -1,6 +1,6 @@
---
title: Mozen
description: Bibliothèque de machine learning
tags: Bibliothèque de machine learning
date: 2020-04-01
yearonly: true
url: mozen.html

View File

@@ -1,6 +1,6 @@
---
title: Voozik
description: Application web musique/video p2p
tags: Application web musique/video p2p
date: 2020-05-01
yearonly: true
url: voozik.html

View File

@@ -1,6 +1,6 @@
---
title: Tron.io
description: Jeu web
tags: Jeu web
date: 2020-06-01
yearonly: true
url: tronio.html

View File

@@ -1,6 +1,6 @@
---
title: NexusV7
description: Static site generator
tags: Static site generator
tags: rust, static site generator
date: 2021-01-01
yearonly: true

View File

@@ -54,6 +54,8 @@ fn load_section(dir_entry: &DirEntry) -> Section {
let section_name = dir_entry.file_name().into_string().unwrap();
let section_url = section_name.to_lowercase().trim().replace(" ", "_");
section_posts.sort_by(|a, b| b.date_compare.partial_cmp(&a.date_compare).unwrap());
println!("[LOADER] Loaded section {} with {} posts", section_name, section_posts.len());
return Section {

View File

@@ -8,8 +8,9 @@ use crate::markdown::marky::Marky;
pub struct Post {
pub title: String,
pub date: String,
pub date_compare: i32,
pub date_printable: String,
pub url: String,
pub description: String,
pub tags: Vec<String>,
pub body: String,
pub is_year_only: bool,
@@ -17,11 +18,30 @@ pub struct Post {
impl Post {
pub fn from_marky(marky: Marky) -> Post {
let date = marky.metadata.get("date").map_or(String::from("none"), String::from);
let is_year_only = marky.metadata.get("yearonly").map_or(false, |a| a == "true");
let (year, month, day) = to_date_number(&date);
let date_compare = year * 1200 + month * 100 + day;
let mut date_printable = String::new();
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());
}
Post {
title: marky.metadata.get("title").map_or(String::from("none"), String::from),
date: marky.metadata.get("date").map_or(String::from("none"), String::from),
date: date,
date_compare: date_compare,
date_printable: date_printable,
url: marky.metadata.get("url").map_or(String::from("none"), String::from),
description: marky.metadata.get("description").map_or(String::from("none"), String::from),
tags: tags_string_to_vec(marky.metadata.get("tags").map_or(String::from("none"), String::from)),
is_year_only: marky.metadata.get("yearonly").map_or(false, |a| a == "true"),
body: to_html(&marky.content),
@@ -30,5 +50,20 @@ impl Post {
}
fn tags_string_to_vec(tags: String) -> Vec<String> {
return tags.split(",").map(String::from).collect();
return tags.split_whitespace().map(String::from).collect();
}
// Convert yyyy-MM-dd to yyyy, MM, dd
fn to_date_number(date: &String) -> (i32, i32, i32) {
let split: Vec<&str> = date.split("-").collect();
if split.len() == 0 {
return (0, 0, 0);
}
let year = split[0].parse::<i32>().unwrap();
let month = split[1].parse::<i32>().unwrap();
let day = split[2].parse::<i32>().unwrap();
return (year, month, day);
}

View File

@@ -1,7 +1,12 @@
<div class="contentContainer">
<article>
<h1>{{post.title}}</h1>
<h5>{{post.date}}</h5>
<h5>
{{#each post.tags}}
<span>{{this}}</span>
{{/each}}
</h5>
<h5>{{post.date_printable}}</h5>
<hr/>
{{{post.body}}}
<hr/>

View File

@@ -7,7 +7,7 @@
{{#each section.posts}}
<a href="{{this.url}}">
<span class="postTitle">{{this.title}}</span>
<span class="postDate">{{this.date}}</span>
<span class="postDate">{{this.date_printable}}</span>
</a>
{{/each}}
</nav>