Merge branch 'master' into feature/ructe-static
This commit is contained in:
commit
b001db6558
18
src/lib.rs
18
src/lib.rs
@ -24,7 +24,7 @@ use crate::{
|
|||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
service::{Bitbucket, FormService, GitHub, Gitlab, Service, Sourcehut},
|
service::{Bitbucket, FormService, GitHub, Gitlab, Service, Sourcehut},
|
||||||
statics::{CLIENT, VERSION_INFO},
|
statics::{CLIENT, VERSION_INFO},
|
||||||
template::RepoInfo,
|
template::{RepoGeneratorInfo, RepoInfo},
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
dev::Server,
|
dev::Server,
|
||||||
@ -56,6 +56,7 @@ struct GeneratorForm<'a> {
|
|||||||
service: FormService,
|
service: FormService,
|
||||||
user: Cow<'a, str>,
|
user: Cow<'a, str>,
|
||||||
repo: Cow<'a, str>,
|
repo: Cow<'a, str>,
|
||||||
|
branch: Option<Cow<'a, str>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -438,16 +439,23 @@ async fn generate(
|
|||||||
state: web::Data<State>,
|
state: web::Data<State>,
|
||||||
repo_count: web::Data<AtomicUsize>,
|
repo_count: web::Data<AtomicUsize>,
|
||||||
) -> Result<HttpResponse> {
|
) -> Result<HttpResponse> {
|
||||||
let repo = format!("{}/{}", params.user, params.repo);
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
let repo_info = RepoGeneratorInfo {
|
||||||
|
service: params.service,
|
||||||
|
user: ¶ms.user,
|
||||||
|
repo: ¶ms.repo,
|
||||||
|
branch: params
|
||||||
|
.branch
|
||||||
|
.as_deref()
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.unwrap_or("master"),
|
||||||
|
};
|
||||||
templates::generate(
|
templates::generate(
|
||||||
&mut buf,
|
&mut buf,
|
||||||
VERSION_INFO,
|
VERSION_INFO,
|
||||||
repo_count.load(Ordering::Relaxed),
|
repo_count.load(Ordering::Relaxed),
|
||||||
&state.settings.base_url,
|
&state.settings.base_url,
|
||||||
params.service.url(),
|
&repo_info,
|
||||||
params.service.service(),
|
|
||||||
&repo,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
Ok(HttpResponse::Ok().content_type("text/html").body(buf))
|
||||||
|
@ -28,8 +28,8 @@ pub(crate) trait Service: Sized + 'static {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize, Clone, Copy)]
|
||||||
pub(crate) enum FormService {
|
pub enum FormService {
|
||||||
#[serde(rename = "github")]
|
#[serde(rename = "github")]
|
||||||
GitHub,
|
GitHub,
|
||||||
#[serde(rename = "gitlab")]
|
#[serde(rename = "gitlab")]
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use crate::service::FormService;
|
||||||
|
|
||||||
pub struct RepoInfo<'a> {
|
pub struct RepoInfo<'a> {
|
||||||
pub commit_url: &'a str,
|
pub commit_url: &'a str,
|
||||||
pub commits: u64,
|
pub commits: u64,
|
||||||
@ -9,3 +11,10 @@ pub struct RepoInfo<'a> {
|
|||||||
pub url: &'a str,
|
pub url: &'a str,
|
||||||
pub branch: &'a str,
|
pub branch: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RepoGeneratorInfo<'a> {
|
||||||
|
pub service: FormService,
|
||||||
|
pub user: &'a str,
|
||||||
|
pub repo: &'a str,
|
||||||
|
pub branch: &'a str,
|
||||||
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
@use super::base;
|
@use super::base;
|
||||||
@use crate::statics::VersionInfo;
|
@use crate::{statics::VersionInfo, template::RepoGeneratorInfo};
|
||||||
|
|
||||||
@(version_info: VersionInfo, repo_count: usize, base_url: &str, url: &str, service: &str, path: &str)
|
@(version_info: VersionInfo, repo_count: usize, base_url: &str, repo_info: &RepoGeneratorInfo)
|
||||||
|
|
||||||
@:base("Hits-of-Code Badges", "Badge Generator", {
|
@:base("Hits-of-Code Badges", "Badge Generator", {
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Here is the markdown for the badge for <a href="https://@url/@path">@url/@path</a>
|
Here is the markdown for the badge for <a href="https://@repo_info.service.url()/@repo_info.user/@repo_info.repo">@repo_info.user/@repo_info.repo</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
[![Hits-of-Code](@base_url/@service/@path)](@base_url/@service/@path/view)
|
[![Hits-of-Code](@base_url/@repo_info.service.service()/@repo_info.user/@repo_info.repo?branch=@repo_info.branch)](@base_url/@repo_info.service.service()/@repo_info.user/@repo_info.repo/view?branch=@repo_info.branch)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -18,6 +18,6 @@ It will be rendered like this
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
<a href="@base_url/@service/@path/view"><img src="@base_url/@service/@path" alt="example badge" /></a>
|
<a href="@base_url/@repo_info.service.service()/@repo_info.user/@repo_info.repo/view?branch=@repo_info.branch"><img src="@base_url/@repo_info.service.service()/@repo_info.user/@repo_info.repo?branch=@repo_info.branch" alt="example badge" /></a>
|
||||||
</pre>
|
</pre>
|
||||||
}, version_info, repo_count)
|
}, version_info, repo_count)
|
||||||
|
@ -80,6 +80,8 @@ the lines of
|
|||||||
<input name="user" id="user" type="text" placeholder="user" />
|
<input name="user" id="user" type="text" placeholder="user" />
|
||||||
<label>/</label>
|
<label>/</label>
|
||||||
<input name="repo" id="repo" type="text" placeholder="repository" />
|
<input name="repo" id="repo" type="text" placeholder="repository" />
|
||||||
|
<label>:</label>
|
||||||
|
<input name="branch" id="branch" type="text" placeholder="branch (defaults to `master`)" />
|
||||||
<button type="submit">Generate</button>
|
<button type="submit">Generate</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user