diff options
| author | Christine Dodrill <me@christine.website> | 2020-12-02 16:16:58 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-02 16:16:58 -0500 |
| commit | 233ea76204ea5bc9a7d8f12816a9525b7a732bc5 (patch) | |
| tree | de0ef2b37a6b8ee04f51eee3169ab29a472fa031 /src | |
| parent | d35f62351f800115e7f6aef7fd0791b9ac608229 (diff) | |
| download | xesite-233ea76204ea5bc9a7d8f12816a9525b7a732bc5.tar.xz xesite-233ea76204ea5bc9a7d8f12816a9525b7a732bc5.zip | |
add webmention support (#274)
* add webmention support
Signed-off-by: Christine Dodrill <me@christine.website>
* add webmention integration post
Signed-off-by: Christine Dodrill <me@christine.website>
Diffstat (limited to 'src')
| -rw-r--r-- | src/app/mod.rs | 11 | ||||
| -rw-r--r-- | src/post/mod.rs | 33 |
2 files changed, 30 insertions, 14 deletions
diff --git a/src/app/mod.rs b/src/app/mod.rs index c18e121..7cb0044 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -16,6 +16,8 @@ pub struct Config { pub(crate) resume_fname: PathBuf, #[serde(rename = "webMentionEndpoint")] pub(crate) webmention_url: String, + #[serde(rename = "miToken")] + pub(crate) mi_token: String, } #[instrument] @@ -58,6 +60,7 @@ pub struct State { pub jf: jsonfeed::Feed, pub sitemap: Vec<u8>, pub patrons: Option<patreon::Users>, + pub mi: mi::Client, } pub async fn init(cfg: PathBuf) -> Result<State> { @@ -65,9 +68,10 @@ pub async fn init(cfg: PathBuf) -> Result<State> { let sb = cfg.signalboost.clone(); let resume = fs::read_to_string(cfg.resume_fname.clone())?; let resume: String = markdown::render(&resume)?; - let blog = crate::post::load("blog")?; - let gallery = crate::post::load("gallery")?; - let talks = crate::post::load("talks")?; + let mi = mi::Client::new(cfg.mi_token.clone(), crate::APPLICATION_NAME.to_string())?; + let blog = crate::post::load("blog", Some(&mi)).await?; + let gallery = crate::post::load("gallery", None).await?; + let talks = crate::post::load("talks", None).await?; let mut everything: Vec<Post> = vec![]; { @@ -122,6 +126,7 @@ pub async fn init(cfg: PathBuf) -> Result<State> { urlwriter.end()?; Ok(State { + mi: mi, cfg: cfg, signalboost: sb, resume: resume, diff --git a/src/post/mod.rs b/src/post/mod.rs index c0062a4..c66e79c 100644 --- a/src/post/mod.rs +++ b/src/post/mod.rs @@ -12,6 +12,7 @@ pub struct Post { pub body: String, pub body_html: String, pub date: DateTime<FixedOffset>, + pub mentions: Vec<mi::WebMention>, } impl Into<jsonfeed::Item> for Post { @@ -70,7 +71,7 @@ impl Post { } } -pub fn load(dir: &str) -> Result<Vec<Post>> { +pub async fn load(dir: &str, mi: Option<&mi::Client>) -> Result<Vec<Post>> { let mut result: Vec<Post> = vec![]; for path in glob(&format!("{}/*.markdown", dir))?.filter_map(Result::ok) { @@ -81,10 +82,19 @@ pub fn load(dir: &str) -> Result<Vec<Post>> { .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")?; + let link = format!("{}/{}", dir, path.file_stem().unwrap().to_str().unwrap()); + let mentions: Vec<mi::WebMention> = match mi { + None => vec![], + Some(mi) => mi + .mentioners(format!("https://christine.website/{}", link)) + .await + .map_err(|why| tracing::error!("error: can't load mentions for {}: {}", link, why)) + .unwrap_or(vec![]), + }; result.push(Post { front_matter: fm, - link: format!("{}/{}", dir, path.file_stem().unwrap().to_str().unwrap()), + link: link, body: markup.to_string(), body_html: crate::app::markdown::render(&markup) .wrap_err_with(|| format!("can't parse markdown for {:?}", path))?, @@ -96,6 +106,7 @@ pub fn load(dir: &str) -> Result<Vec<Post>> { .with_timezone(&Utc) .into() }, + mentions: mentions, }) } @@ -113,23 +124,23 @@ mod tests { use super::*; use color_eyre::eyre::Result; - #[test] - fn blog() { + #[tokio::test] + async fn blog() { let _ = pretty_env_logger::try_init(); - load("blog").expect("posts to load"); + load("blog", None).await.expect("posts to load"); } - #[test] - fn gallery() -> Result<()> { + #[tokio::test] + async fn gallery() -> Result<()> { let _ = pretty_env_logger::try_init(); - load("gallery")?; + load("gallery", None).await?; Ok(()) } - #[test] - fn talks() -> Result<()> { + #[tokio::test] + async fn talks() -> Result<()> { let _ = pretty_env_logger::try_init(); - load("talks")?; + load("talks", None).await?; Ok(()) } } |
