Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/Migrations/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ This is contrasted by Minor changes. These are things where the user does not ne

Breaking changes are recorded in the [MIGRATION.md](../../MIGRATION.md). Since version 9 of the blog, “Entity Framework Migrations” has been introduced for all SQL providers. You can read more in the [documentation](../Storage/Readme.md). In a nutshell, this means that database migration can be carried out easily via the “ef migration” CLI tool. More on this in the documentation linked above.

Changes for the appsettings.json must currently still be made manually. The exact changes that need to be made here can be found in MIGRATION.md.
Changes for the appsettings.json must currently still be made manually. The exact changes that need to be made here can be found in MIGRATION.md.

## UNRELEASED

A new config has been added `UseMultiAuthorMode` in `appsettings.json`. The default value of this config is `false`. If set to `true` then author name will be associated with blog posts at the time of creation.
4 changes: 3 additions & 1 deletion docs/Setup/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ The appsettings.json file has a lot of options to customize the content of the b
"ServiceUrl": "",
"ContainerName": "",
"CdnEndpoint": ""
}
},
"UseMultiAuthorMode": false
}
```

Expand Down Expand Up @@ -109,3 +110,4 @@ The appsettings.json file has a lot of options to customize the content of the b
| ServiceUrl | string | The host url of the Azure blob storage. Only used if `AuthenticationMode` is set to `Default` |
| ContainerName | string | The container name for the image storage provider |
| CdnEndpoint | string | Optional CDN endpoint to use for uploaded images. If set, the blog will return this URL instead of the storage account URL for uploaded assets. |
| UseMultiAuthorMode | boolean | The default value is `false`. If set to `true` then author name will be associated with blog posts at the time of creation. This author name will be fetched from the identity provider's `name` or `nickname` or `preferred_username` claim property. |
7 changes: 6 additions & 1 deletion src/LinkDotNet.Blog.Domain/BlogPost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public sealed partial class BlogPost : Entity

public string Slug => GenerateSlug();

public string? AuthorName { get; private set; }

private string GenerateSlug()
{
if (string.IsNullOrWhiteSpace(Title))
Expand Down Expand Up @@ -92,7 +94,8 @@ public static BlogPost Create(
DateTime? updatedDate = null,
DateTime? scheduledPublishDate = null,
IEnumerable<string>? tags = null,
string? previewImageUrlFallback = null)
string? previewImageUrlFallback = null,
string? authorName = null)
{
if (scheduledPublishDate is not null && isPublished)
{
Expand All @@ -113,6 +116,7 @@ public static BlogPost Create(
IsPublished = isPublished,
Tags = tags?.Select(t => t.Trim()).ToImmutableArray() ?? [],
ReadingTimeInMinutes = ReadingTimeCalculator.CalculateReadingTime(content),
AuthorName = authorName
};

return blogPost;
Expand Down Expand Up @@ -143,5 +147,6 @@ public void Update(BlogPost from)
IsPublished = from.IsPublished;
Tags = from.Tags;
ReadingTimeInMinutes = from.ReadingTimeInMinutes;
AuthorName = from.AuthorName;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace LinkDotNet.Blog.Web.Migrations;

/// <inheritdoc />
public partial class AddAuthorNameInBlogPost : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);

migrationBuilder.AddColumn<string>(
name: "AuthorName",
table: "BlogPosts",
type: "nvarchar(256)",
maxLength: 256,
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
ArgumentNullException.ThrowIfNull(migrationBuilder);

migrationBuilder.DropColumn(
name: "AuthorName",
table: "BlogPosts");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using System;
using LinkDotNet.Blog.Infrastructure.Persistence.Sql;
using Microsoft.EntityFrameworkCore;
Expand All @@ -24,6 +24,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsUnicode(false)
.HasColumnType("TEXT");

b.Property<string>("AuthorName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");

b.Property<string>("Content")
.IsRequired()
.HasColumnType("TEXT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void Configure(EntityTypeBuilder<BlogPost> builder)
builder.Property(x => x.IsPublished).IsRequired();

builder.Property(x => x.Tags).HasMaxLength(2048);
builder.Property(x => x.AuthorName).HasMaxLength(256).IsRequired(false);

builder.HasIndex(x => new { x.IsPublished, x.UpdatedDate })
.HasDatabaseName("IX_BlogPosts_IsPublished_UpdatedDate")
Expand Down
2 changes: 2 additions & 0 deletions src/LinkDotNet.Blog.Web/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public sealed record ApplicationConfiguration
public bool ShowReadingIndicator { get; init; }

public bool ShowSimilarPosts { get; init; }

public bool UseMultiAuthorMode { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
Expand Down Expand Up @@ -27,6 +27,7 @@ public async Task SignInAsync(string redirectUri)
var claims = new[]
{
new Claim(ClaimTypes.Name, "Dummy user"),
new Claim("name", "Dummy user"),
new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString()),
};
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
Expand Down
Loading