Skip to content

Commit c91a478

Browse files
committed
og_image: Make description and license optional and add version prefix in template
1 parent ec8cb2b commit c91a478

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

crates/crates_io_og_image/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ async fn main() -> Result<(), OgImageError> {
3535
// Define the crate data
3636
let data = OgImageData {
3737
name: "example-crate",
38-
version: "v1.2.3",
39-
description: "An example crate for testing OpenGraph image generation",
40-
license: "MIT/Apache-2.0",
38+
version: "1.2.3",
39+
description: Some("An example crate for testing OpenGraph image generation"),
40+
license: Some("MIT/Apache-2.0"),
4141
tags: &["example", "testing", "og-image"],
4242
authors: &[
4343
OgImageAuthorData::with_url(

crates/crates_io_og_image/examples/test_generator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2222
// Test generating an image
2323
let data = OgImageData {
2424
name: "example-crate",
25-
version: "v1.2.3",
26-
description: "An example crate for testing OpenGraph image generation",
27-
license: "MIT/Apache-2.0",
25+
version: "1.2.3",
26+
description: Some("An example crate for testing OpenGraph image generation"),
27+
license: Some("MIT/Apache-2.0"),
2828
tags: &["example", "testing", "og-image"],
2929
authors: &[
3030
OgImageAuthorData::new("example-user", None),

crates/crates_io_og_image/src/lib.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ use tracing::{debug, error, info, instrument, warn};
2222
pub struct OgImageData<'a> {
2323
/// The crate name
2424
pub name: &'a str,
25-
/// Latest version string (e.g., "v1.0.210")
25+
/// Latest version string (e.g., "1.0.210")
2626
pub version: &'a str,
2727
/// Crate description text
28-
pub description: &'a str,
28+
pub description: Option<&'a str>,
2929
/// License information (e.g., "MIT/Apache-2.0")
30-
pub license: &'a str,
30+
pub license: Option<&'a str>,
3131
/// Keywords/categories for the crate
3232
pub tags: &'a [&'a str],
3333
/// Author information
@@ -310,9 +310,9 @@ impl OgImageGenerator {
310310
/// let generator = OgImageGenerator::default();
311311
/// let data = OgImageData {
312312
/// name: "my-crate",
313-
/// version: "v1.0.0",
314-
/// description: "A sample crate",
315-
/// license: "MIT",
313+
/// version: "1.0.0",
314+
/// description: Some("A sample crate"),
315+
/// license: Some("MIT"),
316316
/// tags: &["web", "api"],
317317
/// authors: &[OgImageAuthorData { name: "user", avatar: None }],
318318
/// lines_of_code: Some(5000),
@@ -575,9 +575,9 @@ mod tests {
575575

576576
OgImageData {
577577
name: "minimal-crate",
578-
version: "v1.0.0",
579-
description: "A minimal crate",
580-
license: "MIT",
578+
version: "1.0.0",
579+
description: None,
580+
license: None,
581581
tags: &[],
582582
authors: AUTHORS,
583583
lines_of_code: None,
@@ -595,9 +595,11 @@ mod tests {
595595

596596
OgImageData {
597597
name: "crate-with-\"quotes\"",
598-
version: "v1.0.0-\"beta\"",
599-
description: "A crate with \"quotes\", \\ backslashes, and other special chars: #[]{}()",
600-
license: "MIT OR \"Apache-2.0\"",
598+
version: "1.0.0-\"beta\"",
599+
description: Some(
600+
"A crate with \"quotes\", \\ backslashes, and other special chars: #[]{}()",
601+
),
602+
license: Some("MIT OR \"Apache-2.0\""),
601603
tags: &[
602604
"tag-with-\"quotes\"",
603605
"tag\\with\\backslashes",
@@ -626,9 +628,11 @@ mod tests {
626628

627629
OgImageData {
628630
name: "super-long-crate-name-for-testing-overflow-behavior",
629-
version: "v2.1.0-beta.1+build.12345",
630-
description: "This is an extremely long description that tests how the layout handles descriptions that might wrap to multiple lines or overflow the available space in the OpenGraph image template design. This is an extremely long description that tests how the layout handles descriptions that might wrap to multiple lines or overflow the available space in the OpenGraph image template design.",
631-
license: "MIT/Apache-2.0/ISC/BSD-3-Clause",
631+
version: "2.1.0-beta.1+build.12345",
632+
description: Some(
633+
"This is an extremely long description that tests how the layout handles descriptions that might wrap to multiple lines or overflow the available space in the OpenGraph image template design. This is an extremely long description that tests how the layout handles descriptions that might wrap to multiple lines or overflow the available space in the OpenGraph image template design.",
634+
),
635+
license: Some("MIT/Apache-2.0/ISC/BSD-3-Clause"),
632636
tags: &[
633637
"web-framework",
634638
"async-runtime",
@@ -648,9 +652,9 @@ mod tests {
648652

649653
OgImageData {
650654
name: "test-crate",
651-
version: "v1.0.0",
652-
description: "A test crate for OpenGraph image generation",
653-
license: "MIT/Apache-2.0",
655+
version: "1.0.0",
656+
description: Some("A test crate for OpenGraph image generation"),
657+
license: Some("MIT/Apache-2.0"),
654658
tags: &["testing", "og-image"],
655659
authors: AUTHORS,
656660
lines_of_code: Some(1000),

crates/crates_io_og_image/template/og-image.typ

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@
273273
}
274274

275275
// Description
276-
block(text(size: 14pt, weight: "regular", truncate_to_height(data.at("description", default: ""), maxHeight: 60pt)))
276+
if data.at("description", default: none) != none {
277+
block(text(size: 14pt, weight: "regular", truncate_to_height(data.description, maxHeight: 60pt)))
278+
}
277279

278280
// Authors
279281
if data.at("authors", default: ()).len() > 0 {
@@ -293,7 +295,7 @@
293295
if data.at("releases", default: none) != none {
294296
render-metadata("Releases", data.releases, "tag")
295297
}
296-
render-metadata("Latest", truncate_to_width(data.version, maxWidth: 80pt), "code-branch")
298+
render-metadata("Latest", truncate_to_width("v" + data.version, maxWidth: 80pt), "code-branch")
297299
if data.at("license", default: none) != none {
298300
render-metadata("License", truncate_to_width(data.license, maxWidth: 100pt), "scale-balanced")
299301
}

0 commit comments

Comments
 (0)