-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #677 from clemensv/embeddings-pr
Optional embeddings in blog posts for bare links
- Loading branch information
Showing
24 changed files
with
5,048 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
source/DasBlog.Services/ConfigFile/Interfaces/IOEmbedProviders.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace DasBlog.Services.ConfigFile.Interfaces | ||
{ | ||
public interface IOEmbedProviders | ||
{ | ||
public List<OEmbedProvider> Providers { get; set; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Collections.Generic; | ||
using DasBlog.Services.ConfigFile.Interfaces; | ||
using System.Text.Json.Serialization; | ||
using System.Reflection; | ||
using System; | ||
|
||
namespace DasBlog.Services.ConfigFile | ||
{ | ||
|
||
public class OEmbedProviders : IOEmbedProviders | ||
{ | ||
public OEmbedProviders() { } | ||
|
||
[JsonPropertyName("providers")] | ||
public List<OEmbedProvider> Providers { get; set; } | ||
|
||
} | ||
|
||
public class OEmbedEndpoint | ||
{ | ||
[JsonPropertyName("schemes")] | ||
public List<string> Schemes { get; set; } | ||
|
||
[JsonPropertyName("url")] | ||
public string Url { get; set; } | ||
|
||
[JsonPropertyName("discovery")] | ||
public bool? Discovery { get; set; } | ||
|
||
[JsonPropertyName("formats")] | ||
public List<string> Formats { get; set; } | ||
} | ||
|
||
public class OEmbedProvider : IComparer<OEmbedProvider>, IComparable<OEmbedProvider> | ||
{ | ||
[JsonPropertyName("provider_name")] | ||
public string Provider_Name { get; set; } | ||
|
||
[JsonPropertyName("provider_url")] | ||
public string Provider_Url { get; set; } | ||
|
||
[JsonPropertyName("endpoints")] | ||
public List<OEmbedEndpoint> Endpoints { get; set; } | ||
|
||
[JsonPropertyName("usage_count")] | ||
public long UsageCount { get; set; } | ||
|
||
public int Compare(OEmbedProvider x, OEmbedProvider y) | ||
{ | ||
return -1 * x.UsageCount.CompareTo(y.UsageCount); | ||
} | ||
|
||
public int CompareTo(OEmbedProvider other) | ||
{ | ||
return -1 * UsageCount.CompareTo(other.UsageCount); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
source/DasBlog.Services/FileManagement/OEmbedProvidersFileService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.IO; | ||
using DasBlog.Services.ConfigFile; | ||
using DasBlog.Services.FileManagement.Interfaces; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
|
||
namespace DasBlog.Services.FileManagement | ||
{ | ||
public class OEmbedProvidersFileService : IConfigFileService<OEmbedProviders> | ||
{ | ||
private readonly ConfigFilePathsDataOption options; | ||
|
||
public OEmbedProvidersFileService(IOptions<ConfigFilePathsDataOption> optionsAccessor) | ||
{ | ||
options = optionsAccessor.Value; | ||
} | ||
|
||
public bool SaveConfig(OEmbedProviders config) | ||
{ | ||
var ser = new JsonSerializer(); | ||
using (var writer = new StreamWriter(options.OEmbedProvidersFilePath)) | ||
{ | ||
try | ||
{ | ||
ser.Serialize(writer, config); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
// TODO log | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.