mirror of https://github.com/abpframework/abp.git
committed by
GitHub
23 changed files with 327 additions and 93 deletions
@ -0,0 +1,39 @@ |
|||||
|
using Microsoft.AspNetCore.Builder; |
||||
|
using Microsoft.AspNetCore.Routing; |
||||
|
using Volo.Abp.GlobalFeatures; |
||||
|
using Volo.CmsKit.GlobalFeatures; |
||||
|
using Volo.CmsKit.Public.Web.Pages; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.Web; |
||||
|
|
||||
|
public static class CmsKitPagesConfigurationExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Maps CMS Kit to the routing.
|
||||
|
/// </summary>
|
||||
|
/// <param name="builder"></param>
|
||||
|
/// <param name="order">The matching order for the dynamic route. Lower is prior.</param>
|
||||
|
public static IEndpointRouteBuilder MapCmsPageRoute(this IEndpointRouteBuilder builder, int? order = null) |
||||
|
{ |
||||
|
if (!GlobalFeatureManager.Instance.IsEnabled<PagesFeature>()) |
||||
|
{ |
||||
|
return builder; |
||||
|
} |
||||
|
|
||||
|
builder |
||||
|
.MapDynamicPageRoute<CmsKitHomePageRouteValueTransformer>("/", state: null, order: int.MinValue); |
||||
|
|
||||
|
if (order is null) |
||||
|
{ |
||||
|
builder |
||||
|
.MapDynamicPageRoute<CmsKitPageRouteValueTransformer>("{**slug}"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
builder |
||||
|
.MapDynamicPageRoute<CmsKitPageRouteValueTransformer>("{**slug}", state: default, order: order.Value); |
||||
|
} |
||||
|
|
||||
|
return builder; |
||||
|
} |
||||
|
} |
||||
@ -1,34 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Microsoft.AspNetCore.Http; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Volo.Abp.DependencyInjection; |
|
||||
using Volo.Abp.Features; |
|
||||
using Volo.CmsKit.Features; |
|
||||
using Volo.CmsKit.Pages; |
|
||||
using Volo.CmsKit.Public.Pages; |
|
||||
|
|
||||
namespace Volo.CmsKit.Public.Web; |
|
||||
|
|
||||
public class DefaultHomePageMiddleware : IMiddleware, ITransientDependency |
|
||||
{ |
|
||||
public async Task InvokeAsync(HttpContext context, RequestDelegate next) |
|
||||
{ |
|
||||
var featureChecker = context.RequestServices.GetRequiredService<IFeatureChecker>(); |
|
||||
|
|
||||
if (context.Request.Path.Value == "/") |
|
||||
{ |
|
||||
if (await featureChecker.IsEnabledAsync(CmsKitFeatures.PageEnable)) |
|
||||
{ |
|
||||
var pagePublicAppService = context.RequestServices.GetRequiredService<IPagePublicAppService>(); |
|
||||
|
|
||||
var page = await pagePublicAppService.FindDefaultHomePageAsync(); |
|
||||
if (page != null) |
|
||||
{ |
|
||||
context.Request.Path = $"{PageConsts.UrlPrefix}{page.Slug}"; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
await next(context); |
|
||||
} |
|
||||
} |
|
||||
@ -1,11 +0,0 @@ |
|||||
using Microsoft.AspNetCore.Builder; |
|
||||
|
|
||||
namespace Volo.CmsKit.Public.Web; |
|
||||
|
|
||||
public static class HomePageDefaultMiddlewareExtensions |
|
||||
{ |
|
||||
public static IApplicationBuilder UseHomePageDefaultMiddleware(this IApplicationBuilder builder) |
|
||||
{ |
|
||||
return builder.UseMiddleware<DefaultHomePageMiddleware>(); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,40 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc.Routing; |
||||
|
using Microsoft.AspNetCore.Routing; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Features; |
||||
|
using Volo.CmsKit.Features; |
||||
|
using Volo.CmsKit.Public.Pages; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.Web.Pages; |
||||
|
|
||||
|
public class CmsKitHomePageRouteValueTransformer : DynamicRouteValueTransformer, ITransientDependency |
||||
|
{ |
||||
|
protected IFeatureChecker FeatureChecker { get; } |
||||
|
|
||||
|
protected IPagePublicAppService PagePublicAppService { get; } |
||||
|
|
||||
|
public CmsKitHomePageRouteValueTransformer(IFeatureChecker featureChecker, IPagePublicAppService pagePublicAppService) |
||||
|
{ |
||||
|
FeatureChecker = featureChecker; |
||||
|
PagePublicAppService = pagePublicAppService; |
||||
|
} |
||||
|
|
||||
|
public override async ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values) |
||||
|
{ |
||||
|
if (await FeatureChecker.IsEnabledAsync(CmsKitFeatures.PageEnable)) |
||||
|
{ |
||||
|
var page = await PagePublicAppService.FindDefaultHomePageAsync(); |
||||
|
if (page is not null) |
||||
|
{ |
||||
|
values = new RouteValueDictionary(); |
||||
|
|
||||
|
values["page"] = "/Public/CmsKit/Pages/Index"; |
||||
|
values["slug"] = page.Slug; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return values; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Http; |
||||
|
using Microsoft.AspNetCore.Mvc.Routing; |
||||
|
using Microsoft.AspNetCore.Routing; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Features; |
||||
|
using Volo.CmsKit.Features; |
||||
|
using Volo.CmsKit.Public.Pages; |
||||
|
|
||||
|
namespace Volo.CmsKit.Public.Web.Pages; |
||||
|
|
||||
|
public class CmsKitPageRouteValueTransformer : DynamicRouteValueTransformer, ITransientDependency |
||||
|
{ |
||||
|
protected IFeatureChecker FeatureChecker { get; } |
||||
|
protected IPagePublicAppService PagePublicAppService { get; } |
||||
|
|
||||
|
public CmsKitPageRouteValueTransformer(IFeatureChecker featureChecker, IPagePublicAppService pagePublicAppService) |
||||
|
{ |
||||
|
FeatureChecker = featureChecker; |
||||
|
PagePublicAppService = pagePublicAppService; |
||||
|
} |
||||
|
|
||||
|
public override async ValueTask<RouteValueDictionary> TransformAsync(HttpContext httpContext, RouteValueDictionary values) |
||||
|
{ |
||||
|
if (values.TryGetValue("slug", out var slugParameter) && slugParameter is not null) |
||||
|
{ |
||||
|
if (!await FeatureChecker.IsEnabledAsync(CmsKitFeatures.PageEnable)) |
||||
|
{ |
||||
|
return values; |
||||
|
} |
||||
|
|
||||
|
var slug = slugParameter.ToString().TrimStart('/'); |
||||
|
var exist = await PagePublicAppService.DoesSlugExistAsync(slug); |
||||
|
|
||||
|
if (exist) |
||||
|
{ |
||||
|
values["page"] = "/Public/CmsKit/Pages/Index"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return values; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue