mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-05 13:37:35 +08:00
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json.Serialization;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace AntDesign.Docs.Shared
|
|
{
|
|
public partial class GithubButton
|
|
{
|
|
private string _org = "ant-design-blazor";
|
|
private string _repo = "ant-design-blazor";
|
|
private static int _starCount = 0;
|
|
|
|
[Parameter]
|
|
public string Responsive { get; set; }
|
|
|
|
[Inject] public HttpClient HttpClient { get; set; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
try
|
|
{
|
|
if (_starCount > 0)
|
|
return;
|
|
|
|
var res = await HttpClient.GetFromJsonAsync<GithubResponse>($"https://api.github.com/repos/{this._org}/{this._repo}");
|
|
_starCount = res.StargazersCount;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
private class GithubResponse
|
|
{
|
|
[JsonPropertyName("stargazers_count")]
|
|
public int StargazersCount { get; set; }
|
|
}
|
|
}
|
|
}
|