Crates.io | gen-bsky |
lib.rs | gen-bsky |
version | 0.0.1 |
created_at | 2025-07-31 11:45:06.641239+00 |
updated_at | 2025-08-12 12:42:36.484608+00 |
description | A Library to generate and post a bluesky post |
homepage | |
repository | https://github.com/jerus-org/pcu |
max_upload_size | |
id | 1774948 |
size | 129,373 |
A library to generate a bluesky post.
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:
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();
}
Licensed under either of
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.