summaryrefslogtreecommitdiff
path: root/src/posts
diff options
context:
space:
mode:
Diffstat (limited to 'src/posts')
-rw-r--r--src/posts/abstractions/post.rs1
-rw-r--r--src/posts/fs_post.rs19
2 files changed, 19 insertions, 1 deletions
diff --git a/src/posts/abstractions/post.rs b/src/posts/abstractions/post.rs
index a941281..9667828 100644
--- a/src/posts/abstractions/post.rs
+++ b/src/posts/abstractions/post.rs
@@ -3,4 +3,5 @@ use std::{borrow::Cow, fmt};
pub trait Post: fmt::Debug + Ord {
fn get_title(&self) -> &str;
fn get_article(&self) -> Cow<str>;
+ fn get_description(&self) -> Cow<str>;
}
diff --git a/src/posts/fs_post.rs b/src/posts/fs_post.rs
index 8b8e725..12ce538 100644
--- a/src/posts/fs_post.rs
+++ b/src/posts/fs_post.rs
@@ -1,3 +1,5 @@
+use comrak::Options;
+
use crate::posts::abstractions::post::Post;
use std::{borrow::Cow, fs, path::PathBuf};
@@ -19,7 +21,22 @@ impl Post for FsPost {
fn get_article(&self) -> Cow<str> {
let article = fs::read_to_string(&self.file).unwrap();
- Cow::Owned(article)
+ Cow::Owned(comrak::markdown_to_html(&article, &Options::default()))
+ }
+
+ fn get_description(&self) -> Cow<str> {
+ let article = self.get_article();
+ Cow::Owned(
+ article
+ .split_once('\n')
+ .map(|(first, _)| first)
+ .unwrap_or_default()
+ .trim_start_matches('_')
+ .trim_start_matches('*')
+ .trim_end_matches('_')
+ .trim_end_matches('*')
+ .to_owned(),
+ )
}
}