gen-bsky

Crates.iogen-bsky
lib.rsgen-bsky
version0.0.1
created_at2025-07-31 11:45:06.641239+00
updated_at2025-08-12 12:42:36.484608+00
descriptionA Library to generate and post a bluesky post
homepage
repositoryhttps://github.com/jerus-org/pcu
max_upload_size
id1774948
size129,373
Jeremiah Russell (jerusdp)

documentation

README

Gen-bsky

A library to generate a bluesky post.

Rust 1.87+ circleci-badge Crates.io Docs MIT licensed APACHE licensed BuyMeaCoffee GitHubSponsors

Feature set

  • Create and save a bluesky post record
  • Login and post the record to a bluesky account

Drafts and posts bluesky feed posts for a markdown blog files. The details for the posts are generated from the front matter metadata in the blog post. To maximize the characters available for post title, description and tags a short-name referrer can be generated and hosted on the same website. Drafting and posting are two separate steps to allow for the following workflow:

  1. Draft the bluesky post when building the website from the markdown files.
  • Generate the shortcut referrer and write to shortcut store
  • Generate the text for the bluesky post and save to a store in the repo.
  1. Post the bluesky post when publishing the website
  • For each post saved in the store post to bluesky
  • Delete posts that have been successfully sent

Draft Example

The following sample builds the draft structure and then write the referrer and the bluesky posts. As the referrer has been written when the bluesky post is generated using the shorter link to the referrer. (e.g. https://www.example.com/s/A4t5rb.html instead of https://www.example.com/blog/gen-bsky-release-version-1.3.0/).

use gen_bsky::{Draft, DraftError};
use url::Url;

#[tokio::main]
async fn main()  {
    // Set values for the base_url, paths to the blog post markdown files.
    // And if required a minimum date to allow processing of posts marked as draft.

    let base_url = Url::parse("https://www.example.com/").unwrap();
    let root = None; // Current directory is root for markdown files
    let paths = vec!["content/blog".to_string()];
    let date = toml::value::Datetime {
                  date: Some(toml::value::Date{
                              year: 2025,
                              month: 8,
                              day: 4}),
                  time: None,
                  offset: None};
    let allow_draft = false;

    // Initialise with the `base_url` and the `root`.
    let mut builder = Draft::builder(base_url, None);
   
    // Add the paths.
    for path in paths.iter() {
        builder.add_path_or_file(path).unwrap();
    }
   
    // Set the filters for blog posts
    builder
    .with_minimum_date(date).unwrap()
    .with_allow_draft(allow_draft);
   
    // Build the Draft posts
    let mut posts = builder.build().await.unwrap();
   
    // Write the referrers. Generating the short links for the posts
    posts.write_referrers(None).unwrap();

    // Write the bluesky posts using the short link
    posts.write_bluesky_posts(None).await.unwrap();
}

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 2266

cargo fmt