diff --git a/Cargo.lock b/Cargo.lock index c2c7b45..ce4c02e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,7 +296,7 @@ dependencies = [ [[package]] name = "emile" -version = "0.5.0" +version = "0.5.1" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index fe8919c..2b55023 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "emile" -version = "0.5.0" +version = "0.5.1" authors = ["Geobert Quach "] edition = "2021" @@ -14,7 +14,7 @@ serde = "1.0.203" serde_derive = "1.0.203" slug = "0.1.5" notify = { version = "6.1.1", default-features = false } -clap = { version = "4.5.4", features = ["derive"] } +clap = { version = "4.5.4", features = ["derive", "cargo"] } lazy_static = "1.4.0" tokio = { version = "1.37.0", features = ["sync", "macros", "rt-multi-thread", "time"] } notify-debouncer-mini = { version = "0.4.1", default-features = false } diff --git a/README.md b/README.md index bb6473b..362877c 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ drafts_year_shift = 0 # emile will take this file to create a draft post by adding `title`, `date` and #`draft = true` in the frontmatter -draft_template = "templates/draft.html" +draft_template = "draft.txt" # Destination for `publish` command. publish_dest = "content/" @@ -75,7 +75,7 @@ link_template = "social_link.txt" # tag to put in the blog post, to be replaced by the `link_template` snippet to have link # to social media post -link_tag = "{% emile_social %}" +link_tag = "{$ emile_social $}" # if a tag match, use the associated lang (ex: [{ tag = "english", lang = "en" }]) tag_lang = [] @@ -83,7 +83,7 @@ tag_lang = [] # tag in the list will not be in the social post (ex: ["english", "misc"]) filtered_tag = [] -# social instances to post to. One per `api` (accepled values are "mastodon" or "bluesky"). +# social instances to post to. One per `api` (accepted values are "mastodon" or "bluesky"). #`*_var` are environment variable to read the needed value from. If `social` is present, # it cannot be empty # ex: @@ -189,7 +189,8 @@ in `social_template`. ### Social media link `emile` can add links to the social media posts it created so people can react on your -article. +article. The tag defined by `link_tag` will be replaced by the expanded template +`link_template`. The file specified in `link_template` must be in the `/template` directory. It must contains one `{links}` (plural) tag which will be expanded to a list of links to the diff --git a/src/config.rs b/src/config.rs index b001877..074249c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -194,7 +194,7 @@ impl SiteConfigBuilder { .unwrap_or_else(|| PathBuf::from("social_link.txt")), link_tag: cfg_builder .link_tag - .unwrap_or("{% emile_social %}".to_owned()), + .unwrap_or("{$ emile_social $}".to_owned()), instances: cfg_builder.instances, }); @@ -211,7 +211,7 @@ impl SiteConfigBuilder { drafts_year_shift: cfg_builder.drafts_year_shift.unwrap_or(0), draft_template: cfg_builder .draft_template - .unwrap_or_else(|| "draft.html".to_string()), + .unwrap_or_else(|| "draft.txt".to_string()), publish_dest: cfg_builder .publish_dest .unwrap_or_else(|| PathBuf::from("content/posts")), diff --git a/src/main.rs b/src/main.rs index efe3ecc..bd3971e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ mod watcher; use opt::{Commands, Opt}; use regex::Regex; -use tracing::error; +use tracing::{error, info}; use tracing_subscriber::{fmt::time::UtcTime, prelude::*, EnvFilter}; use watcher::SiteWatcher; @@ -55,6 +55,8 @@ async fn main() -> Result<()> { None }; + info!("emile {}", clap::crate_version!()); + match opt.command { Commands::New { title } => { let cfg = SiteConfigBuilder::get_config(); diff --git a/src/social/mastodon.rs b/src/social/mastodon.rs index 40d408a..042085e 100644 --- a/src/social/mastodon.rs +++ b/src/social/mastodon.rs @@ -1,7 +1,7 @@ -use anyhow::Result; -use reqwest::Url; +use anyhow::{bail, Result}; +use reqwest::{StatusCode, Url}; use serde_derive::{Deserialize, Serialize}; -use tracing::{error, info}; +use tracing::{error, info, warn}; use crate::config::SocialInstance; @@ -42,18 +42,24 @@ pub async fn push_to_mastodon( use sha2::{Digest, Sha256}; let hash = format!("{:x}", Sha256::digest(toot.status.as_bytes())); - let status = reqwest::Client::new() + let res = reqwest::Client::new() .post(&format!("https://{}/api/v1/statuses", instance.server)) .bearer_auth(&token) .header("Idempotency-Key", hash) .json(&toot) .send() - .await? - .json::() .await?; + if res.status() != StatusCode::OK { + let status = res.status(); + let text = res.text().await?; + bail!("Failed to push to Mastodon: {status}, {text}"); + } + + let status = res.json::().await?; + // bookmark it to avoid deletion and for easy retrieval - reqwest::Client::new() + let res = reqwest::Client::new() .post(&format!( "https://{}/api/v1/statuses/{}/bookmark", instance.server, status.id @@ -62,5 +68,11 @@ pub async fn push_to_mastodon( .send() .await?; + if res.status() != StatusCode::OK { + let status = res.status(); + let text = res.text().await?; + warn!("Failed to bookmark toot: {status}, {text}"); + } + Ok(Some(Url::parse(&status.uri)?)) }