Use font-awesome-as-a-crate instead of importing the entire Font Awesome library (#101)

This commit is contained in:
Paolo Barbolini 2021-02-10 16:45:14 +01:00 committed by GitHub
parent b0243d5dac
commit c5443aaa92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 7 deletions

7
Cargo.lock generated
View file

@ -314,6 +314,12 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 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]] [[package]]
name = "foreign-types" name = "foreign-types"
version = "0.3.2" version = "0.3.2"
@ -1461,6 +1467,7 @@ dependencies = [
"cadence", "cadence",
"crates-index 0.15.0", "crates-index 0.15.0",
"derive_more", "derive_more",
"font-awesome-as-a-crate",
"futures", "futures",
"hyper", "hyper",
"indexmap", "indexmap",

View file

@ -37,6 +37,7 @@ slog-async = "2"
slog-term = "2" slog-term = "2"
tokio = { version = "1.0.1", features = ["full"] } tokio = { version = "1.0.1", features = ["full"] }
toml = "0.5" toml = "0.5"
font-awesome-as-a-crate = "0.1.2"
[build-dependencies] [build-dependencies]
sass-rs = "0.2" sass-rs = "0.2"

7
assets/styles/fa.sass Normal file
View file

@ -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

View file

@ -1,5 +1,7 @@
@charset "utf-8"; @charset "utf-8";
@import "./fa.sass";
@import "bulma/utilities/initial-variables"; @import "bulma/utilities/initial-variables";
@import "bulma/utilities/functions"; @import "bulma/utilities/functions";

View file

@ -22,7 +22,6 @@ fn render_html<B: Render>(title: &str, body: B) -> Response<Body> {
link rel="stylesheet" type="text/css" href=(STATIC_STYLE_CSS_PATH); 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=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://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) } body { (body) }
} }

View file

@ -1,3 +1,4 @@
use font_awesome_as_a_crate::{svg as fa, Type as FaType};
use hyper::{Body, Response}; use hyper::{Body, Response};
use indexmap::IndexMap; use indexmap::IndexMap;
use maud::{html, Markup, PreEscaped}; use maud::{html, Markup, PreEscaped};
@ -49,6 +50,8 @@ fn dependency_table(title: &str, deps: &IndexMap<CrateName, AnalyzedDependency>)
let count_insecure = deps.iter().filter(|&(_, dep)| dep.is_insecure()).count(); let count_insecure = deps.iter().filter(|&(_, dep)| dep.is_insecure()).count();
let count_outdated = deps.iter().filter(|&(_, dep)| dep.is_outdated()).count(); let count_outdated = deps.iter().filter(|&(_, dep)| dep.is_outdated()).count();
let fa_cube = PreEscaped(fa(FaType::Solid, "cube").unwrap());
html! { html! {
h3 class="title is-4" { (title) } h3 class="title is-4" { (title) }
p class="subtitle is-5" { p class="subtitle is-5" {
@ -74,7 +77,7 @@ fn dependency_table(title: &str, deps: &IndexMap<CrateName, AnalyzedDependency>)
tr { tr {
td { td {
a class="has-text-grey" href=(get_crates_url(&name)) { a class="has-text-grey" href=(get_crates_url(&name)) {
i class=("fa fa-cube") { "" } { (fa_cube) }
} }
{ "\u{00A0}" } // non-breaking space { "\u{00A0}" } // non-breaking space
a href=(dep.deps_rs_path(name.as_ref())) { (name.as_ref()) } a href=(dep.deps_rs_path(name.as_ref())) { (name.as_ref()) }
@ -105,9 +108,9 @@ fn dependency_table(title: &str, deps: &IndexMap<CrateName, AnalyzedDependency>)
fn get_site_icon(site: &RepoSite) -> &'static str { fn get_site_icon(site: &RepoSite) -> &'static str {
match *site { match *site {
RepoSite::Github => "fa-github", RepoSite::Github => "github",
RepoSite::Gitlab => "fa-gitlab", RepoSite::Gitlab => "gitlab",
RepoSite::Bitbucket => "fa-bitbucket", RepoSite::Bitbucket => "bitbucket",
} }
} }
@ -115,17 +118,21 @@ fn render_title(subject_path: &SubjectPath) -> Markup {
match *subject_path { match *subject_path {
SubjectPath::Repo(ref repo_path) => { SubjectPath::Repo(ref repo_path) => {
let site_icon = get_site_icon(&repo_path.site); let site_icon = get_site_icon(&repo_path.site);
let fa_site_icon = PreEscaped(fa(FaType::Brands, site_icon).unwrap());
html! { html! {
a href=(format!("{}/{}/{}", repo_path.site.to_base_uri(), repo_path.qual.as_ref(), repo_path.name.as_ref())) { 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())) (format!(" {} / {}", repo_path.qual.as_ref(), repo_path.name.as_ref()))
} }
} }
} }
SubjectPath::Crate(ref crate_path) => { SubjectPath::Crate(ref crate_path) => {
let fa_cube = PreEscaped(fa(FaType::Solid, "cube").unwrap());
html! { html! {
a href=(get_crates_version_url(&crate_path.name, &crate_path.version)) { 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)) (format!(" {} {}", crate_path.name.as_ref(), crate_path.version))
} }
} }