aboutsummaryrefslogtreecommitdiff
path: root/src/post
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2020-09-19 11:33:46 -0400
committerGitHub <noreply@github.com>2020-09-19 11:33:46 -0400
commita2fba89738caac83ce24d40b762d6205f2266361 (patch)
tree3a61afb3b1a9d42b0a61b67be527322b6740f179 /src/post
parent1e61d2ad33f7ac7751063bdd373ab3d1305015e2 (diff)
downloadxesite-a2fba89738caac83ce24d40b762d6205f2266361.tar.xz
xesite-a2fba89738caac83ce24d40b762d6205f2266361.zip
TL;DR Rust (#210)
* start mara code * better alt text * more mara tests * cleanups * blog: start tl;dr rust post * more words * feature complete * little oopses * oops lol
Diffstat (limited to 'src/post')
-rw-r--r--src/post/frontmatter.rs2
-rw-r--r--src/post/mod.rs15
2 files changed, 10 insertions, 7 deletions
diff --git a/src/post/frontmatter.rs b/src/post/frontmatter.rs
index 1cc8032..615f2c5 100644
--- a/src/post/frontmatter.rs
+++ b/src/post/frontmatter.rs
@@ -1,6 +1,6 @@
/// This code was borrowed from @fasterthanlime.
-use anyhow::{Result};
+use color_eyre::eyre::{Result};
use serde::{Serialize, Deserialize};
#[derive(Eq, PartialEq, Deserialize, Default, Debug, Serialize, Clone)]
diff --git a/src/post/mod.rs b/src/post/mod.rs
index a948017..c0062a4 100644
--- a/src/post/mod.rs
+++ b/src/post/mod.rs
@@ -1,5 +1,5 @@
-use anyhow::{anyhow, Result};
use chrono::prelude::*;
+use color_eyre::eyre::{eyre, Result, WrapErr};
use glob::glob;
use std::{cmp::Ordering, fs};
@@ -75,8 +75,10 @@ pub fn load(dir: &str) -> Result<Vec<Post>> {
for path in glob(&format!("{}/*.markdown", dir))?.filter_map(Result::ok) {
log::debug!("loading {:?}", path);
- let body = fs::read_to_string(path.clone()).expect("things to work");
- let (fm, content_offset) = frontmatter::Data::parse(body.clone().as_str()).expect("stuff to work");
+ let body =
+ fs::read_to_string(path.clone()).wrap_err_with(|| format!("can't read {:?}", path))?;
+ let (fm, content_offset) = frontmatter::Data::parse(body.clone().as_str())
+ .wrap_err_with(|| format!("can't parse frontmatter of {:?}", path))?;
let markup = &body[content_offset..];
let date = NaiveDate::parse_from_str(&fm.clone().date, "%Y-%m-%d")?;
@@ -84,7 +86,8 @@ pub fn load(dir: &str) -> Result<Vec<Post>> {
front_matter: fm,
link: format!("{}/{}", dir, path.file_stem().unwrap().to_str().unwrap()),
body: markup.to_string(),
- body_html: crate::app::markdown(&markup),
+ body_html: crate::app::markdown::render(&markup)
+ .wrap_err_with(|| format!("can't parse markdown for {:?}", path))?,
date: {
DateTime::<Utc>::from_utc(
NaiveDateTime::new(date, NaiveTime::from_hms(0, 0, 0)),
@@ -97,7 +100,7 @@ pub fn load(dir: &str) -> Result<Vec<Post>> {
}
if result.len() == 0 {
- Err(anyhow!("no posts loaded"))
+ Err(eyre!("no posts loaded"))
} else {
result.sort();
result.reverse();
@@ -108,7 +111,7 @@ pub fn load(dir: &str) -> Result<Vec<Post>> {
#[cfg(test)]
mod tests {
use super::*;
- use anyhow::Result;
+ use color_eyre::eyre::Result;
#[test]
fn blog() {