Skip to content

Commit 46c8931

Browse files
committed
og_image: Add README file
1 parent 9ae5016 commit 46c8931

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

crates/crates_io_og_image/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# crates_io_og_image
2+
3+
A Rust crate for generating Open Graph images for crates.io packages.
4+
5+
![Example OG Image](src/snapshots/crates_io_og_image__tests__generated_og_image.snap.png)
6+
7+
## Overview
8+
9+
`crates_io_og_image` is a specialized library for generating visually appealing Open Graph images for Rust crates. These images are designed to be displayed when crates.io links are shared on social media platforms, providing rich visual context about the crate including its name, description, authors, and key metrics.
10+
11+
The generated images include:
12+
- Crate name and description
13+
- Tags/keywords
14+
- Author information with avatars (when available)
15+
- Key metrics (releases, latest version, license, lines of code, size)
16+
- Consistent crates.io branding
17+
18+
## Requirements
19+
20+
- The [Typst](https://typst.app/) CLI must be installed and available in your `PATH`
21+
22+
## Usage
23+
24+
### Basic Example
25+
26+
```rust
27+
use crates_io_og_image::{OgImageData, OgImageGenerator, OgImageAuthorData};
28+
29+
#[tokio::main]
30+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
31+
// Create a generator instance
32+
let generator = OgImageGenerator::default();
33+
34+
// Define the crate data
35+
let data = OgImageData {
36+
name: "example-crate",
37+
version: "v1.2.3",
38+
description: "An example crate for testing OpenGraph image generation",
39+
license: "MIT/Apache-2.0",
40+
tags: &["example", "testing", "og-image"],
41+
authors: &[
42+
OgImageAuthorData::with_url(
43+
"Turbo87",
44+
"https://avatars.githubusercontent.com/u/141300",
45+
),
46+
],
47+
lines_of_code: Some(2000),
48+
crate_size: 75,
49+
releases: 5,
50+
};
51+
52+
// Generate the image
53+
let temp_file = generator.generate(data).await?;
54+
55+
// The temp_file contains the path to the generated PNG image
56+
println!("Image generated at: {}", temp_file.path().display());
57+
58+
Ok(())
59+
}
60+
```
61+
62+
## Configuration
63+
64+
The path to the Typst CLI can be configured through the `TYPST_PATH` environment variables.
65+
66+
## Development
67+
68+
### Running Tests
69+
70+
```bash
71+
cargo test
72+
```
73+
74+
Note that some tests require Typst to be installed and will be skipped if it's not available.
75+
76+
### Example
77+
78+
The crate includes an example that demonstrates how to generate an image:
79+
80+
```bash
81+
cargo run --example test_generator
82+
```
83+
84+
This will generate a test image in the current directory. This will also test the avatar fetching functionality, which requires network access and isn't run as part of the automated tests.
85+
86+
## License
87+
88+
Licensed under either of:
89+
90+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
91+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
92+
93+
at your option.

0 commit comments

Comments
 (0)