summaryrefslogtreecommitdiff
path: root/src/blog/post.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/blog/post.rs')
-rw-r--r--src/blog/post.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/blog/post.rs b/src/blog/post.rs
index 3c27690..3e4a0d6 100644
--- a/src/blog/post.rs
+++ b/src/blog/post.rs
@@ -12,6 +12,8 @@ pub struct Post {
pub body_html: String,
pub date: DateTime<FixedOffset>,
pub link: String,
+ pub author: String,
+ pub draft: bool,
}
impl Ord for Post {
@@ -43,12 +45,16 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
let date: DateTime<FixedOffset> = DateTime::<Utc>::from_utc(NaiveDateTime::new(date, NaiveTime::from_hms(0,0,0)), Utc)
.with_timezone(&Utc)
.into();
+ let author = &front_matter.clone().author.unwrap_or("Cara Salter".to_string());
+ let draft = &front_matter.clone().draft.unwrap_or(false);
Ok(Post {
front_matter,
body_html,
- link,
- date
+ link,
+ date,
+ author: author.clone(),
+ draft: draft.clone(),
} )
}
@@ -61,8 +67,11 @@ pub async fn load(dir: &str) -> Result<Vec<Post>> {
.await
.into_iter()
.map(Result::unwrap)
+ .filter(|p| !p.draft)
.collect();
+ info!("Loaded {:?} posts", result.len());
+
if result.len() == 0 {
Err(eyre!("No posts found"))
} else {
@@ -81,6 +90,8 @@ mod frontmatter {
pub date: String,
pub series: Option<Vec<String>>,
pub tags: Option<Vec<String>>,
+ pub author: Option<String>,
+ pub draft: Option<bool>,
}
enum ParseState {
@@ -134,7 +145,7 @@ mod frontmatter {
}
}
_ => {
- panic!("Malformed frontmatter");
+ panic!("Malformed frontmatter: {:?}", input);
}
},
ParseState::SkipNewLine { end } => match ch {