Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
CamiloTerevinto committed Nov 17, 2023
2 parents 78e8f14 + a525fde commit d673d2a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
20 changes: 20 additions & 0 deletions Helpers/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
3 changes: 3 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
7 changes: 4 additions & 3 deletions Utilities/RssCreator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using StaticBlogTemplate.Helpers;
using System.Text;

namespace StaticBlogTemplate.Utilities;
Expand All @@ -11,10 +12,10 @@ public static void Generate()
<rss version=""2.0"" xmlns:atom=""http://www.w3.org/2005/Atom"">
<channel>
<title>My Super Blog</title>
<link>https://www.YOUR_BASE_URL.com/</link>
<link>{ConfigurationHelper.BaseUrl}/</link>
<description>The description for the blog content of my site</description>
<lastBuildDate>{today.ToString("r")}</lastBuildDate>
<atom:link href=""https://www.YOUR_BASE_URL.com/rss.xml"" rel=""self"" type=""application/rss+xml"" />
<atom:link href=""{ConfigurationHelper.BaseUrl}/rss.xml"" rel=""self"" type=""application/rss+xml"" />
{{0}}
</channel>
</rss>";
Expand All @@ -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($@"
<item>
Expand Down
3 changes: 2 additions & 1 deletion Utilities/SitemapCreator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using StaticBlogTemplate.Helpers;
using System.Text;

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

var stringBuilder = new StringBuilder();
var baseUrl = $"https://www.YOUR_BASE_URL.com/";
var baseUrl = $"{ConfigurationHelper.BaseUrl}/";

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

Expand Down
5 changes: 3 additions & 2 deletions Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -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}";
}

<!DOCTYPE html>
Expand Down
3 changes: 3 additions & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"Settings": {
"BaseUrl": "https://www.YOUR_BASE_URL.com"
},
"AllowedHosts": "*"
}

0 comments on commit d673d2a

Please sign in to comment.