The code and data behind xeiaso.net
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

use less ram

Signed-off-by: Christine Dodrill <me@christine.website>

+11 -6
+11 -6
src/post/mod.rs
··· 2 2 use color_eyre::eyre::{eyre, Result, WrapErr}; 3 3 use glob::glob; 4 4 use serde::Serialize; 5 - use std::{cmp::Ordering, path::PathBuf}; 5 + use std::{borrow::Borrow, cmp::Ordering, path::PathBuf}; 6 6 use tokio::fs; 7 7 8 8 pub mod frontmatter; ··· 81 81 } 82 82 } 83 83 84 - async fn read_post(dir: &str, fname: PathBuf) -> Result<Post> { 84 + async fn read_post(dir: &str, fname: PathBuf, cli: &Option<mi::Client>) -> Result<Post> { 85 85 let body = fs::read_to_string(fname.clone()) 86 86 .await 87 87 .wrap_err_with(|| format!("can't read {:?}", fname))?; ··· 98 98 .with_timezone(&Utc) 99 99 .into(); 100 100 101 - let mentions: Vec<mi::WebMention> = match std::env::var("MI_TOKEN") { 102 - Ok(token) => mi::Client::new(token.to_string(), crate::APPLICATION_NAME.to_string())? 101 + let mentions: Vec<mi::WebMention> = match cli { 102 + Some(cli) => cli 103 103 .mentioners(format!("https://christine.website/{}", link)) 104 104 .await 105 105 .map_err(|why| tracing::error!("error: can't load mentions for {}: {}", link, why)) ··· 109 109 wm.title.as_ref().unwrap_or(&"".to_string()) != &"Bridgy Response".to_string() 110 110 }) 111 111 .collect(), 112 - Err(_) => vec![], 112 + None => vec![], 113 113 }; 114 114 115 115 let time_taken = estimated_read_time::text( ··· 140 140 } 141 141 142 142 pub async fn load(dir: &str) -> Result<Vec<Post>> { 143 + let cli = match std::env::var("MI_TOKEN") { 144 + Ok(token) => mi::Client::new(token.to_string(), crate::APPLICATION_NAME.to_string()).ok(), 145 + Err(_) => None, 146 + }; 147 + 143 148 let futs = glob(&format!("{}/*.markdown", dir))? 144 149 .filter_map(Result::ok) 145 - .map(|fname| read_post(dir, fname)); 150 + .map(|fname| read_post(dir, fname, cli.borrow())); 146 151 147 152 let mut result: Vec<Post> = futures::future::join_all(futs) 148 153 .await