Skip to content

Commit ddb8c8d

Browse files
authored
Merge pull request #677 from clemensv/embeddings-pr
Optional embeddings in blog posts for bare links
2 parents 1613443 + a5c5d65 commit ddb8c8d

24 files changed

+5048
-19
lines changed

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ source/DasBlog.Web.UI/content
215215
# dasblog-core test infrasructure
216216
test_results/
217217
test_results.xml
218-
/source/DasBlog.Tests/FunctionalTests/Properties/launchSettings.json
219-
/source/DasBlog.Web.UI/Properties/ServiceDependencies/dasblog-linux - Zip Deploy/profile.arm.json
220-
/source/DasBlog.Web.UI/Properties/ServiceDependencies/dasblog-linux - Zip Deploy
221-
/source/DasBlog.Web.UI/Properties/ServiceDependencies
218+
source/DasBlog.Tests/FunctionalTests/Properties/launchSettings.json
219+
source/DasBlog.Web.UI/Properties/ServiceDependencies/*
220+
source/DasBlog.Web.UI/.config
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace DasBlog.Services.ConfigFile.Interfaces
4+
{
5+
public interface IOEmbedProviders
6+
{
7+
public List<OEmbedProvider> Providers { get; set; }
8+
}
9+
10+
}

source/DasBlog.Services/ConfigFile/Interfaces/ISiteConfig.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,5 +364,8 @@ public interface ISiteConfig
364364

365365
[XmlAnyAttribute]
366366
XmlAttribute[] anyAttributes { get; set; }
367-
}
367+
bool EnableRewritingHashtagsToCategoryLinks { get; set; }
368+
bool EnableRewritingBareLinksToEmbeddings { get; set; }
369+
bool EnableRewritingBareLinksToIcons { get; set; }
370+
}
368371
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Collections.Generic;
2+
using DasBlog.Services.ConfigFile.Interfaces;
3+
using System.Text.Json.Serialization;
4+
using System.Reflection;
5+
using System;
6+
7+
namespace DasBlog.Services.ConfigFile
8+
{
9+
10+
public class OEmbedProviders : IOEmbedProviders
11+
{
12+
public OEmbedProviders() { }
13+
14+
[JsonPropertyName("providers")]
15+
public List<OEmbedProvider> Providers { get; set; }
16+
17+
}
18+
19+
public class OEmbedEndpoint
20+
{
21+
[JsonPropertyName("schemes")]
22+
public List<string> Schemes { get; set; }
23+
24+
[JsonPropertyName("url")]
25+
public string Url { get; set; }
26+
27+
[JsonPropertyName("discovery")]
28+
public bool? Discovery { get; set; }
29+
30+
[JsonPropertyName("formats")]
31+
public List<string> Formats { get; set; }
32+
}
33+
34+
public class OEmbedProvider : IComparer<OEmbedProvider>, IComparable<OEmbedProvider>
35+
{
36+
[JsonPropertyName("provider_name")]
37+
public string Provider_Name { get; set; }
38+
39+
[JsonPropertyName("provider_url")]
40+
public string Provider_Url { get; set; }
41+
42+
[JsonPropertyName("endpoints")]
43+
public List<OEmbedEndpoint> Endpoints { get; set; }
44+
45+
[JsonPropertyName("usage_count")]
46+
public long UsageCount { get; set; }
47+
48+
public int Compare(OEmbedProvider x, OEmbedProvider y)
49+
{
50+
return -1 * x.UsageCount.CompareTo(y.UsageCount);
51+
}
52+
53+
public int CompareTo(OEmbedProvider other)
54+
{
55+
return -1 * UsageCount.CompareTo(other.UsageCount);
56+
}
57+
}
58+
}

source/DasBlog.Services/ConfigFile/SiteConfig.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ public string Root {
110110
public bool EnableTrackbackService { get; set; }
111111
public bool EnablePingbackService { get; set; }
112112
public bool EnableStartPageCaching { get; set; }
113-
public bool EnableBlogrollDescription { get; set; }
113+
public bool EnableRewritingHashtagsToCategoryLinks { get; set; }
114+
public bool EnableRewritingBareLinksToEmbeddings { get; set; }
115+
public bool EnableRewritingBareLinksToIcons { get; set; }
116+
117+
public bool EnableBlogrollDescription { get; set; }
114118
public bool EnableUrlRewriting { get; set; }
115119
public bool EnableCrossposts { get; set; }
116120
public bool UseUserCulture { get; set; }

source/DasBlog.Services/DasBlog.Services.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
</ItemGroup>
1414
<ItemGroup>
1515
<PackageReference Include="Coravel" Version="4.1.2" />
16+
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
1617
<PackageReference Include="Kveer.XmlRPC" Version="1.2.0" />
1718
<PackageReference Include="MailKit" Version="2.15.0" />
1819
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
20+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
1921
<PackageReference Include="Quartz.AspNetCore" Version="3.3.3" />
2022
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
2123
</ItemGroup>

source/DasBlog.Services/FileManagement/ConfigFilePathsDataOption.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ public class ConfigFilePathsDataOption
1919
public string BinaryFolder { get; set; }
2020

2121
public string BinaryUrlRelative { get; set; }
22+
public string OEmbedProvidersFilePath { get; set; }
2223
}
2324
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.IO;
3+
using DasBlog.Services.ConfigFile;
4+
using DasBlog.Services.FileManagement.Interfaces;
5+
using Microsoft.Extensions.Options;
6+
using Newtonsoft.Json;
7+
8+
namespace DasBlog.Services.FileManagement
9+
{
10+
public class OEmbedProvidersFileService : IConfigFileService<OEmbedProviders>
11+
{
12+
private readonly ConfigFilePathsDataOption options;
13+
14+
public OEmbedProvidersFileService(IOptions<ConfigFilePathsDataOption> optionsAccessor)
15+
{
16+
options = optionsAccessor.Value;
17+
}
18+
19+
public bool SaveConfig(OEmbedProviders config)
20+
{
21+
var ser = new JsonSerializer();
22+
using (var writer = new StreamWriter(options.OEmbedProvidersFilePath))
23+
{
24+
try
25+
{
26+
ser.Serialize(writer, config);
27+
return true;
28+
}
29+
catch (Exception e)
30+
{
31+
// TODO log
32+
Console.WriteLine(e);
33+
throw;
34+
}
35+
}
36+
}
37+
}
38+
}

source/DasBlog.Services/IDasBlogSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public interface IDasBlogSettings
1414
IMetaTags MetaTags { get; set; }
1515
ISiteSecurityConfig SecurityConfiguration { get; }
1616

17+
IOEmbedProviders OEmbedProviders { get; set; }
18+
1719
string WebRootDirectory { get; }
1820

1921
string RssUrl { get; }

0 commit comments

Comments
 (0)