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.rs49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/blog/post.rs b/src/blog/post.rs
index 3e4a0d6..353c0a1 100644
--- a/src/blog/post.rs
+++ b/src/blog/post.rs
@@ -1,11 +1,10 @@
-use std::{cmp::Ordering, path::PathBuf};
+use color_eyre::eyre::{eyre, Context, Result};
use glob::glob;
-use color_eyre::eyre::{Result, Context, eyre};
-use tokio::{fs};
+use std::{cmp::Ordering, path::PathBuf};
+use tokio::fs;
use chrono::prelude::*;
-
#[derive(Eq, PartialEq, Debug, Clone)]
pub struct Post {
pub front_matter: frontmatter::Data,
@@ -42,20 +41,24 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> {
let link = format!("{}/{}", dir, fname.file_stem().unwrap().to_str().unwrap());
let body_html = crate::internal::markdown::render(&body)
.wrap_err_with(|| format!("can't parse markdown for {:?}", fname))?;
- 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 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,
+ link,
date,
author: author.clone(),
draft: draft.clone(),
- } )
+ })
}
pub async fn load(dir: &str) -> Result<Vec<Post>> {
@@ -78,12 +81,12 @@ pub async fn load(dir: &str) -> Result<Vec<Post>> {
result.sort();
result.reverse();
Ok(result)
- }
+ }
}
mod frontmatter {
- use serde::{Serialize, Deserialize};
use color_eyre::eyre::Result;
+ use serde::{Deserialize, Serialize};
#[derive(Eq, PartialEq, Deserialize, Default, Debug, Serialize, Clone)]
pub struct Data {
pub title: String,
@@ -129,19 +132,17 @@ mod frontmatter {
count: 1,
end: false,
};
- },
- '\n' | '\t' | ' ' => {
-
- },
+ }
+ '\n' | '\t' | ' ' => {}
_ => {
panic!("Start of frontmatter not found!");
}
},
- ParseState::ReadingMark {count, end } => match ch {
+ ParseState::ReadingMark { count, end } => match ch {
'-' => {
*count += 1;
if *count == 3 {
- state = ParseState::SkipNewLine{ end: *end };
+ state = ParseState::SkipNewLine { end: *end };
}
}
_ => {
@@ -159,29 +160,29 @@ mod frontmatter {
line_start: true,
};
}
- },
- _ => {
+ }
+ _ => {
panic!("Expected newline, got {:?}", ch);
}
},
ParseState::ReadingFM { buf, line_start } => match ch {
'-' if *line_start => {
- let mut state_tmp = ParseState::ReadingMark {
+ let mut state_tmp = ParseState::ReadingMark {
count: 1,
end: true,
};
std::mem::swap(&mut state, &mut state_tmp);
- if let ParseState::ReadingFM {buf, ..} = state_tmp {
+ if let ParseState::ReadingFM { buf, .. } = state_tmp {
payload = Some(buf);
} else {
unreachable!();
}
- },
+ }
ch => {
buf.push(ch);
*line_start = ch == '\n';
}
- }
+ },
}
}