diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Members/MemberAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Members/MemberAppService.cs index 4ef8e72daf..0ccb9ac22b 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Members/MemberAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Members/MemberAppService.cs @@ -17,7 +17,7 @@ public class MemberAppService : BloggingAppServiceBase, IMemberAppService public virtual async Task FindAsync(string username) { - var user = await _userRepository.FindAsync(x => x.UserName == username); + var user = await _userRepository.FindAsync(x => x.UserName == username && x.IsActive); if (user == null) { diff --git a/modules/blogging/src/Volo.Blogging.Web/BloggingUrlOptions.cs b/modules/blogging/src/Volo.Blogging.Web/BloggingUrlOptions.cs index 44414acf41..f66258c211 100644 --- a/modules/blogging/src/Volo.Blogging.Web/BloggingUrlOptions.cs +++ b/modules/blogging/src/Volo.Blogging.Web/BloggingUrlOptions.cs @@ -20,6 +20,9 @@ namespace Volo.Blogging /// Used to specify ignore paths if the route prefix is null or empty. /// public List IgnoredPaths { get; } = new (); + + + public SingleBlogModeOptions SingleBlogMode { get; } = new (); private string GetFormattedRoutePrefix() { @@ -31,4 +34,15 @@ namespace Volo.Blogging return _routePrefix.EnsureEndsWith('/').EnsureStartsWith('/'); } } + + public class SingleBlogModeOptions + { + /// + /// Determines whether to enable single blog mode by removing the blog name from the routing. + /// When enabled, only a single blog is allowed within the module. + /// + public bool Enable { get; set; } + + public string BlogName { get; set; } + } } diff --git a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs index dd8d65ea6b..c35e60db3e 100644 --- a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs +++ b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc.RazorPages; +using System; +using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -79,7 +80,7 @@ namespace Volo.Blogging options.IgnoredPaths.AddRange(new[] { "error", "ApplicationConfigurationScript", "ServiceProxyScript", "Languages/Switch", - "ApplicationLocalizationScript" + "ApplicationLocalizationScript", "members" }); }); @@ -91,11 +92,26 @@ namespace Volo.Blogging var routePrefix = urlOptions.RoutePrefix; - options.Conventions.AddPageRoute("/Blogs/Posts/Index", routePrefix + "{blogShortName:blogNameConstraint}"); - options.Conventions.AddPageRoute("/Blogs/Posts/Detail", routePrefix + "{blogShortName:blogNameConstraint}/{postUrl}"); - options.Conventions.AddPageRoute("/Blogs/Posts/Edit", routePrefix + "{blogShortName}/posts/{postId}/edit"); - options.Conventions.AddPageRoute("/Blogs/Posts/New", routePrefix + "{blogShortName}/posts/new"); - options.Conventions.AddPageRoute("/Members/Index", routePrefix + "members/{userName}"); + if (urlOptions.SingleBlogMode.Enable) + { + options.Conventions.AddPageRoute("/Blogs/Posts/Index", routePrefix); + options.Conventions.AddPageRoute("/Blogs/Posts/Detail", routePrefix + "{postUrl}"); + options.Conventions.AddPageRoute("/Blogs/Posts/Edit", routePrefix + "posts/{postId}/edit"); + options.Conventions.AddPageRoute("/Blogs/Posts/New", routePrefix + "posts/new"); + } + else + { + if (!routePrefix.IsNullOrWhiteSpace()) + { + options.Conventions.AddPageRoute("/Blogs/Index", routePrefix); + } + options.Conventions.AddPageRoute("/Blogs/Posts/Index", routePrefix + "{blogShortName:blogNameConstraint}"); + options.Conventions.AddPageRoute("/Blogs/Posts/Detail", routePrefix + "{blogShortName:blogNameConstraint}/{postUrl}"); + options.Conventions.AddPageRoute("/Blogs/Posts/Edit", routePrefix + "{blogShortName}/posts/{postId}/edit"); + options.Conventions.AddPageRoute("/Blogs/Posts/New", routePrefix + "{blogShortName}/posts/new"); + } + + options.Conventions.AddPageRoute("/Blogs/Members/Index", routePrefix + "members/{userName}"); }); Configure(options => diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageModel.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageModel.cs index 8e118810e8..74c924404e 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageModel.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/BloggingPageModel.cs @@ -1,4 +1,8 @@ -using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using System; +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; +using Volo.Blogging.Blogs; +using Volo.Blogging.Blogs.Dtos; namespace Volo.Blogging.Pages.Blog { @@ -8,5 +12,26 @@ namespace Volo.Blogging.Pages.Blog { ObjectMapperContext = typeof(BloggingWebModule); } + + protected async Task GetBlogAsync(IBlogAppService blogAppService, BloggingUrlOptions blogOptions, string blogShortName) + { + if (!blogOptions.SingleBlogMode.Enable) + { + return await blogAppService.GetByShortNameAsync(blogShortName); + } + + if (!blogOptions.SingleBlogMode.BlogName.IsNullOrEmpty()) + { + return await blogAppService.GetByShortNameAsync(blogOptions.SingleBlogMode.BlogName); + } + + var blogs = await blogAppService.GetListAsync(); + if (blogs.Items.Count == 1) + { + return blogs.Items[0]; + } + + return await blogAppService.GetByShortNameAsync(blogOptions.SingleBlogMode.BlogName); + } } } \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Index.cshtml.cs index 32a451c8be..83abf579ec 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Index.cshtml.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Blogs; using Volo.Blogging.Blogs.Dtos; @@ -10,16 +11,23 @@ namespace Volo.Blogging.Pages.Blog public class IndexModel : AbpPageModel { private readonly IBlogAppService _blogAppService; + private readonly BloggingUrlOptions _blogOptions; public IReadOnlyList Blogs { get; private set; } - public IndexModel(IBlogAppService blogAppService) + public IndexModel(IBlogAppService blogAppService, IOptions blogOptions) { _blogAppService = blogAppService; + _blogOptions = blogOptions.Value; } public virtual async Task OnGetAsync() { + if (_blogOptions.SingleBlogMode.Enable) + { + return RedirectToPage("./Posts/Index"); + } + var result = await _blogAppService.GetListAsync(); if (result.Items.Count == 1) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.cshtml similarity index 98% rename from modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml rename to modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.cshtml index ae68a1561a..e0465ba57a 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.cshtml @@ -5,7 +5,7 @@ @using Volo.Abp.Users @using Volo.Blogging.Areas.Blog.Helpers.TagHelpers @using Volo.Blogging.Localization -@model Volo.Blogging.Pages.Members.IndexModel +@model Volo.Blogging.Pages.Blogs.Members.IndexModel @inject IStringLocalizer L @inject ICurrentUser CurrentUser @{ @@ -13,11 +13,11 @@ } @section scripts { - + } @section styles { - + }
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.cshtml.cs similarity index 97% rename from modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml.cs rename to modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.cshtml.cs index 43cd31fd4a..acff24cc4f 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.cshtml.cs @@ -8,7 +8,7 @@ using Volo.Blogging.Blogs; using Volo.Blogging.Members; using Volo.Blogging.Posts; -namespace Volo.Blogging.Pages.Members; +namespace Volo.Blogging.Pages.Blogs.Members; public class IndexModel : AbpPageModel { diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.css b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.css similarity index 100% rename from modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.css rename to modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.css diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.js similarity index 100% rename from modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.js rename to modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Members/Index.js diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml index 9a65911d3b..20b4ed3dc2 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml @@ -67,7 +67,7 @@
@if (Model.Post.Writer != null) { - + User Avatar } @@ -76,7 +76,7 @@ @if (Model.Post.Writer != null) {
- + @(Model.Post.Writer.UserName) @BloggingPageHelper.GetLocalizedTimeAgoText(Model.Post.CreationTime) @@ -141,7 +141,7 @@ @if (Model.LatestPosts.Count > 1) @@ -194,14 +194,14 @@ {
- + @(post.Writer!.UserName)
@@ -456,13 +456,13 @@ else var post = Model.PostsList[index];
- +