use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct AnalyticsPaths {
pub script_path: String,
pub event_path: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct SentryBrowser {
pub script_path: String,
pub tunnel_path: String,
pub environment: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize)]
pub struct SocialImageMetadata {
pub width: Option<u32>,
pub height: Option<u32>,
pub mime_type: Option<&'static str>,
}
pub const MINIMUM_SOCIAL_IMAGE_WIDTH: u32 = 600;
pub const MINIMUM_SOCIAL_IMAGE_HEIGHT: u32 = 314;
impl SocialImageMetadata {
#[must_use]
pub const fn is_large_enough(&self) -> bool {
match (self.width, self.height) {
(Some(width), Some(height)) => {
width >= MINIMUM_SOCIAL_IMAGE_WIDTH && height >= MINIMUM_SOCIAL_IMAGE_HEIGHT
}
_ => true,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct FeedLinks {
pub title: String,
pub rss: String,
pub atom: String,
pub json: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct FrontendRuntime {
pub theme_script: String,
pub social_image: SocialImageMetadata,
pub has_svg_icon: bool,
pub analytics: AnalyticsPaths,
pub sentry_browser: SentryBrowser,
pub feed: Option<FeedLinks>,
}
#[cfg(test)]
mod tests {
use super::{MINIMUM_SOCIAL_IMAGE_HEIGHT, MINIMUM_SOCIAL_IMAGE_WIDTH, SocialImageMetadata};
#[test]
fn an_image_at_the_floor_is_large_enough() {
let image: SocialImageMetadata = SocialImageMetadata {
width: Some(MINIMUM_SOCIAL_IMAGE_WIDTH),
height: Some(MINIMUM_SOCIAL_IMAGE_HEIGHT),
mime_type: Some("image/webp"),
};
let expected: bool = true;
let actual: bool = image.is_large_enough();
assert_eq!(expected, actual);
}
#[test]
fn an_image_below_the_floor_would_degrade_to_a_thumbnail() {
let image: SocialImageMetadata = SocialImageMetadata {
width: Some(400),
height: Some(210),
mime_type: Some("image/webp"),
};
let expected: bool = false;
let actual: bool = image.is_large_enough();
assert_eq!(expected, actual);
}
#[test]
fn unknown_dimensions_are_not_treated_as_a_failure() {
let expected: bool = true;
let actual: bool = SocialImageMetadata::default().is_large_enough();
assert_eq!(expected, actual);
}
}