2024-06-21 22:59:30 +08:00
|
|
|
|
using Markdig;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using YamlDotNet.Serialization;
|
|
|
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
|
|
|
|
|
|
|
|
namespace YaeBlog.Core.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class ServiceCollectionExtensions
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddMarkdig(this IServiceCollection collection)
|
|
|
|
|
{
|
|
|
|
|
MarkdownPipelineBuilder builder = new();
|
|
|
|
|
|
2024-07-15 17:14:48 +08:00
|
|
|
|
builder.UseAdvancedExtensions();
|
|
|
|
|
|
2024-06-21 22:59:30 +08:00
|
|
|
|
collection.AddSingleton<MarkdownPipeline>(_ => builder.Build());
|
|
|
|
|
|
|
|
|
|
return collection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IServiceCollection AddYamlParser(this IServiceCollection collection)
|
|
|
|
|
{
|
2024-08-23 20:24:32 +08:00
|
|
|
|
DeserializerBuilder deserializerBuilder = new();
|
|
|
|
|
deserializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
|
|
|
|
deserializerBuilder.IgnoreUnmatchedProperties();
|
|
|
|
|
collection.AddSingleton(deserializerBuilder.Build());
|
|
|
|
|
|
|
|
|
|
SerializerBuilder serializerBuilder = new();
|
|
|
|
|
serializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
|
|
|
|
collection.AddSingleton(serializerBuilder.Build());
|
2024-06-21 22:59:30 +08:00
|
|
|
|
|
|
|
|
|
return collection;
|
|
|
|
|
}
|
|
|
|
|
}
|