From 139741362e2941ab3b0e598fc8439f7c63b20e06 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 13 Dec 2020 13:28:22 +0000 Subject: [PATCH] links direct to other deps.rs pages (#86) and a crates link is provided on the icon to the left --- src/models/crates.rs | 7 +++++++ src/server/views/html/status.rs | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/models/crates.rs b/src/models/crates.rs index e0c6901..c6ff022 100644 --- a/src/models/crates.rs +++ b/src/models/crates.rs @@ -105,6 +105,13 @@ impl AnalyzedDependency { pub fn is_outdated(&self) -> bool { self.latest > self.latest_that_matches } + + pub fn deps_rs_path(&self, name: &str) -> String { + match &self.latest_that_matches { + Some(version) => ["/crate/", name, "/", version.to_string().as_str()].concat(), + None => ["/crate/", name].concat(), + } + } } #[derive(Debug)] diff --git a/src/server/views/html/status.rs b/src/server/views/html/status.rs index 9f5c027..a97b741 100644 --- a/src/server/views/html/status.rs +++ b/src/server/views/html/status.rs @@ -1,6 +1,7 @@ use hyper::{Body, Response}; use indexmap::IndexMap; use maud::{html, Markup}; +use semver::Version; use crate::engine::AnalyzeDependenciesOutcome; use crate::models::crates::{AnalyzedDependencies, AnalyzedDependency, CrateName}; @@ -8,6 +9,14 @@ use crate::models::repo::RepoSite; use crate::models::SubjectPath; use crate::server::views::badge; +fn get_crates_url(name: impl AsRef) -> String { + format!("https://crates.io/crates/{}", name.as_ref()) +} + +fn get_crates_version_url(name: impl AsRef, version: &Version) -> String { + format!("https://crates.io/crates/{}/{}", name.as_ref(), version) +} + fn dependency_tables(crate_name: CrateName, deps: AnalyzedDependencies) -> Markup { html! { h2 class="title is-3" { @@ -62,7 +71,11 @@ fn dependency_table(title: &str, deps: IndexMap) @for (name, dep) in deps { tr { td { - a href=(format!("https://crates.io/crates/{}", name.as_ref())) { (name.as_ref()) } + a class="has-text-grey" href=(get_crates_url(&name)) { + i class=("fa fa-cube") { "" } + } + { "\u{00A0}" } // non-breaking space + a href=(dep.deps_rs_path(name.as_ref())) { (name.as_ref()) } } td class="has-text-right" { code { (dep.required.to_string()) } } td class="has-text-right" { @@ -109,7 +122,7 @@ fn render_title(subject_path: &SubjectPath) -> Markup { } SubjectPath::Crate(ref crate_path) => { html! { - a href=(format!("https://crates.io/crates/{}/{}", crate_path.name.as_ref(), crate_path.version)) { + a href=(get_crates_version_url(&crate_path.name, &crate_path.version)) { i class="fa fa-cube" { "" } (format!(" {} {}", crate_path.name.as_ref(), crate_path.version)) }