@@ -76,8 +76,7 @@ pub async fn serve_html(state: AppState, request: Request, next: Next) -> Respon
76
76
// `state.config.og_image_base_url` will always be `Some` as that's required
77
77
// if `state.config.serve_html` is `true`, and otherwise this
78
78
// middleware won't be executed; see `crate::middleware::apply_axum_middleware`.
79
- let og_image_base_url = state. config . og_image_base_url . as_ref ( ) . unwrap ( ) ;
80
- let og_image_url = generate_og_image_url ( path, og_image_base_url) ;
79
+ let og_image_url = generate_og_image_url ( path, & state. config . og_image_base_url ) ;
81
80
82
81
// Fetch the HTML from cache given `og_image_url` as key or render it
83
82
let html = RENDERED_HTML_CACHE
@@ -125,7 +124,11 @@ fn extract_crate_name(path: &str) -> Option<&str> {
125
124
/// Come up with an Open Graph image URL. In case a crate page is requested,
126
125
/// we use the crate's name as extracted from the request path and the OG image
127
126
/// base URL from config to generate one, otherwise we use the fallback image.
128
- fn generate_og_image_url ( path : & str , og_image_base_url : & Url ) -> Cow < ' static , str > {
127
+ fn generate_og_image_url ( path : & str , og_image_base_url : & Option < Url > ) -> Cow < ' static , str > {
128
+ let Some ( og_image_base_url) = og_image_base_url else {
129
+ return OG_IMAGE_FALLBACK_URL . into ( ) ;
130
+ } ;
131
+
129
132
if let Some ( krate) = extract_crate_name ( path) {
130
133
if let Ok ( og_img_url) = og_image_base_url
131
134
. join ( krate)
@@ -182,6 +185,7 @@ mod tests {
182
185
] ;
183
186
184
187
let og_image_base_url: Url = "http://localhost:3000/og/" . parse ( ) . unwrap ( ) ;
188
+ let og_image_base_url = Some ( og_image_base_url) ;
185
189
186
190
for ( path, expected) in PATHS . iter ( ) . copied ( ) {
187
191
assert_that ! (
0 commit comments