diff --git a/Helpers/ConfigurationHelper.cs b/Helpers/ConfigurationHelper.cs new file mode 100644 index 0000000..821ea29 --- /dev/null +++ b/Helpers/ConfigurationHelper.cs @@ -0,0 +1,20 @@ +namespace StaticBlogTemplate.Helpers +{ + public class ConfigurationHelper + { + public static void Initialize(IConfiguration configuration) + { + Configuration = configuration; + } + + public static IConfiguration? Configuration { get; private set; } + + public static string BaseUrl + { + get + { + return Configuration?["Settings:BaseUrl"] ?? string.Empty; + } + } + } +} diff --git a/Program.cs b/Program.cs index ac1ce65..7627ee0 100644 --- a/Program.cs +++ b/Program.cs @@ -1,7 +1,10 @@ +using StaticBlogTemplate.Helpers; using StaticBlogTemplate.Utilities; var builder = WebApplication.CreateBuilder(args); +ConfigurationHelper.Initialize(builder.Configuration); + // Add services to the container. var mvcBuilder = builder.Services.AddControllersWithViews(); diff --git a/Utilities/RssCreator.cs b/Utilities/RssCreator.cs index f28127e..70635cc 100644 --- a/Utilities/RssCreator.cs +++ b/Utilities/RssCreator.cs @@ -1,3 +1,4 @@ +using StaticBlogTemplate.Helpers; using System.Text; namespace StaticBlogTemplate.Utilities; @@ -11,10 +12,10 @@ public static void Generate() My Super Blog - https://www.YOUR_BASE_URL.com/ + {ConfigurationHelper.BaseUrl}/ The description for the blog content of my site {today.ToString("r")} - + {{0}} "; @@ -23,7 +24,7 @@ public static void Generate() foreach (var post in PostManager.Posts) { - var fullUrl = $"https://www.YOUR_BASE_URL.com/{post.Value.RelativeUrl}"; + var fullUrl = $"{ConfigurationHelper.BaseUrl}/{post.Value.RelativeUrl}"; stringBuilder.Append($@" diff --git a/Utilities/SitemapCreator.cs b/Utilities/SitemapCreator.cs index e08a381..ac46289 100644 --- a/Utilities/SitemapCreator.cs +++ b/Utilities/SitemapCreator.cs @@ -1,3 +1,4 @@ +using StaticBlogTemplate.Helpers; using System.Text; namespace StaticBlogTemplate.Utilities; @@ -19,7 +20,7 @@ public static void Generate() "; var stringBuilder = new StringBuilder(); - var baseUrl = $"https://www.YOUR_BASE_URL.com/"; + var baseUrl = $"{ConfigurationHelper.BaseUrl}/"; stringBuilder.AppendFormat(template, baseUrl, "2023-02-10"); diff --git a/Views/Shared/_Layout.cshtml b/Views/Shared/_Layout.cshtml index 5c7e86a..52eb41f 100644 --- a/Views/Shared/_Layout.cshtml +++ b/Views/Shared/_Layout.cshtml @@ -1,6 +1,7 @@ -@{ +@using StaticBlogTemplate.Helpers; +@{ var relativeUrl = ViewBag.RelativeUrl; - var fullUrl = $"https://www.YOUR_BASE_URL.com/{relativeUrl}"; + var fullUrl = $"{ConfigurationHelper.BaseUrl}/{relativeUrl}"; } diff --git a/appsettings.json b/appsettings.json index 10f68b8..9ac774d 100644 --- a/appsettings.json +++ b/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, + "Settings": { + "BaseUrl": "https://www.YOUR_BASE_URL.com" + }, "AllowedHosts": "*" }