From 7dfdd131e4346bdfda6a709e9de0c1e543d8554e Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 7 Jul 2021 21:17:01 -0400 Subject: closer integration into android, read estimates Signed-off-by: Christine Dodrill --- src/main.rs | 4 +++- src/post/mod.rs | 39 +++++++++++---------------------------- 2 files changed, 14 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 0576f97..bbe5658 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,6 +142,8 @@ async fn main() -> Result<()> { let sitemap = warp::path("sitemap.xml") .and(with_state(state.clone())) .and_then(handlers::feeds::sitemap); + let asset_links = warp::path!(".well-known" / "assetlinks.json") + .and(warp::fs::file("./static/assetlinks.json")); let go_vanity_jsonfeed = warp::path("jsonfeed") .and(warp::any().map(move || "christine.website/jsonfeed")) @@ -162,7 +164,7 @@ async fn main() -> Result<()> { }); let static_pages = index - .or(feeds) + .or(feeds.or(asset_links)) .or(resume.or(signalboost)) .or(patrons) .or(jsonfeed.or(atom.or(sitemap)).or(rss)) diff --git a/src/post/mod.rs b/src/post/mod.rs index 4c54404..acdd325 100644 --- a/src/post/mod.rs +++ b/src/post/mod.rs @@ -15,6 +15,7 @@ pub struct Post { pub date: DateTime, pub mentions: Vec, pub new_post: NewPost, + pub read_time_estimate_minutes: u64, } /// Used with the Android app to show information in a widget. @@ -80,33 +81,6 @@ impl Post { } } -fn trim(string: &str) -> String { - let mut buf = String::new(); - let mut capturing = false; - - for line in string.lines() { - if line.starts_with("#") { - continue; - } - - if line == "" { - if capturing && buf.len() > 260 { - break; - } else { - capturing = true; - continue; - } - } - - if capturing { - buf.push_str(" "); - buf.push_str(line); - } - } - - buf -} - async fn read_post(dir: &str, fname: PathBuf) -> Result { let body = fs::read_to_string(fname.clone()) .await @@ -133,9 +107,17 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result { Err(_) => vec![], }; + let time_taken = estimated_read_time::text( + &body, + &estimated_read_time::Options::new() + .build() + .unwrap_or_default(), + ); + let read_time_estimate_minutes = time_taken.seconds() / 60; + let new_post = NewPost { title: front_matter.title.clone(), - summary: trim(body).to_string(), + summary: format!("{} minute read", read_time_estimate_minutes), link: format!("https://christine.website/{}", link), }; @@ -146,6 +128,7 @@ async fn read_post(dir: &str, fname: PathBuf) -> Result { date, mentions, new_post, + read_time_estimate_minutes, }) } -- cgit v1.2.3