Begin add markdown parsing
Some checks failed
deploy / docker (push) Has been cancelled

This commit is contained in:
Florian RICHER 2023-11-26 15:36:01 +01:00
parent aca074ef01
commit 34e81035d0
9 changed files with 208 additions and 0 deletions

55
src/app/models/post.rs Normal file
View file

@ -0,0 +1,55 @@
pub struct PostMetadata {
image_path: Option<String>,
title: String,
date: String,
description: String,
project_link: Option<String>,
}
pub struct Post {
metadata: PostMetadata,
content: String,
}
cfg_if::cfg_if! {
if #[cfg(feature = "ssr")] {
impl From<String> for Post {
fn from(content: String) -> Self {
use pulldown_cmark::{Parser, Options, html};
let parser = Parser::new_ext(&content, Options::all());
let mut html_output = String::new();
html::push_html(&mut html_output, parser);
println!("\nHTML output:\n{}\n", &html_output);
Self {
metadata: PostMetadata {
image_path: None,
title: String::from(""),
date: String::from(""),
description: String::from(""),
project_link: None,
},
content: html_output,
}
}
}
impl Post {
pub fn get_all() -> Result<Vec<Self>, String> {
let files_content = super::super::server::utils::get_files_content_with_blob("posts/*.md")?;
let mut posts: Vec<Self> = Vec::new();
for (_filename, content) in files_content {
let post = Self::from(content);
posts.push(post);
}
Ok(posts)
}
}
}
}