Skip to content

Commit

Permalink
Merge pull request #745 from EdiWang/master
Browse files Browse the repository at this point in the history
Release v12.13.0
  • Loading branch information
EdiWang authored Aug 10, 2023
2 parents 6026cf0 + 296dfb8 commit 2c2d95a
Show file tree
Hide file tree
Showing 22 changed files with 241 additions and 2,445 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Docker Linux x64](https://github.com/EdiWang/Moonglade/actions/workflows/docker.yml/badge.svg)](https://github.com/EdiWang/Moonglade/actions/workflows/docker.yml)
![.NET Build Linux](https://github.com/EdiWang/Moonglade/workflows/.NET%20Build%20Linux/badge.svg)

The [.NET](https://dotnet.microsoft.com/) blog system of [edi.wang](https://edi.wang) that runs on [**Microsoft Azure**](https://azure.microsoft.com/en-us/). Designed for developers, enabling most common blogging features including posts, comments, categories, archive, tags and pages.
The [.NET](https://dotnet.microsoft.com/) blog system that optimized for [**Microsoft Azure**](https://azure.microsoft.com/en-us/). Designed for developers, enabling most common blogging features including posts, comments, categories, archive, tags and pages.

## 📦 Deployment

Expand All @@ -24,6 +24,17 @@ But there is no automated script to deploy it, you need to manually create all t

Use automated deployment script to get your Moonglade up and running in 10 minutes with minimal Azure components, follow instructions [here](https://github.com/EdiWang/Moonglade/wiki/Quick-Deploy-on-Azure)

### 🐋 Quick Deploy with Docker-Compose

Simply go the the root folder of this repo and run:

```bash
docker-compose build
docker-compose up
```

That's it! Now open: [Browser: http://localhost:8080](http://localhost:8080)

### 🐧 Quick Deploy on Linux without Docker

To quickly get it running on a new Linux machine without Docker, follow instructions [here](https://github.com/EdiWang/Moonglade/wiki/Quick-Install-on-Linux-Machine). You can watch video tutorial [here](https://anduins-site.player.aiur.site/moonglade-install.mp4).
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'
services:
db:
image: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: ROOT_SUPER_EVIL_PASSWORD@1234
MYSQL_DATABASE: AppDatabase
MYSQL_USER: WebApp
MYSQL_PASSWORD: WebApp@Passw0rd
ports:
- "3306:3306"
web:
build: .
environment:
ConnectionStrings__MoongladeDatabase: "Server=db;Database=AppDatabase;Uid=WebApp;Pwd=WebApp@Passw0rd;"
ConnectionStrings__DatabaseType: "MySQL"
ImageStorage__FileSystemPath: "/app/images"
ports:
- "8080:80"
depends_on:
- db
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:80"]
interval: 30s
timeout: 10s
retries: 5
6 changes: 3 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<Authors>Edi Wang</Authors>
<Company>edi.wang</Company>
<Copyright>(C) 2023 edi.wang@outlook.com</Copyright>
<AssemblyVersion>12.12.0.0</AssemblyVersion>
<FileVersion>12.12.0.0</FileVersion>
<Version>12.12.0</Version>
<AssemblyVersion>12.13.0.0</AssemblyVersion>
<FileVersion>12.13.0.0</FileVersion>
<Version>12.13.0</Version>
</PropertyGroup>
</Project>
31 changes: 22 additions & 9 deletions src/Moonglade.Comments/CreateCommentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Moonglade.Comments;

public class CreateCommentCommand : IRequest<CommentDetailedItem>
public class CreateCommentCommand : IRequest<(int Status, CommentDetailedItem Item)>
{
public CreateCommentCommand(Guid postId, CommentRequest payload, string ipAddress)
{
Expand All @@ -23,7 +23,7 @@ public CreateCommentCommand(Guid postId, CommentRequest payload, string ipAddres
public string IpAddress { get; set; }
}

public class CreateCommentCommandHandler : IRequestHandler<CreateCommentCommand, CommentDetailedItem>
public class CreateCommentCommandHandler : IRequestHandler<CreateCommentCommand, (int Status, CommentDetailedItem Item)>
{
private readonly IBlogConfig _blogConfig;
private readonly IRepository<PostEntity> _postRepo;
Expand All @@ -39,7 +39,7 @@ public CreateCommentCommandHandler(
_commentRepo = commentRepo;
}

public async Task<CommentDetailedItem> Handle(CreateCommentCommand request, CancellationToken ct)
public async Task<(int Status, CommentDetailedItem Item)> Handle(CreateCommentCommand request, CancellationToken ct)
{
if (_blogConfig.ContentSettings.EnableWordFilter)
{
Expand All @@ -53,12 +53,28 @@ public async Task<CommentDetailedItem> Handle(CreateCommentCommand request, Canc
if (await _moderator.HasBadWord(request.Payload.Username, request.Payload.Content))
{
await Task.CompletedTask;
return null;
return (-1, null);
}
break;
}
}

var spec = new PostSpec(request.PostId, false);
var postInfo = await _postRepo.FirstOrDefaultAsync(spec, p => new
{
p.Title,
p.PubDateUtc
});

if (_blogConfig.ContentSettings.CloseCommentAfterDays > 0)
{
var days = DateTime.UtcNow.Date.Subtract(postInfo.PubDateUtc.GetValueOrDefault()).Days;
if (days > _blogConfig.ContentSettings.CloseCommentAfterDays)
{
return (-2, null);
}
}

var model = new CommentEntity
{
Id = Guid.NewGuid(),
Expand All @@ -73,9 +89,6 @@ public async Task<CommentDetailedItem> Handle(CreateCommentCommand request, Canc

await _commentRepo.AddAsync(model, ct);

var spec = new PostSpec(request.PostId, false);
var postTitle = await _postRepo.FirstOrDefaultAsync(spec, p => p.Title);

var item = new CommentDetailedItem
{
Id = model.Id,
Expand All @@ -84,10 +97,10 @@ public async Task<CommentDetailedItem> Handle(CreateCommentCommand request, Canc
Email = model.Email,
IpAddress = model.IPAddress,
IsApproved = model.IsApproved,
PostTitle = postTitle,
PostTitle = postInfo.Title,
Username = model.Username
};

return item;
return (0, item);
}
}
13 changes: 13 additions & 0 deletions src/Moonglade.Configuration/ContentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class ContentSettings : IBlogSettings
{
[Display(Name = "Comment provider")]
public CommentProvider CommentProvider { get; set; }

[Display(Name = "Comments display order")]
public CommentOrder CommentOrder { get; set; }

[Display(Name = "Post title alignment")]
public PostTitleAlignment PostTitleAlignment { get; set; } = PostTitleAlignment.Left;
Expand All @@ -21,6 +24,10 @@ public class ContentSettings : IBlogSettings
[Display(Name = "Comments require review and approval")]
public bool RequireCommentReview { get; set; }

[Display(Name = "Automatically close comments on posts older than x days")]
[Range(0, 65536)]
public int CloseCommentAfterDays { get; set; }

[DataType(DataType.MultilineText)]
[Display(Name = "Blocked words")]
[MaxLength(2048)]
Expand Down Expand Up @@ -91,6 +98,12 @@ public enum CommentProvider
ThirdParty = 1
}

public enum CommentOrder
{
OldToNew = 0,
NewToOld = 1
}

public enum PostTitleAlignment
{
Left = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Data/Moonglade.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="MediatR" Version="12.1.1" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />

<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.10" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Moonglade.Utils/Moonglade.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="NUglify" Version="1.20.7" />
<PackageReference Include="Markdig" Version="0.31.0" />
<PackageReference Include="Markdig" Version="0.32.0" />
</ItemGroup>

</Project>
20 changes: 12 additions & 8 deletions src/Moonglade.Web/Controllers/CommentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,26 @@ public async Task<IActionResult> Create([NotEmpty] Guid postId, CommentRequest r
var ip = (bool)HttpContext.Items["DNT"]! ? "N/A" : Helper.GetClientIP(HttpContext);
var item = await _mediator.Send(new CreateCommentCommand(postId, request, ip));

if (item is null)
switch (item.Status)
{
ModelState.AddModelError(nameof(request.Content), "Your comment contains bad bad word.");
return Conflict(ModelState);
case -1:
ModelState.AddModelError(nameof(request.Content), "Your comment contains bad bad word.");
return Conflict(ModelState);
case -2:
ModelState.AddModelError(nameof(postId), "Comment is closed for this post.");
return Conflict(ModelState);
}

if (_blogConfig.NotificationSettings.SendEmailOnNewComment)
{
try
{
await _mediator.Publish(new CommentNotification(
item.Username,
item.Email,
item.IpAddress,
item.PostTitle,
item.CommentContent));
item.Item.Username,
item.Item.Email,
item.Item.IpAddress,
item.Item.PostTitle,
item.Item.CommentContent));
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Moonglade.Web/Moonglade.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="Edi.ImageWatermark" Version="2.8.0" />
<PackageReference Include="Edi.PasswordGenerator" Version="1.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="7.0.9" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="7.0.10" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="WilderMinds.MetaWeblog" Version="5.1.1" />
<PackageReference Include="Spectre.Console" Version="0.47.0" />
Expand Down
12 changes: 9 additions & 3 deletions src/Moonglade.Web/Pages/Components/CommentList/Default.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@

@if (null != Model && Model.Any())
{
var orderedList =
BlogConfig.ContentSettings.CommentOrder == CommentOrder.NewToOld ?
Model.OrderByDescending(m => m.CreateTimeUtc) :
Model.OrderBy(m => m.CreateTimeUtc);

<div class="comment-list row">
@foreach (var item in Model.OrderBy(m => m.CreateTimeUtc))
@foreach (var item in orderedList)
{
<div class="col-md-1 mb-3 d-none d-sm-block">
@if (BlogConfig.ContentSettings.EnableGravatar && !string.IsNullOrWhiteSpace(item.Email))
Expand Down Expand Up @@ -56,9 +61,10 @@
<strong>
@SharedLocalizer["Author"]
</strong>
<span class="float-end text-muted">@SharedLocalizer["Replied at"]
<span class="float-end text-muted">
@SharedLocalizer["Replied at"]
<time data-utc-label="@reply.ReplyTimeUtc.ToString("u")">@reply.ReplyTimeUtc</time>
</span>
</span>
</div>
<p>
@Html.Raw(ContentProcessor.MarkdownToContent(reply.ReplyContent, ContentProcessor.MarkdownConvertType.Html))
Expand Down
Loading

0 comments on commit 2c2d95a

Please sign in to comment.