Skip to content

Commit d432923

Browse files
committed
Added AppConfig to toggle
1 parent a7b72eb commit d432923

File tree

7 files changed

+65
-32
lines changed

7 files changed

+65
-32
lines changed

Readme.md

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,41 @@ The appsettings.json file has a lot of options to customize the content of the b
5858
"Shortname": "blog"
5959
},
6060
"KofiToken": "ABC123",
61-
"GithubSponsorName": "your-tag-here"
61+
"GithubSponsorName": "your-tag-here",
62+
"ShowReadingIndicator": true
6263
}
6364

6465
```
6566

66-
| Property | Type | Description |
67-
| ------------------------- | -------------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------|
68-
| BlogName | string | Name of your blog. Is used in the navbar and is used as the title of the page. Will not be shown when `BlogBrandUrl` is set |
69-
| BlogBrandUrl | string | The url to an image which is used as a brand image in the navigation bar. If not set or `null` the `BlogName` will be shown |
70-
| Social | node | Represents all possible linked social accounts |
71-
| GithubAccountUrl | string | Url to your github account. If not set it is not shown in the introduction card |
72-
| LinkedInAccountUrl | string | Url to your LinkedIn account. If not set it is not shown in the introduction card |
73-
| TwitterAccountUrl | string | Url to your Twitter account. If not set it is not shown in the introduction card |
74-
| Introduction | | Is used for the introduction part of the blog |
75-
| Description | MarkdownString | Small introduction text for yourself. This is also used for `<meta name="description">` tag. For this the markup will be converted to plain text |
76-
| BackgroundUrl | string | Url or path to the background image. (Optional) |
77-
| ProfilePictureUrl | string | Url or path to your profile picture |
67+
| Property | Type | Description |
68+
| ------------------------- | -------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
69+
| BlogName | string | Name of your blog. Is used in the navbar and is used as the title of the page. Will not be shown when `BlogBrandUrl` is set |
70+
| BlogBrandUrl | string | The url to an image which is used as a brand image in the navigation bar. If not set or `null` the `BlogName` will be shown |
71+
| Social | node | Represents all possible linked social accounts |
72+
| GithubAccountUrl | string | Url to your github account. If not set it is not shown in the introduction card |
73+
| LinkedInAccountUrl | string | Url to your LinkedIn account. If not set it is not shown in the introduction card |
74+
| TwitterAccountUrl | string | Url to your Twitter account. If not set it is not shown in the introduction card |
75+
| Introduction | | Is used for the introduction part of the blog |
76+
| Description | MarkdownString | Small introduction text for yourself. This is also used for `<meta name="description">` tag. For this the markup will be converted to plain text |
77+
| BackgroundUrl | string | Url or path to the background image. (Optional) |
78+
| ProfilePictureUrl | string | Url or path to your profile picture |
7879
| PersistenceProvider | string | Declares the type of the storage provider (one of the following: `SqlServer`, `Sqlite`, `RavenDb`, `InMemory`, `MySql`). More in-depth explanation down below |
79-
| ConnectionString | string | Is used for connection to a database. Not used when `InMemoryStorageProvider` is used |
80-
| DatabaseName | string | Name of the database. Only used with `RavenDbStorageProvider` |
81-
| Auth0 | | Configuration for setting up Auth0 |
82-
| Domain | string | See more details here: https://manage.auth0.com/dashboard/ |
83-
| ClientId | string | See more details here: https://manage.auth0.com/dashboard/ |
84-
| ClientSecret | string | See more details here: https://manage.auth0.com/dashboard/ |
85-
| BlogPostsPerPage | int | Gives the amount of blog posts loaded and display per page. For more the user has to use the navigation |
86-
| AboutMeProfileInformation | node | Sets information for the About Me Page. If omitted the page is disabled completely |
87-
| Name | string | Name, which is displayed on top of the profile card |
88-
| Heading | string | Displayed under the name. For example job title |
89-
| ProfilePictureUrl | string | Displayed profile picture |
80+
| ConnectionString | string | Is used for connection to a database. Not used when `InMemoryStorageProvider` is used |
81+
| DatabaseName | string | Name of the database. Only used with `RavenDbStorageProvider` |
82+
| Auth0 | | Configuration for setting up Auth0 |
83+
| Domain | string | See more details here: https://manage.auth0.com/dashboard/ |
84+
| ClientId | string | See more details here: https://manage.auth0.com/dashboard/ |
85+
| ClientSecret | string | See more details here: https://manage.auth0.com/dashboard/ |
86+
| BlogPostsPerPage | int | Gives the amount of blog posts loaded and display per page. For more the user has to use the navigation |
87+
| AboutMeProfileInformation | node | Sets information for the About Me Page. If omitted the page is disabled completely |
88+
| Name | string | Name, which is displayed on top of the profile card |
89+
| Heading | string | Displayed under the name. For example job title |
90+
| ProfilePictureUrl | string | Displayed profile picture |
9091
| Giscus | node | Enables the comment section via giscus. If left empty the comment secion will not be shown. For more information checkout the section about comments down below |
9192
| Disqus | node | Enables the comment section via disqus. If left empty the comment secion will not be shown. For more information checkout the section about comments down below |
92-
| KofiToken | string | Enables the "Buy me a Coffee" button of Kofi. To aquire the token head down to the "Kofi" section |
93-
| GithubSponsorName | string | Enables the "Github Sponsor" button which redirects to GitHub. Only pass in the user name instead of the url. |
93+
| KofiToken | string | Enables the "Buy me a Coffee" button of Kofi. To aquire the token head down to the "Kofi" section |
94+
| GithubSponsorName | string | Enables the "Github Sponsor" button which redirects to GitHub. Only pass in the user name instead of the url. |
95+
| ShowReadingIndicator | boolean | If set to `true` (default) a circle indicates the progress when a user reads a blog post (without comments). |
9496

9597
## Storage Provider
9698
Currently, there are 5 Storage-Provider:

src/LinkDotNet.Blog.Web/AppConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@ public record AppConfiguration
3838
public string GithubSponsorName { get; init; }
3939

4040
public bool IsGithubSponsorAvailable => !string.IsNullOrEmpty(GithubSponsorName);
41+
42+
public bool ShowReadingIndicator { get; init; }
4143
}

src/LinkDotNet.Blog.Web/AppConfigurationFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static AppConfiguration Create(IConfiguration config)
2828
DisqusConfiguration = disqus,
2929
KofiToken = config[nameof(AppConfiguration.KofiToken)],
3030
GithubSponsorName = config[nameof(AppConfiguration.GithubSponsorName)],
31+
ShowReadingIndicator = config.GetValue<bool>(nameof(AppConfiguration.ShowReadingIndicator)),
3132
};
3233

3334
return configuration;

src/LinkDotNet.Blog.Web/Features/ShowBlogPost/ShowBlogPostPage.razor

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@inject IRepository<BlogPost> BlogPostRepository
88
@inject IJSRuntime JsRuntime
99
@inject IUserRecordService UserRecordService
10+
@inject AppConfiguration AppConfiguration
1011

1112
@if (BlogPost == null)
1213
{
@@ -54,7 +55,10 @@ else
5455
</div>
5556
</div>
5657

57-
<ReadingIndicator ContainerCssSelector=".blog-inner-content"/>
58+
@if (AppConfiguration.ShowReadingIndicator)
59+
{
60+
<ReadingIndicator ContainerCssSelector=".blog-inner-content"/>
61+
}
5862
}
5963

6064
@code {

src/LinkDotNet.Blog.Web/appsettings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
"Name": "Steven Giesel",
3333
"Heading": "Software Engineer",
3434
"ProfilePictureUrl": "assets/profile-picture.webp",
35-
}
35+
},
36+
"ShowReadingIndicator": true,
3637
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void ShouldMapFromAppConfiguration()
3232
{ "Disqus:Shortname", "blog" },
3333
{ "KofiToken", "ABC" },
3434
{ "GithubSponsorName", "linkdotnet" },
35+
{ "ShowReadingIndicator", "true" },
3536
};
3637
var configuration = new ConfigurationBuilder()
3738
.AddInMemoryCollection(inMemorySettings)
@@ -64,6 +65,7 @@ public void ShouldMapFromAppConfiguration()
6465
appConfiguration.DisqusConfiguration.Shortname.Should().Be("blog");
6566
appConfiguration.KofiToken.Should().Be("ABC");
6667
appConfiguration.GithubSponsorName.Should().Be("linkdotnet");
68+
appConfiguration.ShowReadingIndicator.Should().BeTrue();
6769
}
6870

6971
[Theory]

tests/LinkDotNet.Blog.UnitTests/Web/Features/ShowBlogPost/ShowBlogPostPageTests.cs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ public void ShouldShowLoadingAnimation()
2222
{
2323
const string blogPostId = "2";
2424
var repositoryMock = new Mock<IRepository<BlogPost>>();
25-
JSInterop.Mode = JSRuntimeMode.Loose;
25+
SetupMocks();
2626
Services.AddScoped(_ => repositoryMock.Object);
27-
Services.AddScoped(_ => Mock.Of<IUserRecordService>());
2827
repositoryMock.Setup(r => r.GetByIdAsync(blogPostId))
2928
.Returns(async () =>
3029
{
@@ -80,7 +79,6 @@ public void ShouldUseFallbackAsOgDataIfAvailable(string preview, string fallback
8079
[Fact]
8180
public void ShowTagWithLinksWhenAvailable()
8281
{
83-
JSInterop.Mode = JSRuntimeMode.Loose;
8482
var repositoryMock = new Mock<IRepository<BlogPost>>();
8583
var blogPost = new BlogPostBuilder()
8684
.WithTags("tag1")
@@ -100,7 +98,6 @@ public void ShowTagWithLinksWhenAvailable()
10098
[Fact]
10199
public void ShowNotShowTagsWhenNotSet()
102100
{
103-
JSInterop.Mode = JSRuntimeMode.Loose;
104101
var repositoryMock = new Mock<IRepository<BlogPost>>();
105102
var blogPost = new BlogPostBuilder()
106103
.Build();
@@ -114,8 +111,32 @@ public void ShowNotShowTagsWhenNotSet()
114111
cut.FindAll(".goto-tag").Should().BeEmpty();
115112
}
116113

114+
[Theory]
115+
[InlineData(true, 1)]
116+
[InlineData(false, 0)]
117+
public void ShowReadingIndicatorWhenEnabled(bool isEnabled, int count)
118+
{
119+
var appConfiguration = new AppConfiguration
120+
{
121+
ShowReadingIndicator = isEnabled,
122+
};
123+
var repositoryMock = new Mock<IRepository<BlogPost>>();
124+
var blogPost = new BlogPostBuilder()
125+
.Build();
126+
repositoryMock.Setup(r => r.GetByIdAsync("1")).ReturnsAsync(blogPost);
127+
Services.AddScoped(_ => repositoryMock.Object);
128+
SetupMocks();
129+
Services.AddScoped(_ => appConfiguration);
130+
131+
var cut = RenderComponent<ShowBlogPostPage>(
132+
p => p.Add(s => s.BlogPostId, "1"));
133+
134+
cut.FindComponents<ReadingIndicator>().Count.Should().Be(count);
135+
}
136+
117137
private void SetupMocks()
118138
{
139+
JSInterop.Mode = JSRuntimeMode.Loose;
119140
Services.AddScoped(_ => Mock.Of<IUserRecordService>());
120141
Services.AddScoped(_ => Mock.Of<IToastService>());
121142
Services.AddScoped(_ => Mock.Of<AppConfiguration>());

0 commit comments

Comments
 (0)