Get the latest commit and show it on the home page

This commit is contained in:
Robert Marshall 2020-04-05 07:42:22 +01:00
parent ffb3e791ab
commit 5d67e92245
23 changed files with 233 additions and 60 deletions

View file

@ -1,6 +1,7 @@
using System;
using Markdig;
using Pek.Markdig.HighlightJs;
using Website.Extensions;
using Website.Models;
namespace Website.ViewModels
@ -15,27 +16,7 @@ namespace Website.ViewModels
Content = preview ? blogPost.Draft : blogPost.Content;
}
private static string GetDaySuffix(int day) {
switch (day) {
case 1:
case 21:
case 31:
return @"\s\t";
case 2:
case 22:
return @"\n\d";
case 3:
case 23:
return @"\r\d";
default:
return @"\t\h";
}
}
private static string FormatTimestamp(DateTime timestamp) {
var suffix = GetDaySuffix(timestamp.Day);
return timestamp.ToString($@"dddd \t\h\e d{suffix} \o\f MMMM yyyy");
}
private static string FormatTimestamp(DateTime timestamp) => timestamp.ToString($@"dddd \t\h\e d{timestamp.GetDaySuffix()} \o\f MMMM yyyy");
private static MarkdownPipeline GetPipeline() => new MarkdownPipelineBuilder()
//.UseAdvancedExtensions()

View file

@ -0,0 +1,27 @@
using System;
using Website.Extensions;
using Website.Models.Git;
namespace Website.ViewModels {
public class GitCommitViewModel {
public GitCommitViewModel(Repository repo, Branch branch, Commit commit) {
RepositoryName = repo.Name;
RepositoryUrl = repo.Url;
BranchName = branch.Name;
Hash = commit.Id;
CommitUrl = commit.Url;
CommitMessage = commit.Message;
Timestamp = FormatTimestamp(commit.Timestamp);
}
private static string FormatTimestamp(DateTimeOffset timestamp) => timestamp.ToString($@"HH:mm:ss on dddd \t\h\e d{timestamp.GetDaySuffix()} \o\f MMMM yyyy");
public string RepositoryName { get; }
public string RepositoryUrl { get; }
public string BranchName { get; }
public string Hash { get; }
public string CommitUrl { get; }
public string CommitMessage { get; }
public string Timestamp { get; }
}
}

View file

@ -0,0 +1,6 @@
namespace Website.ViewModels {
public class HomeViewModel {
public BlogPostViewModel BlogPost { get; set; }
public GitCommitViewModel GitCommit { get; internal set; }
}
}