mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 02:16:30 +00:00
Add support for projects hosted on sourcehut (sr.ht) (#117)
This commit is contained in:
parent
5b3fa9b0b2
commit
c99b0df891
2 changed files with 20 additions and 8 deletions
|
@ -54,6 +54,7 @@ pub enum RepoSite {
|
|||
Github,
|
||||
Gitlab,
|
||||
Bitbucket,
|
||||
Sourcehut,
|
||||
}
|
||||
|
||||
impl RepoSite {
|
||||
|
@ -62,6 +63,7 @@ impl RepoSite {
|
|||
RepoSite::Github => "https://github.com",
|
||||
RepoSite::Gitlab => "https://gitlab.com",
|
||||
RepoSite::Bitbucket => "https://bitbucket.org",
|
||||
RepoSite::Sourcehut => "https://git.sr.ht",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +72,7 @@ impl RepoSite {
|
|||
RepoSite::Github => "https://raw.githubusercontent.com",
|
||||
RepoSite::Gitlab => "https://gitlab.com",
|
||||
RepoSite::Bitbucket => "https://bitbucket.org",
|
||||
RepoSite::Sourcehut => "https://git.sr.ht",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,6 +80,7 @@ impl RepoSite {
|
|||
match self {
|
||||
RepoSite::Github => "HEAD",
|
||||
RepoSite::Gitlab | RepoSite::Bitbucket => "raw/HEAD",
|
||||
RepoSite::Sourcehut => "blob/HEAD",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +93,7 @@ impl FromStr for RepoSite {
|
|||
"github" => Ok(RepoSite::Github),
|
||||
"gitlab" => Ok(RepoSite::Gitlab),
|
||||
"bitbucket" => Ok(RepoSite::Bitbucket),
|
||||
"sourcehut" => Ok(RepoSite::Sourcehut),
|
||||
_ => Err(anyhow!("unknown repo site identifier")),
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +105,7 @@ impl AsRef<str> for RepoSite {
|
|||
RepoSite::Github => "github",
|
||||
RepoSite::Gitlab => "gitlab",
|
||||
RepoSite::Bitbucket => "bitbucket",
|
||||
RepoSite::Sourcehut => "sourcehut",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,9 +117,12 @@ impl FromStr for RepoQualifier {
|
|||
type Err = Error;
|
||||
|
||||
fn from_str(input: &str) -> Result<RepoQualifier, Error> {
|
||||
let is_valid = input
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '.' || c == '-' || c == '_');
|
||||
let is_valid = input.chars().all(|c| {
|
||||
c.is_ascii_alphanumeric() || c == '.' || c == '-' || c == '_'
|
||||
// Sourcehut projects have the form
|
||||
// https://git.sr.ht/~user/project.
|
||||
|| c == '~'
|
||||
});
|
||||
|
||||
ensure!(is_valid, "invalid repo qualifier");
|
||||
Ok(RepoQualifier(input.to_string()))
|
||||
|
|
|
@ -106,11 +106,14 @@ fn dependency_table(title: &str, deps: &IndexMap<CrateName, AnalyzedDependency>)
|
|||
}
|
||||
}
|
||||
|
||||
fn get_site_icon(site: &RepoSite) -> &'static str {
|
||||
fn get_site_icon(site: &RepoSite) -> (FaType, &'static str) {
|
||||
match *site {
|
||||
RepoSite::Github => "github",
|
||||
RepoSite::Gitlab => "gitlab",
|
||||
RepoSite::Bitbucket => "bitbucket",
|
||||
RepoSite::Github => (FaType::Brands, "github"),
|
||||
RepoSite::Gitlab => (FaType::Brands, "gitlab"),
|
||||
RepoSite::Bitbucket => (FaType::Brands, "bitbucket"),
|
||||
// FIXME: There is no brands/sourcehut icon, so just use a regular
|
||||
// circle which looks pretty much like sr.ht's circle.
|
||||
RepoSite::Sourcehut => (FaType::Regular, "circle"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +121,7 @@ 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());
|
||||
let fa_site_icon = PreEscaped(fa(site_icon.0, site_icon.1).unwrap());
|
||||
|
||||
html! {
|
||||
a href=(format!("{}/{}/{}", repo_path.site.to_base_uri(), repo_path.qual.as_ref(), repo_path.name.as_ref())) {
|
||||
|
|
Loading…
Reference in a new issue