Skip to content

Commit

Permalink
Merge pull request #823 from EdiWang/fix/routelink-culture
Browse files Browse the repository at this point in the history
Use CultureInfo.InvariantCulture for date formatting
  • Loading branch information
EdiWang authored Sep 21, 2024
2 parents 495d1a7 + 0d4861f commit 3b1d9c3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Moonglade.Core/PostFeature/CreatePostCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration;
using System.Globalization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Moonglade.Configuration;
using Moonglade.Data;
Expand Down Expand Up @@ -53,7 +54,7 @@ public async Task<PostEntity> Handle(CreatePostCommand request, CancellationToke
IsOutdated = request.Payload.IsOutdated,
};

post.RouteLink = $"{post.PubDateUtc.GetValueOrDefault():yyyy/M/d}/{request.Payload.Slug}";
post.RouteLink = $"{post.PubDateUtc.GetValueOrDefault().ToString("yyyy/M/d", CultureInfo.InvariantCulture)}/{request.Payload.Slug}";

// check if exist same slug under the same day
var todayUtc = DateTime.UtcNow.Date;
Expand Down
3 changes: 2 additions & 1 deletion src/Moonglade.Core/PostFeature/UpdatePostCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Moonglade.Data;
using Moonglade.Data.Specifications;
using Moonglade.Utils;
using System.Globalization;

namespace Moonglade.Core.PostFeature;

Expand Down Expand Up @@ -92,7 +93,7 @@ public async Task<PostEntity> Handle(UpdatePostCommand request, CancellationToke
post.IsFeatured = postEditModel.Featured;
post.HeroImageUrl = string.IsNullOrWhiteSpace(postEditModel.HeroImageUrl) ? null : Helper.SterilizeLink(postEditModel.HeroImageUrl);
post.IsOutdated = postEditModel.IsOutdated;
post.RouteLink = $"{post.PubDateUtc.GetValueOrDefault():yyyy/M/d}/{postEditModel.Slug}";
post.RouteLink = $"{post.PubDateUtc.GetValueOrDefault().ToString("yyyy/M/d", CultureInfo.InvariantCulture)}/{postEditModel.Slug}";

// 1. Add new tags to tag lib
var tags = string.IsNullOrWhiteSpace(postEditModel.Tags) ?
Expand Down
3 changes: 2 additions & 1 deletion src/Moonglade.Data/Seed.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using Moonglade.Data.Entities;
using System.Globalization;

namespace Moonglade.Data;

Expand Down Expand Up @@ -48,7 +49,7 @@ public static async Task SeedAsync(BlogDbContext dbContext, ILogger logger, int
ContentLanguageCode = "en-us",
Tags = dbContext.Tag.ToList(),
PostCategory = dbContext.PostCategory.ToList(),
RouteLink = $"{DateTime.UtcNow:yyyy/M/d}/welcome-to-moonglade"
RouteLink = $"{DateTime.UtcNow.ToString("yyyy/M/d", CultureInfo.InvariantCulture)}/welcome-to-moonglade"
};

await dbContext.Post.AddAsync(post);
Expand Down

0 comments on commit 3b1d9c3

Please sign in to comment.