From 2f6587f39aa2bc801fe61493a68104afe8346b39 Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Tue, 24 Sep 2024 08:26:12 +0200 Subject: [PATCH 1/2] Revert "hotfix: don't fail on invalid font-awesome icons, just report" This reverts commit de1f9e72f930c3d118dcb65471e36cc3ab021417. --- src/web/page/templates.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/web/page/templates.rs b/src/web/page/templates.rs index 60f835a8b..90fe7df99 100644 --- a/src/web/page/templates.rs +++ b/src/web/page/templates.rs @@ -1,6 +1,6 @@ use crate::error::Result; -use crate::web::{report_error, rustdoc::RustdocPage}; -use anyhow::{anyhow, Context}; +use crate::web::rustdoc::RustdocPage; +use anyhow::Context; use rinja::Template; use std::{fmt, sync::Arc}; use tracing::trace; @@ -267,16 +267,8 @@ impl IconType { IconType::Brand => font_awesome_as_a_crate::Type::Brands, }; - let icon_file_string = match font_awesome_as_a_crate::svg(type_, icon_name) { - Ok(s) => s, - Err(err) => { - report_error(&anyhow!(err).context(format!( - "error trying to render icon with name \"{}\"", - icon_name - ))); - "" - } - }; + let icon_file_string = font_awesome_as_a_crate::svg(type_, icon_name) + .map_err(|err| rinja::Error::Custom(Box::new(err)))?; let mut classes = vec!["fa-svg"]; if fw { From d6e72139fb3e3f0998f9650265f33d110d5e9736 Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Mon, 23 Sep 2024 17:29:04 +0200 Subject: [PATCH 2/2] fix wrong code-branch icon variant in crate-details --- src/web/crate_details.rs | 38 ++++++++++++++++++++++++++++++++++++ src/web/page/templates.rs | 14 ++++++++++--- templates/crate/details.html | 2 +- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/web/crate_details.rs b/src/web/crate_details.rs index 0eaecb889..e5ce5c3ce 100644 --- a/src/web/crate_details.rs +++ b/src/web/crate_details.rs @@ -1583,6 +1583,44 @@ mod tests { }); } + #[test] + fn details_with_repository_and_stats_can_render_icon() { + wrapper(|env| { + env.fake_release() + .name("library") + .version("0.1.0") + .repo("https://github.com/org/repo") + .github_stats("org/repo", 10, 10, 10) + .create()?; + + let page = kuchikiki::parse_html().one( + env.frontend() + .get("/crate/library/0.1.0/") + .send()? + .error_for_status()? + .text()?, + ); + + let link = page + .select_first("a.pure-menu-link[href='https://github.com/org/repo']") + .unwrap(); + + let icon_node = link.as_node().children().nth(1).unwrap(); + assert_eq!( + icon_node + .as_element() + .unwrap() + .attributes + .borrow() + .get("class") + .unwrap(), + "fa-svg" + ); + + Ok(()) + }); + } + #[test] fn feature_flags_report_null() { wrapper(|env| { diff --git a/src/web/page/templates.rs b/src/web/page/templates.rs index 90fe7df99..c3bfb4193 100644 --- a/src/web/page/templates.rs +++ b/src/web/page/templates.rs @@ -1,6 +1,6 @@ use crate::error::Result; use crate::web::rustdoc::RustdocPage; -use anyhow::Context; +use anyhow::{anyhow, Context}; use rinja::Template; use std::{fmt, sync::Arc}; use tracing::trace; @@ -267,8 +267,16 @@ impl IconType { IconType::Brand => font_awesome_as_a_crate::Type::Brands, }; - let icon_file_string = font_awesome_as_a_crate::svg(type_, icon_name) - .map_err(|err| rinja::Error::Custom(Box::new(err)))?; + let icon_file_string = font_awesome_as_a_crate::svg(type_, icon_name).map_err(|err| { + rinja::Error::Custom( + anyhow!(err) + .context(format!( + "error trying to render icon with name \"{}\" and type \"{}\"", + icon_name, type_, + )) + .into(), + ) + })?; let mut classes = vec!["fa-svg"]; if fw { diff --git a/templates/crate/details.html b/templates/crate/details.html index 6d4e023db..28c568145 100644 --- a/templates/crate/details.html +++ b/templates/crate/details.html @@ -64,7 +64,7 @@ {# If the repo link is for github or gitlab, show some stats #} {# TODO: add support for hosts besides github and gitlab (#35) #} {%- if let Some(repository_metadata) = repository_metadata -%} - {{ "code-branch"|fab(false, false, "") }} + {{ "code-branch"|fas(false, false, "") }} {% if let Some(name) = repository_metadata.name %} {{name}} {% else %}