Skip to content

Commit d673d2a

Browse files
2 parents 78e8f14 + a525fde commit d673d2a

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

Helpers/ConfigurationHelper.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace StaticBlogTemplate.Helpers
2+
{
3+
public class ConfigurationHelper
4+
{
5+
public static void Initialize(IConfiguration configuration)
6+
{
7+
Configuration = configuration;
8+
}
9+
10+
public static IConfiguration? Configuration { get; private set; }
11+
12+
public static string BaseUrl
13+
{
14+
get
15+
{
16+
return Configuration?["Settings:BaseUrl"] ?? string.Empty;
17+
}
18+
}
19+
}
20+
}

Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
using StaticBlogTemplate.Helpers;
12
using StaticBlogTemplate.Utilities;
23

34
var builder = WebApplication.CreateBuilder(args);
45

6+
ConfigurationHelper.Initialize(builder.Configuration);
7+
58
// Add services to the container.
69
var mvcBuilder = builder.Services.AddControllersWithViews();
710

Utilities/RssCreator.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using StaticBlogTemplate.Helpers;
12
using System.Text;
23

34
namespace StaticBlogTemplate.Utilities;
@@ -11,10 +12,10 @@ public static void Generate()
1112
<rss version=""2.0"" xmlns:atom=""http://www.w3.org/2005/Atom"">
1213
<channel>
1314
<title>My Super Blog</title>
14-
<link>https://www.YOUR_BASE_URL.com/</link>
15+
<link>{ConfigurationHelper.BaseUrl}/</link>
1516
<description>The description for the blog content of my site</description>
1617
<lastBuildDate>{today.ToString("r")}</lastBuildDate>
17-
<atom:link href=""https://www.YOUR_BASE_URL.com/rss.xml"" rel=""self"" type=""application/rss+xml"" />
18+
<atom:link href=""{ConfigurationHelper.BaseUrl}/rss.xml"" rel=""self"" type=""application/rss+xml"" />
1819
{{0}}
1920
</channel>
2021
</rss>";
@@ -23,7 +24,7 @@ public static void Generate()
2324

2425
foreach (var post in PostManager.Posts)
2526
{
26-
var fullUrl = $"https://www.YOUR_BASE_URL.com/{post.Value.RelativeUrl}";
27+
var fullUrl = $"{ConfigurationHelper.BaseUrl}/{post.Value.RelativeUrl}";
2728

2829
stringBuilder.Append($@"
2930
<item>

Utilities/SitemapCreator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using StaticBlogTemplate.Helpers;
12
using System.Text;
23

34
namespace StaticBlogTemplate.Utilities;
@@ -19,7 +20,7 @@ public static void Generate()
1920
</url>";
2021

2122
var stringBuilder = new StringBuilder();
22-
var baseUrl = $"https://www.YOUR_BASE_URL.com/";
23+
var baseUrl = $"{ConfigurationHelper.BaseUrl}/";
2324

2425
stringBuilder.AppendFormat(template, baseUrl, "2023-02-10");
2526

Views/Shared/_Layout.cshtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
@{
1+
@using StaticBlogTemplate.Helpers;
2+
@{
23
var relativeUrl = ViewBag.RelativeUrl;
3-
var fullUrl = $"https://www.YOUR_BASE_URL.com/{relativeUrl}";
4+
var fullUrl = $"{ConfigurationHelper.BaseUrl}/{relativeUrl}";
45
}
56

67
<!DOCTYPE html>

appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"Microsoft.AspNetCore": "Warning"
66
}
77
},
8+
"Settings": {
9+
"BaseUrl": "https://www.YOUR_BASE_URL.com"
10+
},
811
"AllowedHosts": "*"
912
}

0 commit comments

Comments
 (0)