Skip to content

Commit 7932177

Browse files
committed
do not default to master
1 parent 303812c commit 7932177

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/http/routes.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ pub(crate) async fn generate(
5252
platform: params.service,
5353
user: &params.user,
5454
repo: &params.repo,
55-
branch: params
56-
.branch
57-
.as_deref()
58-
.filter(|s| !s.is_empty())
59-
.unwrap_or("master"),
55+
branch: params.branch.as_deref().filter(|s| !s.is_empty()),
6056
}
6157
)
6258
}

src/template.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,12 @@ pub struct RepoGeneratorInfo<'a> {
1818
pub platform: Platform,
1919
pub user: &'a str,
2020
pub repo: &'a str,
21-
pub branch: &'a str,
21+
pub branch: Option<&'a str>,
22+
}
23+
24+
impl RepoGeneratorInfo<'_> {
25+
pub fn query(&self) -> String {
26+
self.branch
27+
.map_or_else(String::new, |b| format!("?branch={b}"))
28+
}
2229
}

templates/generate.rs.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
</p>
1111

1212
<pre>
13-
[![Hits-of-Code](@base_url/@repo_info.platform.url_path()/@repo_info.user/@repo_info.repo?branch=@repo_info.branch)](@base_url/@repo_info.platform.url_path()/@repo_info.user/@repo_info.repo/view?branch=@repo_info.branch)
13+
[![Hits-of-Code](@base_url/@repo_info.platform.url_path()/@repo_info.user/@repo_info.repo@repo_info.query())](@base_url/@repo_info.platform.url_path()/@repo_info.user/@repo_info.repo/view@repo_info.query())
1414
</pre>
1515

1616
<p>
1717
It will be rendered like this
1818
</p>
1919

2020
<pre>
21-
<a href="@base_url/@repo_info.platform.url_path()/@repo_info.user/@repo_info.repo/view?branch=@repo_info.branch"><img src="@base_url/@repo_info.platform.url_path()/@repo_info.user/@repo_info.repo?branch=@repo_info.branch" alt="example badge" /></a>
21+
<a href="@base_url/@repo_info.platform.url_path()/@repo_info.user/@repo_info.repo/view@repo_info.query()"><img src="@base_url/@repo_info.platform.url_path()/@repo_info.user/@repo_info.repo@repo_info.query()" alt="example badge" /></a>
2222
</pre>
2323
}, version_info, repo_count)

0 commit comments

Comments
 (0)