Skip to content

Commit f216218

Browse files
committed
Added Disqus feature
1 parent ba5b200 commit f216218

File tree

9 files changed

+76
-8
lines changed

9 files changed

+76
-8
lines changed

src/LinkDotNet.Blog.Web/AppConfiguration.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ public record AppConfiguration
3030
public GiscusConfiguration GiscusConfiguration { get; init; }
3131

3232
public bool IsGiscusEnabled => GiscusConfiguration != null;
33-
}
33+
34+
public DisqusConfiguration DisqusConfiguration { get; init; }
35+
36+
public bool IsDisqusEnabled => DisqusConfiguration != null;
37+
}

src/LinkDotNet.Blog.Web/AppConfigurationFactory.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LinkDotNet.Blog.Domain;
1+
using System;
2+
using LinkDotNet.Blog.Domain;
23
using LinkDotNet.Blog.Web.Shared.Services;
34
using Microsoft.Extensions.Configuration;
45

@@ -10,6 +11,7 @@ public static AppConfiguration Create(IConfiguration config)
1011
{
1112
var profileInformation = config.GetSection("AboutMeProfileInformation").Get<ProfileInformation>();
1213
var giscus = config.GetSection("Giscus").Get<GiscusConfiguration>();
14+
var disqus = config.GetSection("Disqus").Get<DisqusConfiguration>();
1315
var configuration = new AppConfiguration
1416
{
1517
BlogName = config["BlogName"],
@@ -21,8 +23,9 @@ public static AppConfiguration Create(IConfiguration config)
2123
BlogPostsPerPage = int.Parse(config["BlogPostsPerPage"]),
2224
ProfileInformation = profileInformation,
2325
GiscusConfiguration = giscus,
26+
DisqusConfiguration = disqus,
2427
};
2528

2629
return configuration;
2730
}
28-
}
31+
}

src/LinkDotNet.Blog.Web/LinkDotNet.Blog.Web.csproj

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@
4040
<InternalsVisibleTo Include="LinkDotNet.Blog.IntegrationTests" />
4141
</ItemGroup>
4242

43+
<ItemGroup>
44+
<None Update="Shared\Disqus.razor.js">
45+
<DependentUpon>Disqus.razor</DependentUpon>
46+
</None>
47+
</ItemGroup>
48+
4349
<ItemGroup>
44-
<None Update="Shared\Giscus.razor.js">
45-
<DependentUpon>Giscus.razor</DependentUpon>
46-
</None>
50+
<None Update="Shared\Giscus.razor.js">
51+
<DependentUpon>Giscus.razor</DependentUpon>
52+
</None>
4753
</ItemGroup>
54+
4855
<PropertyGroup>
4956
<CodeAnalysisRuleSet>..\..\stylecop.analyzers.ruleset</CodeAnalysisRuleSet>
5057
</PropertyGroup>

src/LinkDotNet.Blog.Web/Pages/BlogPostPage.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ else
4040
<div class="d-flex justify-content-between py-2">
4141
<Like BlogPost="@BlogPost" OnBlogPostLiked="@UpdateLikes"></Like>
4242
<ShareBlogPost></ShareBlogPost>
43-
</div>
44-
<Giscus></Giscus>
43+
</div>
44+
<CommentSection></CommentSection>
4545
</div>
4646
</div>
4747
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@inject AppConfiguration appConfiguration
2+
3+
@if (MultipleCommentPlugins)
4+
{
5+
<div class="alert alert-danger" role="alert">
6+
There are multiple comment sections configured. Please set up the configuration so that only one comment section is active.
7+
</div>
8+
}
9+
10+
@if (appConfiguration.IsDisqusEnabled)
11+
{
12+
<Disqus></Disqus>
13+
}
14+
@if (appConfiguration.IsGiscusEnabled)
15+
{
16+
<Giscus></Giscus>
17+
}
18+
19+
@code {
20+
private bool MultipleCommentPlugins => appConfiguration.IsDisqusEnabled && appConfiguration.IsGiscusEnabled;
21+
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inject IJSRuntime jsRuntime
2+
@inject AppConfiguration appConfiguration
3+
<div id="disqus_thread">
4+
</div>
5+
6+
@code {
7+
protected override async Task OnAfterRenderAsync(bool firstRender)
8+
{
9+
if (firstRender && appConfiguration.IsDisqusEnabled)
10+
{
11+
await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./Shared/Disqus.razor.js");
12+
await jsRuntime.InvokeVoidAsync("initDisqus", appConfiguration.DisqusConfiguration);
13+
}
14+
}
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
window.initDisqus = (disqus) => {
2+
var d = document, s = d.createElement('script');
3+
4+
s.src = `https://${disqus.shortname}.disqus.com/embed.js`;
5+
6+
s.setAttribute('data-timestamp', +new Date());
7+
d.body.appendChild(s);
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace LinkDotNet.Blog.Web.Shared.Services;
2+
3+
public record DisqusConfiguration
4+
{
5+
public string Shortname { get; init; }
6+
}

src/LinkDotNet.Blog.Web/appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,8 @@
3434
"RepositoryId": "",
3535
"Category": "",
3636
"CategoryId": ""
37+
},
38+
"Disqus": {
39+
"Shortname": "debug-blog-test"
3740
}
3841
}

0 commit comments

Comments
 (0)