From c5443aaa92239a3c1900280ad3727739d9f2cf24 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Wed, 10 Feb 2021 16:45:14 +0100 Subject: [PATCH] Use font-awesome-as-a-crate instead of importing the entire Font Awesome library (#101) --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + assets/styles/fa.sass | 7 +++++++ assets/styles/main.sass | 2 ++ src/server/views/html/mod.rs | 1 - src/server/views/html/status.rs | 19 +++++++++++++------ 6 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 assets/styles/fa.sass diff --git a/Cargo.lock b/Cargo.lock index 664ef42..331287e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -314,6 +314,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "font-awesome-as-a-crate" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12cc52b2062ad4cb425d969c77325dd3da70312ed7ed892c7e8143384da58aa" + [[package]] name = "foreign-types" version = "0.3.2" @@ -1461,6 +1467,7 @@ dependencies = [ "cadence", "crates-index 0.15.0", "derive_more", + "font-awesome-as-a-crate", "futures", "hyper", "indexmap", diff --git a/Cargo.toml b/Cargo.toml index 6540bb4..c91ae79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ slog-async = "2" slog-term = "2" tokio = { version = "1.0.1", features = ["full"] } toml = "0.5" +font-awesome-as-a-crate = "0.1.2" [build-dependencies] sass-rs = "0.2" diff --git a/assets/styles/fa.sass b/assets/styles/fa.sass new file mode 100644 index 0000000..e5aa1de --- /dev/null +++ b/assets/styles/fa.sass @@ -0,0 +1,7 @@ +/* Stop icons from using up all of the available space */ +svg + width: 1em + height: 1em + fill: currentColor + /* pull icon about one stroke width into the descenders */ + margin-bottom: -0.1em diff --git a/assets/styles/main.sass b/assets/styles/main.sass index 109c10e..f63748e 100644 --- a/assets/styles/main.sass +++ b/assets/styles/main.sass @@ -1,5 +1,7 @@ @charset "utf-8"; +@import "./fa.sass"; + @import "bulma/utilities/initial-variables"; @import "bulma/utilities/functions"; diff --git a/src/server/views/html/mod.rs b/src/server/views/html/mod.rs index 05b7996..39770d1 100644 --- a/src/server/views/html/mod.rs +++ b/src/server/views/html/mod.rs @@ -22,7 +22,6 @@ fn render_html(title: &str, body: B) -> Response { link rel="stylesheet" type="text/css" href=(STATIC_STYLE_CSS_PATH); link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Fira+Sans:400,500,600"; link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Source+Code+Pro"; - link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"; } body { (body) } } diff --git a/src/server/views/html/status.rs b/src/server/views/html/status.rs index 00bef26..a6f3d97 100644 --- a/src/server/views/html/status.rs +++ b/src/server/views/html/status.rs @@ -1,3 +1,4 @@ +use font_awesome_as_a_crate::{svg as fa, Type as FaType}; use hyper::{Body, Response}; use indexmap::IndexMap; use maud::{html, Markup, PreEscaped}; @@ -49,6 +50,8 @@ fn dependency_table(title: &str, deps: &IndexMap) let count_insecure = deps.iter().filter(|&(_, dep)| dep.is_insecure()).count(); let count_outdated = deps.iter().filter(|&(_, dep)| dep.is_outdated()).count(); + let fa_cube = PreEscaped(fa(FaType::Solid, "cube").unwrap()); + html! { h3 class="title is-4" { (title) } p class="subtitle is-5" { @@ -74,7 +77,7 @@ fn dependency_table(title: &str, deps: &IndexMap) tr { td { a class="has-text-grey" href=(get_crates_url(&name)) { - i class=("fa fa-cube") { "" } + { (fa_cube) } } { "\u{00A0}" } // non-breaking space a href=(dep.deps_rs_path(name.as_ref())) { (name.as_ref()) } @@ -105,9 +108,9 @@ fn dependency_table(title: &str, deps: &IndexMap) fn get_site_icon(site: &RepoSite) -> &'static str { match *site { - RepoSite::Github => "fa-github", - RepoSite::Gitlab => "fa-gitlab", - RepoSite::Bitbucket => "fa-bitbucket", + RepoSite::Github => "github", + RepoSite::Gitlab => "gitlab", + RepoSite::Bitbucket => "bitbucket", } } @@ -115,17 +118,21 @@ fn render_title(subject_path: &SubjectPath) -> Markup { match *subject_path { SubjectPath::Repo(ref repo_path) => { let site_icon = get_site_icon(&repo_path.site); + let fa_site_icon = PreEscaped(fa(FaType::Brands, site_icon).unwrap()); + html! { a href=(format!("{}/{}/{}", repo_path.site.to_base_uri(), repo_path.qual.as_ref(), repo_path.name.as_ref())) { - i class=(format!("fa {}", site_icon)) { "" } + { (fa_site_icon) } (format!(" {} / {}", repo_path.qual.as_ref(), repo_path.name.as_ref())) } } } SubjectPath::Crate(ref crate_path) => { + let fa_cube = PreEscaped(fa(FaType::Solid, "cube").unwrap()); + html! { a href=(get_crates_version_url(&crate_path.name, &crate_path.version)) { - i class="fa fa-cube" { "" } + { (fa_cube) } (format!(" {} {}", crate_path.name.as_ref(), crate_path.version)) } }