Skip to content

Commit a265ffc

Browse files
committed
Added Github Sponsor
1 parent 9c5a768 commit a265ffc

File tree

8 files changed

+59
-10
lines changed

8 files changed

+59
-10
lines changed

src/LinkDotNet.Blog.Web/AppConfiguration.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ public record AppConfiguration
3434
public string KofiToken { get; init; }
3535

3636
public bool IsKofiEnabled => !string.IsNullOrEmpty(KofiToken);
37-
}
37+
38+
public string GithubSponsorName { get; init; }
39+
40+
public bool IsGithubSponsorAvailable => !string.IsNullOrEmpty(GithubSponsorName);
41+
}

src/LinkDotNet.Blog.Web/AppConfigurationFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static AppConfiguration Create(IConfiguration config)
2626
GiscusConfiguration = giscus,
2727
DisqusConfiguration = disqus,
2828
KofiToken = config["KofiToken"],
29+
GithubSponsorName = config["GithubSponsorName"],
2930
};
3031

3132
return configuration;

src/LinkDotNet.Blog.Web/Features/ShowBlogPost/Components/DonationSection.razor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
@if (AppConfiguration.IsKofiEnabled)
44
{
55
<Kofi KofiToken="@AppConfiguration.KofiToken"></Kofi>
6+
}
7+
8+
@if (AppConfiguration.IsGithubSponsorAvailable)
9+
{
10+
<GithubSponsor Name="@AppConfiguration.GithubSponsorName"></GithubSponsor>
611
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<a href="https://github.com/sponsors/@Name" class="text-decoration-none border border-dark rounded p-2">
2+
<i class="github"></i> Sponsors
3+
</a>
4+
@code {
5+
[Parameter]
6+
public string Name { get; set; }
7+
}

src/LinkDotNet.Blog.Web/appsettings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@
3232
"Name": "Steven Giesel",
3333
"Heading": "Software Engineer",
3434
"ProfilePictureUrl": "assets/profile-picture.webp"
35-
}
35+
},
36+
"KofiToken": "----",
37+
"GithubSponsorName": "linkdotnet"
3638
}

tests/LinkDotNet.Blog.UnitTests/Web/AppConfigurationFactoryTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void ShouldMapFromAppConfiguration()
3131
{ "Giscus:CategoryId", "generalid" },
3232
{ "Disqus:Shortname", "blog" },
3333
{ "KofiToken", "ABC" },
34+
{ "GithubSponsorName", "linkdotnet" },
3435
};
3536
var configuration = new ConfigurationBuilder()
3637
.AddInMemoryCollection(inMemorySettings)
@@ -62,6 +63,7 @@ public void ShouldMapFromAppConfiguration()
6263
appConfiguration.GiscusConfiguration.CategoryId.Should().Be("generalid");
6364
appConfiguration.DisqusConfiguration.Shortname.Should().Be("blog");
6465
appConfiguration.KofiToken.Should().Be("ABC");
66+
appConfiguration.GithubSponsorName.Should().Be("linkdotnet");
6567
}
6668

6769
[Theory]

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/Components/DonationSectionTests.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,37 @@ namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;
66

77
public class DonationSectionTests : TestContext
88
{
9-
[Fact]
10-
public void ShouldShowKofiWhenTokenIsSet()
9+
[Theory]
10+
[InlineData("linkdotnet", true)]
11+
[InlineData(null, false)]
12+
13+
public void ShouldShowKofiIfSet(string token, bool hasComponent)
1114
{
1215
var appConfig = new AppConfiguration
1316
{
14-
KofiToken = "set",
17+
KofiToken = token,
1518
};
1619
Services.AddScoped(_ => appConfig);
1720

1821
var cut = RenderComponent<DonationSection>();
1922

20-
cut.FindComponents<Kofi>().Should().HaveCount(1);
23+
cut.HasComponent<Kofi>().Should().Be(hasComponent);
2124
}
2225

23-
[Fact]
24-
public void ShouldHideKofiWhenTokenNotSet()
26+
[Theory]
27+
[InlineData("linkdotnet", true)]
28+
[InlineData(null, false)]
29+
30+
public void ShouldShowGithubSponsorIfSet(string account, bool hasComponent)
2531
{
26-
var appConfig = new AppConfiguration();
32+
var appConfig = new AppConfiguration
33+
{
34+
GithubSponsorName = account,
35+
};
2736
Services.AddScoped(_ => appConfig);
2837

2938
var cut = RenderComponent<DonationSection>();
3039

31-
cut.FindComponents<Kofi>().Should().HaveCount(0);
40+
cut.HasComponent<GithubSponsor>().Should().Be(hasComponent);
3241
}
3342
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using AngleSharp.Html.Dom;
2+
using AngleSharpWrappers;
3+
using LinkDotNet.Blog.Web.Features.ShowBlogPost.Components;
4+
5+
namespace LinkDotNet.Blog.UnitTests.Web.Features.ShowBlogPost.Components;
6+
7+
public class GithubSponsorTests : TestContext
8+
{
9+
[Fact]
10+
public void ShouldSetUrlCorrect()
11+
{
12+
var cut = RenderComponent<GithubSponsor>(
13+
p => p.Add(g => g.Name, "linkdotnet"));
14+
15+
var anchor = cut.Find("a").Unwrap() as IHtmlAnchorElement;
16+
anchor.Should().NotBeNull();
17+
anchor.Href.Should().Be("https://github.com/sponsors/linkdotnet");
18+
}
19+
}

0 commit comments

Comments
 (0)