Frontend Update

This commit is contained in:
Connor Drahoss 2022-09-10 11:35:05 -07:00
parent c52eb760e7
commit 6df3188b02
17 changed files with 129 additions and 131 deletions

View File

@ -9,6 +9,7 @@ namespace ExtensiblePortfolioSite.SDK.Git
public static void Register(String Service, IGitProvider Provider)
{
Console.WriteLine($"Registering service {Service}");
if (Providers.TryGetValue(Service, out GitService? GitService))
{
GitService.addProvider(Provider);

View File

@ -20,5 +20,10 @@ namespace ExtensiblePortfolioSite.SDK.Git
/// List of files modified in the commit
/// </summary>
public IReadOnlyCollection<String> ModifiedFiles { get; }
/// <summary>
/// URL to the commit author's avatar
/// </summary>
public string AuthorAvatarUrl { get; }
}
}

View File

@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace ExtensiblePortfolioSite.SDK
{
internal static class Json
public static class Json
{
private static class DefaultConverters
{
@ -40,7 +40,7 @@ namespace ExtensiblePortfolioSite.SDK
IncludeFields = true,
MaxDepth = 64,
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals | JsonNumberHandling.AllowReadingFromString,
PropertyNameCaseInsensitive = false,
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
ReadCommentHandling = JsonCommentHandling.Skip,
UnknownTypeHandling = JsonUnknownTypeHandling.JsonElement,
@ -61,6 +61,7 @@ namespace ExtensiblePortfolioSite.SDK
public static T? Deserialize<T>(String String) => JsonSerializer.Deserialize<T>(String, Options);
public static T? Deserialize<T>(Stream STM) => JsonSerializer.Deserialize<T>(STM, Options);
public static T? Deserialize<T>(ref Utf8JsonReader Reader) => JsonSerializer.Deserialize<T>(ref Reader, Options);
public static T? Deserialize<T>(JsonElement Element) => JsonSerializer.Deserialize<T>(Element, Options);
public static ValueTask<T?> DeserializeAsync<T>(Stream STM) => JsonSerializer.DeserializeAsync<T>(STM, Options);
public static ValueTask<T?> DeserializeAsync<T>(Stream STM, CancellationToken cancellationToken) => JsonSerializer.DeserializeAsync<T>(STM, Options, cancellationToken);

View File

@ -31,6 +31,7 @@ namespace ExtensiblePortfolioSite.SDK.Plugins
List<Byte[]> PublicKeyTokens = new();
PublicKeyTokens.Add(typeof(String).Assembly.GetName().GetPublicKeyToken()!); // Framework Libraries
PublicKeyTokens.Add(new byte[8] { 0xb0, 0x3f, 0x5f, 0x7f, 0x11, 0xd5, 0x0a, 0x3a }); // System.Runtime
PublicKeyTokens.Add(new byte[8] { 0xcc, 0x7b, 0x13, 0xff, 0xcd, 0x2d, 0xdd, 0x51 }); // System.Text.Json
KnownPublicKeyTokens = PublicKeyTokens.ToArray();
}

View File

@ -68,6 +68,10 @@ namespace ExtensiblePortfolioSite
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public string[] Description { get; set; } = Array.Empty<String>();
[JsonPropertyName("Biography")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public string[] Biography { get; set; } = Array.Empty<String>();
[JsonPropertyName("Languages")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public LanguageObject[] Languages { get; set; } = Array.Empty<LanguageObject>();

View File

@ -27,14 +27,10 @@
<None Include="Pages\Projects\Index.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Plugins\" />
</ItemGroup>
<Target Name="IncludePlugins" BeforeTargets="AfterBuild">
<MSBuild Projects="..\GithubPlugin\GithubPlugin.csproj" BuildInParallel="$(BuildInParallel)" Targets="Build">
</MSBuild>
<Copy SourceFiles="$(SolutionDir)GithubPlugin\bin\$(Configuration)\net6.0\GithubPlugin.dll" DestinationFolder="Plugins/" />
<Copy SourceFiles="$(SolutionDir)GithubPlugin\bin\$(Configuration)\net6.0\GithubPlugin.dll" DestinationFolder="Plugins/" SkipUnchangedFiles="true" />
</Target>
</Project>

View File

@ -22,8 +22,10 @@
</div>
<div class="about-me-container" style="display: flex; flex-direction: column; flex: 1; align-items: center; min-width: 60%; min-height: 40vh;">
<h2>About Me</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce commodo imperdiet hendrerit. Vestibulum pretium mauris eu sagittis tristique. Sed tellus nulla, facilisis in molestie id, fermentum facilisis nulla. Nullam vel tristique neque. Nam accumsan arcu vel nulla efficitur, posuere convallis diam rhoncus. Mauris mollis at sapien eu gravida. Nullam viverra velit porttitor ex mattis, in iaculis justo tincidunt. Morbi pulvinar odio nec mauris luctus facilisis. Phasellus aliquam commodo turpis. Quisque in tincidunt tellus, vel facilisis massa.</p>
<p>Pellentesque auctor eros vitae pretium ornare. Donec quam erat, tempor id elit eu, aliquet suscipit mi. Morbi facilisis nisi vel dapibus facilisis. Phasellus efficitur ac odio id ultricies. Cras ullamcorper lacinia posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Vivamus lobortis, arcu a mollis venenatis, nisi libero cursus risus, ut sodales felis erat quis lorem. Praesent nisl turpis, egestas ac auctor et, tempor ac mauris. Donec aliquam lacus nisi, id hendrerit neque aliquam ut. Nullam maximus velit nulla, quis euismod lacus porttitor ac. Nullam lacinia non arcu vitae scelerisque. Nulla nisl nibh, vestibulum eget ex sit amet, viverra vulputate purus. Nullam non arcu ac diam sagittis consectetur.</p>
@foreach(String s in Config.GetConfig().ProfileSection.Biography)
{
<p>@s</p>
}
</div>
<div class="personals-container" style="min-width: 20%;">
<div style="display: flex; flex-direction: row; align-items: center; padding: 0.25em 0; ">

View File

@ -10,42 +10,27 @@
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<div class="container repo-container">
@{
//var githubService = GitManager.GetService("github.com");
//var user = githubService.GetUser(new Uri("https://github.com/KoromaruKoruko"));
//Console.WriteLine("FOUND USER");
//Console.WriteLine(user.Name);
//var repos = user.GetUserRepositories();
//Console.WriteLine("REPOSITORIES");
//foreach(var repo in repos)
// Console.WriteLine(repo.Name);
var client = new HttpClient();
client.DefaultRequestHeaders.Add("User-Agent", "KoromaruKoruko");
client.DefaultRequestHeaders.Add("Authorization", "Bearer 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");
HttpResponseMessage response = await client.GetAsync("https://api.github.com/users/KoromaruKoruko/repos");
JsonDocument json = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
foreach(JsonElement elem in json.RootElement.EnumerateArray())
foreach(Config.ConfigObject.GitRepoObject repo in Config.GetConfig().GitRepos)
{
int popout_id = Random.Shared.Next();
HttpResponseMessage commitResponse = await client.GetAsync(elem.GetProperty("commits_url").GetString()!.Split('{')[0]);
JsonDocument commitInfo = await JsonDocument.ParseAsync(await commitResponse.Content.ReadAsStreamAsync());
JsonElement commitJson = commitInfo.RootElement.EnumerateArray().First();
String[] lastCommitMessage = commitJson.GetProperty("commit").GetProperty("message")!.GetString()!.Split("\n").Where(s => s != "").ToArray();
IRepository repository = GitManager.GetService(repo.ServiceProvider).GetRepository(repo.Repository);
repository.TryGetCommit(0, out ICommit commit);
String[] lastCommitMessage = commit!.Description.Split("\n").Where(s => s != "").ToArray();
// Begin repo
<div class="repo">
<div class="repo-title">
<span class="eps-lineclamp-1">KoromaruKoruko/</span>
<span class="eps-lineclamp-1">@elem.GetProperty("name")</span>
<span class="eps-lineclamp-1">@repository.Owner.Name/</span>
<span class="eps-lineclamp-1">@repository.Name</span>
</div>
<div class="repo-description eps-lineclamp-2">
@elem.GetProperty("description")
@repo.Description.Aggregate((a, b) => a + "\n" + b)
</div>
<div class="popout">
<span class="popout-title">@elem.GetProperty("description")</span>
<span class="popout-title">@repo.Description.Aggregate((a, b) => a + "\n" + b)</span>
</div>
<div class="commit">
<img class="commit-author" src="@commitJson.GetProperty("author").GetProperty("avatar_url").GetString()"/>
<img class="commit-author" src="@commit.AuthorAvatarUrl"/>
<div class="commit-info">
<div class="commit-title eps-lineclamp-1">
@if(lastCommitMessage.Length > 0)
@ -74,10 +59,10 @@
</div>
</div>
<div class="repo-footer">
<a class="repo-link" href="@elem.GetProperty("html_url").GetString()">
<a class="repo-link" href="@repo.Repository.OriginalString">
<span>visit repo >></span>
</a>
<img class="repo-icon" src="/img/logos/github/Light-64px.png"/>
<img class="repo-icon" src="/content/img/logos/@repo.ServiceProvider/light.png"/>
</div>
</div>
// End repo

View File

@ -86,6 +86,9 @@ namespace ExtensiblePortfolioSite
// Load Plugins
PluginManager.LoadPlugins(Path.GetFullPath("Plugins/"));
//Initialize Plugins
PluginManager.InitializePlugins();
// TODO: [Resource] File Provider
// TODO: [Plugin] Web Static Files Provider
// TODO: [Plugin] Web Hook Provider

View File

@ -13,6 +13,11 @@
"I'm a c# Programmer who prides herself in making things configurable and highly optimized."
],
// Multi paragraph biography for About Me page
"Biography": [
"I'm a c# Programmer who prides herself in making things configurable and highly optimized."
],
// Languages you'd like to advertise
"Languages": [
{

View File

@ -70,7 +70,7 @@ main .text-center {
}
.repo-container {
border: solid 1px #444;
/*border: solid 1px #444;*/
border-radius: .25em;
width: 81.5em;
display: flex;

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -20,11 +20,16 @@ namespace GithubPlugin
[JsonIgnore]
public IGitProvider? Provider { get; internal set; }
[JsonPropertyName("sha")]
public string? Hash { get; private set; }
[JsonIgnore]
public string? AuthorAvatarUrl { get; internal set; }
[JsonInclude]
[JsonPropertyName("sha")]
public string? Hash { get; init; }
[JsonInclude]
[JsonPropertyName("message")]
public string? Description { get; private set; }
public string? Description { get; init; }
public GitReference GetReference()
{

View File

@ -1,4 +1,5 @@
using ExtensiblePortfolioSite.SDK.Git;
using ExtensiblePortfolioSite.SDK;
using ExtensiblePortfolioSite.SDK.Git;
using ExtensiblePortfolioSite.SDK.Plugins;
using System.Text.Json;
@ -6,7 +7,7 @@ using System.Text.RegularExpressions;
namespace GithubPlugin
{
[GitProvider("github.com")]
[GitProvider("Github")]
[Serializable]
public class GithubProvider : IGitProvider
{
@ -69,7 +70,7 @@ namespace GithubPlugin
public bool TryGetRepositoryByName(IUser User, string RepositoryName, out IRepository? Repository)
{
if(User.GetType() == typeof(GithubUser))
if(User is GithubUser _user)
{
if (Repositories.TryGetValue(RepositoryName, out GithubRepo? _repo))
{
@ -77,15 +78,15 @@ namespace GithubPlugin
return true;
} else
{
var response = httpClient.GetAsync($"repos/{User.Name}/{RepositoryName}").Result;
var response = httpClient.GetAsync($"repos/{_user.Name}/{RepositoryName}").Result;
if (!response.IsSuccessStatusCode)
{
Repository = null;
return false;
}
GithubRepo tempRepo = JsonSerializer.Deserialize<GithubRepo>(response.Content.ReadAsStream())!;
GithubRepo tempRepo = Json.Deserialize<GithubRepo>(response.Content.ReadAsStream())!;
tempRepo.Provider = this;
tempRepo.Owner = User;
tempRepo.Owner = _user;
Repository = tempRepo;
return true;
}
@ -108,7 +109,7 @@ namespace GithubPlugin
User = null;
return false;
}
GithubUser tempUser = JsonSerializer.Deserialize<GithubUser>(response.Content.ReadAsStream())!;
GithubUser tempUser = Json.Deserialize<GithubUser>(response.Content.ReadAsStringAsync().Result)!;
tempUser.Provider = this;
User = tempUser;
return true;

View File

@ -1,4 +1,5 @@
using ExtensiblePortfolioSite.SDK.Git;
using ExtensiblePortfolioSite.SDK;
using ExtensiblePortfolioSite.SDK.Git;
using System.Text.Json;
using System.Text.Json.Serialization;
@ -7,14 +8,17 @@ namespace GithubPlugin
[Serializable]
public class GithubRepo : IRepository
{
[JsonInclude]
[JsonPropertyName("name")]
public string Name { get; private set; }
public string Name { get; init; }
[JsonInclude]
[JsonPropertyName("description")]
public string Description { get; private set; }
public string Description { get; init; }
[JsonIgnore]
public IUser Owner { get; internal set; }
[JsonInclude]
[JsonPropertyName("owner")]
public GithubUser Owner { get; internal set; }
[JsonIgnore]
public GithubProvider Provider { get; internal set; }
@ -22,30 +26,17 @@ namespace GithubPlugin
[JsonIgnore]
IGitProvider IGitObject.Provider => this.Provider;
[JsonIgnore]
IUser IRepository.Owner => this.Owner;
public ICommit? GetCommit(uint HeadOffset = 0)
{
var response = Provider.GetAPIResource($"repos/{Owner.Name}/{Name}/commits");
if(response.IsSuccessStatusCode)
{
JsonDocument json = JsonDocument.Parse(response.Content.ReadAsStream());
JsonElement commitObject = json.RootElement.EnumerateArray().Skip((int)HeadOffset).First();
GithubCommit commit = JsonSerializer.Deserialize<GithubCommit>(commitObject.GetProperty("commit"))!;
commit.Provider = Provider;
commit.Repository = this;
List<string> tempFiles = new();
JsonElement files = commitObject.GetProperty("files");
foreach(JsonElement file in files.EnumerateArray())
{
tempFiles.Add(file.GetProperty("filename").GetString()!);
}
commit.ModifiedFiles = tempFiles;
return commit;
} else
{
if (response.IsSuccessStatusCode)
return GetCommitByRef(JsonDocument.Parse(response.Content.ReadAsStream()).RootElement.EnumerateArray().Skip((int)HeadOffset).First().GetProperty("sha").GetString());
else
return null;
}
}
public ICommit? GetCommitByRef(string reference)
{
@ -54,7 +45,8 @@ namespace GithubPlugin
{
JsonDocument json = JsonDocument.Parse(response.Content.ReadAsStream());
JsonElement commitObject = json.RootElement;
GithubCommit commit = JsonSerializer.Deserialize<GithubCommit>(commitObject.GetProperty("commit"))!;
GithubCommit commit = Json.Deserialize<GithubCommit>(commitObject.GetProperty("commit"))!;
commit.AuthorAvatarUrl = commitObject.GetProperty("author").GetProperty("avatar_url").GetString();
commit.Provider = Provider;
commit.Repository = this;
List<string> tempFiles = new();

View File

@ -1,25 +1,24 @@
using ExtensiblePortfolioSite.SDK.Git;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExtensiblePortfolioSite.SDK;
using ExtensiblePortfolioSite.SDK.Git;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace GithubPlugin
{
[Serializable]
public class GithubUser : IUser
{
[JsonInclude]
[JsonPropertyName("login")]
public string Name { get; private set; }
public string Name { get; init; }
[JsonInclude]
[JsonPropertyName("id")]
public int Identifier { get; private set; }
public int Identifier { get; init; }
[JsonInclude]
[JsonPropertyName("avatar_url")]
public string AvatarURL { get; private set; }
public string AvatarURL { get; init; }
[JsonIgnore]
public GithubProvider Provider { get; internal set; }
@ -37,15 +36,13 @@ namespace GithubPlugin
var response = Provider.GetAPIResource($"users/{Name}/repos");
if(response.IsSuccessStatusCode)
{
JsonDocument json = JsonDocument.Parse(response.Content.ReadAsStream());
List<IRepository> ret = new(json.RootElement.GetArrayLength());
foreach(JsonElement repo in json.RootElement.EnumerateArray())
using Stream STM = response.Content.ReadAsStream();
foreach (GithubRepo repo in Json.Deserialize<GithubRepo[]>(STM) ?? Array.Empty<GithubRepo>())
{
ret.Add(JsonSerializer.Deserialize<GithubRepo>(repo)!);
repo.Provider = this.Provider;
yield return repo;
}
return ret;
}
return new List<IRepository>();
}
}
}