feat(Docs) Added FrontMatter and Git edit links

This commit is contained in:
2022-04-11 23:31:23 -04:00
parent ddb6318186
commit 1939bbe70a
31 changed files with 254 additions and 299 deletions
+7
View File
@@ -0,0 +1,7 @@
namespace IGP.Utils;
public static class Interval {
public static string ToTime(int interval) {
return TimeSpan.FromSeconds(interval).ToString(@"mm\:ss");
}
}
+51
View File
@@ -0,0 +1,51 @@
using Markdig;
using Markdig.Extensions.Yaml;
using Markdig.Syntax;
using Model.Doc;
using YamlDotNet.Serialization;
namespace IGP.Utils;
public static class MarkdownFiles {
private static readonly IDeserializer YamlDeserializer =
new DeserializerBuilder()
.IgnoreUnmatchedProperties()
.Build();
public static readonly MarkdownPipeline Pipeline
= new MarkdownPipelineBuilder()
.UseYamlFrontMatter()
.UseAdvancedExtensions()
.Build();
public static async Task<string> LoadMarkdown(HttpClient httpClient, string filepath)
{
return await httpClient.GetStringAsync(filepath);
}
public static async Task<T> LoadFrontMatter<T>(HttpClient httpClient, string filepath) {
var markdown = await LoadMarkdown(httpClient, filepath);
var document = Markdown.Parse(markdown, Pipeline);
var block = document
.Descendants<YamlFrontMatterBlock>()
.FirstOrDefault();
if (block == null)
return default!;
var yaml =
block
.Lines
.Lines
.OrderByDescending(x => x.Line)
.Select(x => $"{x}\n")
.ToList()
.Select(x => x.Replace("---", string.Empty))
.Where(x => !string.IsNullOrWhiteSpace(x))
.Aggregate((s, agg) => agg + s);
return YamlDeserializer.Deserialize<T>(yaml);
}
}
+6
View File
@@ -0,0 +1,6 @@
namespace IGP.Utils;
public static class Project {
public static string GitResourcesUrl => "https://github.com/JonathanMcCaffrey/IGP-Fan-Reference/blob/develop/IGP/wwwroot/";
}