Skip to content

Commit

Permalink
refactor: include id in og image creation and adjust image styling
Browse files Browse the repository at this point in the history
Refactored the create_og_image function to include a unique, more descriptive id for the OpenGraph images. This helps in better identification of each image. The logo image size has also been slightly revised for better visibility and aesthetics, incorporating the id into the image in a formatted, stylized manner. Adjustments have been made respectively in the routes as well.
  • Loading branch information
nekofar committed Jun 16, 2024
1 parent e5719cb commit cd5a328
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ pub async fn handle_og_image<D>(_req: Request, ctx: RouteContext<D>) -> worker::
let image = match (community, platform) {
(Some(LilNouns), Some(Ethereum)) => {
let (title, description) = fetch_lil_nouns_data(&ctx.env, numbers[2]).await?;
create_og_image(&title.to_uppercase(), &description, Ethereum)
create_og_image(numbers[2], &title.to_uppercase(), &description, Ethereum)
}
(Some(LilNouns), Some(PropLot)) => {
let (title, description) = fetch_prop_lot_data(&ctx.env, numbers[2]).await?;
create_og_image(&title.to_uppercase(), &description, PropLot)
create_og_image(numbers[2], &title.to_uppercase(), &description, PropLot)
}
(Some(LilNouns), Some(MetaGov)) => {
let (title, description) = fetch_meta_gov_data(&ctx.env, numbers[2]).await?;
create_og_image(&title.to_uppercase(), &description, MetaGov)
create_og_image(numbers[2], &title.to_uppercase(), &description, MetaGov)
}
_ => String::new(),
};
Expand Down
13 changes: 11 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn truncate_and_clean_string(input: &str, limit: usize) -> String {
}
}

pub fn create_og_image(title: &str, description: &str, platform: Platform) -> String {
pub fn create_og_image(id: u64, title: &str, description: &str, platform: Platform) -> String {
let non_alpha_numeric = Regex::new("[^a-zA-Z0-9 .:]").unwrap();

let title = non_alpha_numeric.replace_all(title, "");
Expand Down Expand Up @@ -101,16 +101,25 @@ pub fn create_og_image(title: &str, description: &str, platform: Platform) -> St
&foreground_color
);

let reference_number_formatted = format!(
"/l_text:Prop%20{}_56:{},{},c_fit,w_1050",
utf8_percent_encode("RethinkSans-ExtraBold.ttf", NON_ALPHANUMERIC),
id,
&foreground_color
);

let parts = vec![
&cloudinary_url,
&background_color,
"/c_scale,h_630,w_1200",
&logo_image,
"/c_scale,w_250/e_screen,fl_layer_apply,g_north_west,x_70,y_70",
"/c_scale,w_210/e_screen,fl_layer_apply,g_north_west,x_70,y_70",
&title_encoded,
"/fl_layer_apply,g_north_west,x_70,y_220",
&description_encoded,
"/fl_layer_apply,g_north_west,x_70,y_385",
&reference_number_formatted,
"/fl_layer_apply,g_north_east,x_70,y_70",
"/f_auto,q_auto:eco",
"/blank.png",
];
Expand Down

0 comments on commit cd5a328

Please sign in to comment.